production-taskbar-client / src / main / main.js
main.js
Raw
import { app, crashReporter, ipcMain } from "electron";

import initLogger from "./utils/log";
import initInputChannel from "./ipc/inputChannel";
import initWindowsChannel from "./ipc/windowsChannel";
import initInformingChannel from "./ipc/informingChannel";
import initMainChannel from "./ipc/mainChannel";
import initWinEventChannel from "./ipc/winEventChannel";
import initExtractIconChannel from "./ipc/extractIconChannel";
import initInfoChannel from "./ipc/infoChannel";
import initAppUpdater from "./ipc/updateChannel";
import initHelpdeskChannel from "./ipc/helpdeskChannel";
import initInputEventChannel from "./ipc/inputEventChannel";
import initAutoswitchChannel from "./ipc/autoswitchChannel";
import getTaskbarWindow from "./mainWindow";
import initSpeedometerChannel from "./ipc/speedometerChannel";

initLogger();

// generate minidumps on crash into [userFolder]\Crashpad folder
crashReporter.start({
  submitURL: process.env.CRASH_REPORTER_SUBMIT_URL,
  uploadToServer: !!process.env.CRASH_REPORTER_SUBMIT_URL,
  ignoreSystemCrashHandler: true, // default false
});

app.disableHardwareAcceleration();
app.requestSingleInstanceLock();

let mainWindow;

app.allowRendererProcessReuse = true;
app.commandLine.appendSwitch("touch-events", "enabled");

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on("ready", async () => {
  initMainChannel();
  mainWindow = await getTaskbarWindow();
  initWindowsChannel(mainWindow);
  initInputChannel();
  initWinEventChannel(mainWindow);
  initInputEventChannel();
  initExtractIconChannel();
  initInfoChannel();
  initAppUpdater(mainWindow);
  initHelpdeskChannel(mainWindow);
  initAutoswitchChannel(mainWindow);
  initInformingChannel(mainWindow);
  initSpeedometerChannel(mainWindow);
});

app.on("activate", async () => {
  if (mainWindow === null) {
    mainWindow = await getTaskbarWindow();
  }
});

app.on("second-instance", () => {
  app.quit();
});

app.on("before-quit", () => {
  ipcMain.emit("main", { event: "app-exit" });
  app.exit();
});