Quit the app when suspending or locking it
This commit is contained in:
parent
748de04248
commit
45d4f51163
|
@ -1,10 +1,10 @@
|
||||||
import { app, BrowserWindow, Menu, dialog, shell, powerMonitor, ipcMain } from "electron";
|
import { app, BrowserWindow, Menu, dialog, shell, powerMonitor } from "electron";
|
||||||
import { autoUpdater, UpdateInfo } from "electron-updater";
|
import { autoUpdater, UpdateInfo } from "electron-updater";
|
||||||
// import * as os from "os";
|
// import * as os from "os";
|
||||||
import ElectronStore from "electron-store";
|
import ElectronStore from "electron-store";
|
||||||
|
|
||||||
const debug = true; //process.argv.includes("--dbg");
|
const debug = process.argv.includes("--dbg");
|
||||||
// const pwaUrl = process.env.PL_PWA_URL!.replace(/(\/*)$/, "");
|
const pwaUrl = process.env.PL_PWA_URL!.replace(/(\/*)$/, "");
|
||||||
const appName = process.env.PL_APP_NAME!;
|
const appName = process.env.PL_APP_NAME!;
|
||||||
const appScheme = process.env.PL_APP_SCHEME!;
|
const appScheme = process.env.PL_APP_SCHEME!;
|
||||||
|
|
||||||
|
@ -136,8 +136,8 @@ function createWindow(path: string = "") {
|
||||||
win.webContents.openDevTools();
|
win.webContents.openDevTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
win.loadFile("index.html");
|
// win.loadFile("index.html");
|
||||||
// win.loadURL(`${pwaUrl}/${path}`);
|
win.loadURL(`${pwaUrl}/${path}`);
|
||||||
|
|
||||||
win.once("ready-to-show", () => {
|
win.once("ready-to-show", () => {
|
||||||
win.show();
|
win.show();
|
||||||
|
@ -307,32 +307,21 @@ async function start() {
|
||||||
|
|
||||||
await app.whenReady();
|
await app.whenReady();
|
||||||
|
|
||||||
const startUrl = process.argv.find((arg) => arg.startsWith(`${appScheme}:`));
|
|
||||||
const path = startUrl?.replace(/\w+:(\/*)/, "");
|
|
||||||
|
|
||||||
const window = createWindow(path);
|
|
||||||
createApplicationMenu();
|
|
||||||
|
|
||||||
// Lock app on suspend system event
|
// Lock app on suspend system event
|
||||||
powerMonitor.on("suspend", async () => {
|
powerMonitor.on("suspend", async () => {
|
||||||
console.log("suspending");
|
app.quit();
|
||||||
ipcMain.emit("electron-lock-app");
|
|
||||||
window.webContents.send("electron-lock-app");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Lock app on lock system event
|
// Lock app on lock system event
|
||||||
powerMonitor.on("lock-screen", async () => {
|
powerMonitor.on("lock-screen", async () => {
|
||||||
console.log("locking screen");
|
app.quit();
|
||||||
ipcMain.emit("electron-lock-app");
|
|
||||||
window.webContents.send("electron-lock-app");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: Remove this
|
const startUrl = process.argv.find((arg) => arg.startsWith(`${appScheme}:`));
|
||||||
setTimeout(() => {
|
const path = startUrl?.replace(/\w+:(\/*)/, "");
|
||||||
console.log("fake lock");
|
|
||||||
// ipcMain.emit("electron-lock-app");
|
createWindow(path);
|
||||||
window.webContents.send("electron-lock-app");
|
createApplicationMenu();
|
||||||
}, 10000);
|
|
||||||
|
|
||||||
app.setAsDefaultProtocolClient(appScheme);
|
app.setAsDefaultProtocolClient(appScheme);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
const { resolve, join } = require("path");
|
const { resolve, join } = require("path");
|
||||||
const { EnvironmentPlugin } = require("webpack");
|
const { EnvironmentPlugin } = require("webpack");
|
||||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
||||||
|
|
||||||
const rootDir = resolve(__dirname, "../..");
|
const rootDir = resolve(__dirname, "../..");
|
||||||
const assetsDir = resolve(rootDir, process.env.PL_ASSETS_DIR || "assets");
|
const assetsDir = resolve(rootDir, process.env.PL_ASSETS_DIR || "assets");
|
||||||
|
@ -40,10 +39,6 @@ module.exports = [
|
||||||
PL_VENDOR_VERSION: version,
|
PL_VENDOR_VERSION: version,
|
||||||
PL_TERMS_OF_SERVICE: terms_of_service,
|
PL_TERMS_OF_SERVICE: terms_of_service,
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
title: name,
|
|
||||||
template: resolve(__dirname, "src/index.html"),
|
|
||||||
}),
|
|
||||||
{
|
{
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
const package = JSON.stringify({
|
const package = JSON.stringify({
|
||||||
|
|
Loading…
Reference in New Issue