Jitsi Push-to-Talk

This commit is contained in:
Andrew Morgan
2018-11-15 19:01:02 +01:00
parent 588030141b
commit 6e71fa5902
5 changed files with 178 additions and 9 deletions

View File

@@ -17,5 +17,6 @@
"Explore rooms": "Explore rooms",
"Room Directory": "Room Directory",
"Search the room directory": "Search the room directory",
"Get started with some tips from Riot Bot!": "Get started with some tips from Riot Bot!"
"Get started with some tips from Riot Bot!": "Get started with some tips from Riot Bot!",
"Push-to-Talk": "Push-to-Talk"
}

View File

@@ -25,6 +25,7 @@ import Promise from 'bluebird';
import rageshake from 'matrix-react-sdk/lib/rageshake/rageshake';
const ipcRenderer = window.ipcRenderer;
var globalKeybindings = {};
function platformFriendlyName(): string {
// used to use window.process but the same info is available here
@@ -99,6 +100,25 @@ export default class ElectronPlatform extends VectorBasePlatform {
this.startUpdateCheck = this.startUpdateCheck.bind(this);
this.stopUpdateCheck = this.stopUpdateCheck.bind(this);
ipcRenderer.on('keybinding-pressed', (event, keybindName) => {
// Prevent holding down a shortcut meaning multiple presses
if (globalKeybindings[keybindName].pressed) {
return;
}
globalKeybindings[keybindName].pressed = true;
// Run the callback
globalKeybindings[keybindName].callback();
});
ipcRenderer.on('keybinding-released', (event, keybindName) => {
// Keybinding is no longer pressed
globalKeybindings[keybindName].pressed = false;
// Run the callback
globalKeybindings[keybindName].releaseCallback();
});
}
async onUpdateDownloaded(ev, updateInfo) {
@@ -198,6 +218,26 @@ export default class ElectronPlatform extends VectorBasePlatform {
ipcRenderer.send('check_updates');
}
addGlobalKeybinding(keybindName: string, keybindCode: string, callback: () => void, releaseCallback: () => void) {
// Add a keybinding that works even when the app is minimized
const keybinding = {name: keybindName, code: keybindCode};
ipcRenderer.send('register-keybinding', keybinding);
globalKeybindings[keybindName] = {callback, releaseCallback};
console.warn("Adding global keybinding:", keybindName, "with code:", keybindCode);
}
removeGlobalKeybinding(keybindName: string, keybindCode: string) {
// Unbind a global keybinding
ipcRenderer.send('unregister-keybinding', keybindCode);
// Remove the callback
delete globalKeybindings[keybindName];
console.warn("Removing global keybinding:", keybindName);
}
installUpdate() {
// IPC to the main process to install the update, since quitAndInstall
// doesn't fire the before-quit event so the main process needs to know
@@ -232,7 +272,7 @@ export default class ElectronPlatform extends VectorBasePlatform {
const ipcCallId = ++this._nextIpcCallId;
return new Promise((resolve, reject) => {
this._pendingIpcCalls[ipcCallId] = {resolve, reject};
window.ipcRenderer.send('ipcCall', {id: ipcCallId, name, args});
ipcRenderer.send('ipcCall', {id: ipcCallId, name, args});
// Maybe add a timeout to these? Probably not necessary.
});
}