Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
Calling commandline in Electron not showing GUI

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();
  }
});

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!