What is the proper way to implement commandline support in an electron app without showing the gui, but executing the code and closing the application?
I couldn't find any samples online of a proper way to implement this. I was wondering if i should replace the
app.on("ready", createWindow); with a different method like init() that checks if there are any commandline args otherwise proceed as normal like the following...
import { app, BrowserWindow, nativeTheme } from "electron";
import path from "path";
let mainWindow;
function createWindow() {
/**
* Initial window options
*/
console.log("running application....");
mainWindow = new BrowserWindow({
width: 1000,
height: 960,
useContentSize: true,
webPreferences: {
contextIsolation: true,
enableRemoteModule: true,
preload: path.resolve(__dirname, process.env.QUASAR_ELECTRON_PRELOAD),
},
});
mainWindow.loadURL(process.env.APP_URL);
if (process.env.DEBUGGING) {
// if on DEV or Production with debug enabled
mainWindow.webContents.openDevTools();
} else {
// we're on production; no access to devtools pls
mainWindow.webContents.on("devtools-opened", () => {
mainWindow.webContents.closeDevTools();
});
}
mainWindow.on("closed", () => {
mainWindow = null;
});
}
function processArgs() {
console.log("running commandline....");
}
app.on("ready", createWindow); // REPLACE createWindow with init method that checks and then calls createWindow is no args are supplied?
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
if (mainWindow === null) {
createWindow();
}
});