Skip to content

Commit

Permalink
global hot key support for custom PPT
Browse files Browse the repository at this point in the history
  • Loading branch information
steveseguin committed May 7, 2022
1 parent f88c105 commit 49d063d
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 35 deletions.
141 changes: 108 additions & 33 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,37 +121,6 @@ function createWindow (URL=url, NODE=node) {
currentTitle = title.toString() + " " +(counter.toString());
}

const ret = globalShortcut.register('CommandOrControl+M', () => {
console.log('CommandOrControl+N is pressed')
if (mainWindow) {
mainWindow.webContents.send('postMessage', {'mic':'toggle'})
}
})
const ret_refresh = globalShortcut.register('CommandOrControl+Shift+R', () => {
console.log('CommandOrControl+Shift+R')
if (mainWindow) {
mainWindow.reload();
}
})

ipcMain.on('postMessage', (msg) => {
console.log('We received a postMessage from the preload script')
})

if (!ret) {
console.log('registration failed')
}

ipcMain.on('getAppVersion', function(eventRet) {
try{
if (mainWindow) {
mainWindow.webContents.send('appVersion', app.getVersion());
}
} catch(e){errorlog(e);}
});



ipcMain.on('prompt', function(eventRet, arg) { // this enables a PROMPT pop up , which is used to BLOCK the main thread until the user provides input. VDO.Ninja uses prompt for passwords, etc.
try {
arg.val = arg.val || '';
Expand Down Expand Up @@ -281,6 +250,110 @@ function createWindow (URL=url, NODE=node) {
}
});

ipcMain.on('postMessage', (msg) => {
console.log('We received a postMessage from the preload script')
})

ipcMain.on('getAppVersion', function(eventRet) {
try{
if (mainWindow) {
mainWindow.webContents.send('appVersion', app.getVersion());
}
} catch(e){errorlog(e);}
});

if (mainWindow && mainWindow.node){
const ret = globalShortcut.register('CommandOrControl+M', () => {
console.log('CommandOrControl+M is pressed')
if (mainWindow) {
mainWindow.webContents.send('postMessage', {'mic':'toggle'})
}
});
if (!ret) {
console.log('registration failed1')
}
}

const ret_refresh = globalShortcut.register('CommandOrControl+Shift+R', () => {
console.log('CommandOrControl+Shift+R')
if (mainWindow) {
mainWindow.reload();
}
});
if (!ret_refresh) {
console.log('registration failed2')
}


var PPTHotkey = false;

ipcMain.on('PPTHotkey', function(event, value) {
if (!mainWindow){return;}
if (!mainWindow.node){return;}
if (PPTHotkey){
try {
if (globalShortcut.isRegistered(PPTHotkey)){
globalShortcut.unregister(PPTHotkey);
}
} catch(e){
}
}

if (!value){
PPTHotkey=false;
return;
}
PPTHotkey = "";
if (value.ctrl){
PPTHotkey += "CommandOrControl";
}
if (value.alt){
if (PPTHotkey){PPTHotkey+="+";}
PPTHotkey += "Alt";
}
if (value.meta){
if (PPTHotkey){PPTHotkey+="+";}
PPTHotkey += "Meta";
}
if (value.key){
if (PPTHotkey){PPTHotkey+="+";}
var matched = false;
if (value.key === "+"){
PPTHotkey += "Plus";
matched = true;
} else if (value.key === " "){
PPTHotkey += "Space";
matched = true;
} else if (value.key.length === 1){
PPTHotkey += value.key.toUpperCase();
matched = true;
} else {
var possibleKeyCodes = ["Space","Backspace","Tab","Capslock","Return","Enter","Plus","Numlock","Scrolllock","Delete","Insert","Return","Up","Down","Left","Right","Home","End","PageUp","PageDown","Escape","Esc","VolumeUp","VolumeDown","VolumeMute","MediaNextTrack","MediaPreviousTrack","MediaStop","MediaPlayPause","PrintScreen","num0","num1","num2","num3","num4","num5","num6","num7","num8","num9","numdec","numadd","numsub","nummult","numdiv"];
for (var i = 0;i<possibleKeyCodes.length;i++){
if (possibleKeyCodes[i].toLowerCase() === value.key.toLowerCase()){
PPTHotkey += possibleKeyCodes[i];
matched = true;
break;
}
}
}
if (!matched){
PPTHotkey += value.key.toUpperCase(); // last resort
}
} else {
//console.log("Can't register just a control button; needs a key for global hotkeys");
return;
}
const ret_ppt = globalShortcut.register(PPTHotkey, function(){
if (mainWindow) {
mainWindow.webContents.send('postMessage', {'PPT':true})
}
});
if (!ret_ppt) {
//console.log('registration failed3')
};
});

try {
if (pin == true) {
// "floating" + 1 is higher than all regular windows, but still behind things
Expand Down Expand Up @@ -444,7 +517,7 @@ contextMenu({
browserWindow.webContents.send('postMessage', {'changeAudioOutputDevice':details[response]});
}

})
});


}
Expand Down Expand Up @@ -866,7 +939,9 @@ contextMenu({
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})

electron.powerMonitor.on('on-battery', () => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "VDON.Electron.Capture.App",
"version": "2.9.0",
"version": "2.10.0",
"description": "A simple tool to aid with frameless window video capture and VDON publishing",
"author": "Steve Seguin <steve@seguin.email>",
"main": "main.js",
Expand Down Expand Up @@ -120,7 +120,7 @@
"yargs": "^15.4.1"
},
"engines": {
"node": "v16.13.2",
"node": "v16.14.0",
"npm": "8.7.0"
},
"resolutions": {
Expand Down
26 changes: 26 additions & 0 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ window.addEventListener('DOMContentLoaded', () => {
})

window.addEventListener('message', ({ data }) => {
console.log("MessageIncoming:15:"+data);
ipcRenderer.send('postMessage', data)
})

var PPTTimeout = null;
ipcRenderer.on('postMessage', (event, ...args) => {
try{
if ("mic" in args[0]) { // this should work for the director's mic mute button as well. Needs to be manually enabled the first time still tho.
Expand All @@ -27,6 +29,30 @@ ipcRenderer.on('postMessage', (event, ...args) => {
} else if (args[0].mic === "toggle") { // toggle
toggleMute();
}
return;
}

if (args[0].PPT){
if (PPTTimeout){
clearTimeout(PPTTimeout);
PPTTimeout = setTimeout(function(){
PPTTimeout=null;
session.muted = true;
toggleMute(true);
getById("mutebutton").classList.remove("PPTActive");
},200);
} else {
session.muted = false;
toggleMute(true);
getById("mutebutton").classList.add("PPTActive");
PPTTimeout = setTimeout(function(){
PPTTimeout=null;
session.muted = true;
toggleMute(true);
getById("mutebutton").classList.remove("PPTActive");
},600);
}
return;
}

if ("getDeviceList" in args[0]) {
Expand Down

0 comments on commit 49d063d

Please sign in to comment.