let setWriteId;
let setStreamsId;
+let autoStopId; /* keep track of recording time */
+
let playbackId; /* UID of the message being played */
const streamState = { rec: false, pb: false };
backgroundMitt.on("write", (int16Arr) => {
clearTimeout(setWriteId);
- setWriteId = setTimeout(() => setPlaybackStatus(false), 500);
+ setWriteId = setTimeout(setPlaybackStatus.prototype.bind(null, false), 500);
});
function setStreams()
}
}
+function startRecording()
+{
+ setRecordingStatus(true);
+
+ /* 15s recording time limit */
+ autoStopId = setTimeout(stopRecording, 15000);
+}
+
function stopRecording()
{
+ if (autoStopId)
+ {
+ clearTimeout(autoStopId);
+ }
+
setRecordingStatus(false);
sendMessage({
setStreamsId = setInterval(setStreams, 2000);
const res = globalShortcut.register('CommandOrControl+Return', () => {
- streamState.rec ? stopRecording() : setRecordingStatus(true);
+ streamState.rec ? stopRecording() : startRecording();
});
if (!res) throw new Error("Failed to register recording shortcut");
function setPlaybackStatus(status)
{
+ console.log("Setting playback status: ", status);
+
streamState.pb = status;
ipcEmit("playback", playbackId, status);
updateTray("playback", status);
Vue.onMounted(() => {
window.mainApi.on("playback", (id, status) => {
if (id === props.id) {
+ console.log(id, status);
playback.value = status;
}
});
new Notification({title: message.context, body: message.content[message.content.length - 1]}).show();
}
- if (message.audio) playback(message.audio, message.id);
-
ipcEmit("ui-update", message);
+
+ if (message.audio) playback(message.audio, message.id);
}
}
}
-const EventEmitter = require('events');
+const EventEmitter = require("events");
-class BackgroundMitt extends EventEmitter { }
-const backgroundMitt = new BackgroundMitt();
+const backgroundMitt = new EventEmitter();
-const ipcEmit = (channel, payload) =>
+const ipcEmit = (channel, ...args) =>
{
- backgroundMitt.emit('ipc-renderer', {
- channel,
- payload
- });
+ backgroundMitt.emit("ipc-renderer", channel, ...args);
};
module.exports.backgroundMitt = backgroundMitt;
.on("closed", () => {
store.set("focus", false);
- backgroundMitt.removeAllListeners("ipc-renderer");
win = null;
})
win.webContents.on("did-finish-load", () => {
- /* Gateway to the frontend */
- backgroundMitt.on("ipc-renderer", (e) => {
- win.webContents.send(e.channel, e.payload);
+ backgroundMitt.removeAllListeners("ipc-renderer");
+
+ backgroundMitt.on("ipc-renderer", (channel, ...args) => {
+ win.webContents.send(channel, ...args);
});
win.webContents.send("set-account", store.get("account"));