Jitsi Push-to-Talk
This commit is contained in:
parent
0aeef3187a
commit
70e7c63213
5 changed files with 220 additions and 71 deletions
|
@ -8,7 +8,27 @@
|
|||
"dependencies": {
|
||||
"auto-launch": "^5.0.1",
|
||||
"electron-window-state": "^4.1.0",
|
||||
"iohook": "^0.2.4",
|
||||
"minimist": "^1.2.0",
|
||||
"png-to-ico": "^1.0.2"
|
||||
},
|
||||
"iohook": {
|
||||
"targets": [
|
||||
"node-64",
|
||||
"electron-64"
|
||||
],
|
||||
"platforms": [
|
||||
"win32",
|
||||
"darwin",
|
||||
"linux"
|
||||
],
|
||||
"arches": [
|
||||
"x64",
|
||||
"ia32"
|
||||
]
|
||||
},
|
||||
"cmake-js": {
|
||||
"runtime": "electron",
|
||||
"runtimeVersion": "3.0.5"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ if (checkSquirrelHooks()) return;
|
|||
const argv = require('minimist')(process.argv);
|
||||
const {app, ipcMain, powerSaveBlocker, BrowserWindow, Menu} = require('electron');
|
||||
const AutoLaunch = require('auto-launch');
|
||||
const ioHook = require('iohook');
|
||||
|
||||
const tray = require('./tray');
|
||||
const vectorMenu = require('./vectormenu');
|
||||
|
@ -238,6 +239,13 @@ app.on('ready', () => {
|
|||
return false;
|
||||
}
|
||||
});
|
||||
mainWindow.on('blur', () => {
|
||||
// Stop recording keypresses if Riot loses focus
|
||||
// Used for Push-To-Talk, keypress recording only triggered when setting
|
||||
// a global shortcut in Settings
|
||||
mainWindow.webContents.send('window-blurred');
|
||||
stopListeningKeys();
|
||||
});
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
// Handle forward/backward mouse buttons in Windows
|
||||
|
@ -268,6 +276,92 @@ app.on('before-quit', () => {
|
|||
}
|
||||
});
|
||||
|
||||
// Counter for keybindings we have registered
|
||||
let ioHookTasks = 0;
|
||||
|
||||
// Limit for amount of keybindings that can be
|
||||
// registered at once.
|
||||
const keybindingRegistrationLimit = 1;
|
||||
|
||||
// Fires when a global keybinding is being registered
|
||||
ipcMain.on('register-keybinding', function(ev, keybinding) {
|
||||
// Prevent registering more than the defined limit
|
||||
if (ioHookTasks >= keybindingRegistrationLimit) {
|
||||
ioHookTasks = keybindingRegistrationLimit;
|
||||
return;
|
||||
}
|
||||
|
||||
// Start listening for global keyboard shortcuts
|
||||
if (ioHookTasks <= 0) {
|
||||
ioHookTasks = 0;
|
||||
ioHook.start();
|
||||
}
|
||||
ioHookTasks++;
|
||||
|
||||
ioHook.registerShortcut(keybinding.code, () => {
|
||||
ev.sender.send('keybinding-pressed', keybinding.name);
|
||||
}, () => {
|
||||
ev.sender.send('keybinding-released', keybinding.name);
|
||||
});
|
||||
});
|
||||
|
||||
// Fires when a global keybinding is being unregistered
|
||||
ipcMain.on('unregister-keybinding', function(ev, keybindingCode) {
|
||||
// Stop listening for global keyboard shortcuts if we're
|
||||
// unregistering the last one
|
||||
if (ioHookTasks <= 1) {
|
||||
ioHook.stop();
|
||||
}
|
||||
ioHookTasks--;
|
||||
|
||||
ioHook.unregisterShortcutByKeys(keybindingCode);
|
||||
});
|
||||
|
||||
// Tell renderer process what key was pressed
|
||||
// iohook has its own encoding for keys, so we can't just use a
|
||||
// listener in the renderer process to register iohook shortcuts
|
||||
let renderProcessID = null;
|
||||
const reportKeyEvent = function(keyEvent) {
|
||||
// "this" is the renderer process because we call this method with .bind()
|
||||
renderProcessID.sender.send('keypress', {
|
||||
keydown: keyEvent.type == 'keydown',
|
||||
keycode: keyEvent.keycode,
|
||||
});
|
||||
};
|
||||
|
||||
// Fires when listening on all keys
|
||||
// !!Security note: Ensure iohook is only allowed to listen to keybindings
|
||||
// when the browser window is in focus, else an XSS could lead to keylogging
|
||||
// Currently, this is achieved by leveraging browserWindow to act on focus loss
|
||||
ipcMain.on('start-listening-keys', function(ev, keybindingCode) {
|
||||
// Start recording keypresses
|
||||
if (ioHookTasks <= 0) {
|
||||
ioHookTasks = 0;
|
||||
ioHook.start();
|
||||
}
|
||||
ioHookTasks++;
|
||||
|
||||
renderProcessID = ev;
|
||||
ioHook.on('keydown', reportKeyEvent);
|
||||
ioHook.on('keyup', reportKeyEvent);
|
||||
});
|
||||
|
||||
const stopListeningKeys = () => {
|
||||
// Stop recording keypresses
|
||||
ioHook.off('keydown', reportKeyEvent);
|
||||
ioHook.off('keyup', reportKeyEvent);
|
||||
};
|
||||
|
||||
ipcMain.on('stop-listening-keys', () => {
|
||||
if (ioHookTasks <= 1) {
|
||||
ioHookTasks = 1;
|
||||
ioHook.stop();
|
||||
}
|
||||
ioHookTasks--;
|
||||
|
||||
stopListeningKeys();
|
||||
});
|
||||
|
||||
// Set the App User Model ID to match what the squirrel
|
||||
// installer uses for the shortcut icon.
|
||||
// This makes notifications work on windows 8.1 (and is
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue