Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite to signalr #670

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Manually merge in ElectronNET.Host from @theolivenbaum -> main.js nee…
…ds cleanup
  • Loading branch information
LORDofDOOM committed Mar 4, 2022
commit db208e17aa6ad93d7a91e7d32b1523728748ffef
44 changes: 26 additions & 18 deletions ElectronNET.Host/api/app.ts
Original file line number Diff line number Diff line change
@@ -2,23 +2,31 @@ import { HubConnection } from "@microsoft/signalr";

let isQuitWindowAllClosed = true;
let appWindowAllClosedEventId;
export = (socket: HubConnection, app: Electron.App) => {

// By default, quit when all windows are closed
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin' && isQuitWindowAllClosed) {
export = (socket: HubConnection, app: Electron.App, firstTime: boolean) => {

if (firstTime) {
// By default, quit when all windows are closed
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin' && isQuitWindowAllClosed) {
socket.invoke('AppWindowAllClosed', 0);
app.quit();
} else if (appWindowAllClosedEventId) {
// If the user is on macOS
// - OR -
// If the user has indicated NOT to quit when all windows are closed,
// emit the event.
app.quit();
} else if (appWindowAllClosedEventId) {
// If the user is on macOS
// - OR -
// If the user has indicated NOT to quit when all windows are closed,
// emit the event.
socket.invoke('AppWindowAllClosed', appWindowAllClosedEventId);
}
});
}
});

app.on('activate', () => {
// 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.
socket.invoke('AppWindowActivate');
});
}

socket.on('quit-app-window-all-closed-event', (quit) => {
isQuitWindowAllClosed = quit;
@@ -116,11 +124,11 @@ export = (socket: HubConnection, app: Electron.App) => {
let error = {};

if (options) {
const nativeImage = await app.getFileIcon(path, options).catch((errorFileIcon) => error = errorFileIcon);
const nativeImage = await app.getFileIcon(path, options).catch((errorFileIcon) => error = errorFileIcon);

socket.invoke('appGetFileIconCompleted', [error, nativeImage]);
} else {
const nativeImage = await app.getFileIcon(path).catch((errorFileIcon) => error = errorFileIcon);
const nativeImage = await app.getFileIcon(path).catch((errorFileIcon) => error = errorFileIcon);

socket.invoke('appGetFileIconCompleted', [error, nativeImage]);
}
@@ -190,7 +198,7 @@ export = (socket: HubConnection, app: Electron.App) => {
socket.invoke('SendClientResponseBool', guid, success);

app.on('second-instance', (event, args = [], workingDirectory = '') => {
socket.invoke('SendClientResponseJArray', guid, [args, workingDirectory]);
socket.invoke('AppActivateFromSecondInstance', {args: args, workingDirectory: workingDirectory});
});
});

26 changes: 25 additions & 1 deletion ElectronNET.Host/api/autoUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HubConnection } from "@microsoft/signalr";
import { autoUpdater } from 'electron-updater';
import {BrowserWindow} from 'electron';

export = (socket: HubConnection, app: Electron.App) => {

@@ -126,7 +127,30 @@ export = (socket: HubConnection, app: Electron.App) => {
});

socket.on('autoUpdaterQuitAndInstall', async (isSilent, isForceRunAfter) => {
autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
console.log('running autoUpdaterQuitAndInstall');

app.removeAllListeners("window-all-closed");
const windows = BrowserWindow.getAllWindows();
if (windows && windows.length) {
windows.forEach(w => {
try {
w.removeAllListeners('close');
w.removeAllListeners('closed');
w.destroy();
} catch {
//ignore, probably already destroyed
}
});
}

//The call to quitAndInstall needs to happen after the windows
//get a chance to close and release resources, so it must be done on a timeout
setTimeout(() => {
console.log('running autoUpdater.quitAndInstall');
console.log('isSilent:' + isSilent);
console.log('isForceRunAfter:' + isForceRunAfter);
autoUpdater.quitAndInstall(isSilent, isForceRunAfter);
}, 100);
});

socket.on('autoUpdaterDownloadUpdate', async (guid) => {
Loading
Oops, something went wrong.