Skip to content

Commit

Permalink
imp(demo): Better demo
Browse files Browse the repository at this point in the history
  • Loading branch information
gergof committed Sep 6, 2022
1 parent 0079193 commit 672f687
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
37 changes: 35 additions & 2 deletions demo/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,50 @@ const ShutdownHandler = require('../dist').default;
app.whenReady().then(() => {
const win = new BrowserWindow({
width: 600,
height: 300
height: 300,
title: 'Electron-shutdown-handler demo'
});

win.loadFile('index.html');
console.log('PID = ', process.pid);

console.log('--- Electron-shutdown-handler demo ---');

console.log('PID =', process.pid);
console.log('You can use rmlogotest.exe <PID> to "simulate" a shutdown');
console.log(
'You can close this app by executing Ctrl+C in the terminal or shutting down your system'
);

let allowQuit = false;

app.on('before-quit', e => {
if (!allowQuit) {
e.preventDefault();
}
});

win.on('close', e => {
if (!allowQuit) {
e.preventDefault();
}
});

ShutdownHandler.setWindowHandle(win.getNativeWindowHandle());
ShutdownHandler.blockShutdown('Yayy! It works! Shutdown in 10 seconds');

ShutdownHandler.on('shutdown', () => {
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!');
console.log('! System is shutting down !');
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!');

console.log();
console.log('Setting a 10 second timer');

setTimeout(() => {
console.log('Shutting down NOW');
ShutdownHandler.releaseShutdown();
allowQuit = true;
app.quit();
}, 10_000);
});
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"install": "run-script-os",
"install:win32": "prebuild-install -r napi || node-gyp rebuild",
"install:default": "echo \"No native addon required\"",
"demo": "electron ./demo/electron.js --no-sandbox",
"demo": "node_modules\\electron\\dist\\electron.exe demo/electron.js --no-sandbox",
"clean": "node-gyp clean && rimraf dist",
"build": "npm run clean && npm run build:ts && npm run build:gyp",
"build:ts": "tsc",
"build:gyp": "node-gyp configure build",
"build:gyp": "node-gyp rebuild",
"prebuild": "prebuild --all -r napi --strip",
"typecheck": "tsc --noEmit",
"lint": "esw --color --ext .ts src",
Expand Down

0 comments on commit 672f687

Please sign in to comment.