From b8f6f0819187878bd1a5c64bc2f2dd1375a48301 Mon Sep 17 00:00:00 2001 From: GameGodS3 Date: Thu, 13 Jul 2023 10:46:41 +0530 Subject: [PATCH] Added feature to launch minimised. Resolves issue #38 and issue #43 --- src/App.js | 12 +++++++++--- src/Settings.js | 2 +- src/Window.js | 14 ++++++-------- src/configOptions.js | 9 +++++++-- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/App.js b/src/App.js index bf8b2a3..a68d86b 100644 --- a/src/App.js +++ b/src/App.js @@ -1,11 +1,16 @@ const { app, BrowserWindow, nativeImage } = require("electron"); const { autoUpdater } = require("electron-updater"); +const Store = require("electron-store"); +const configOptions = require("./configOptions"); + const { Instance } = require("./Window"); const { setShortcut } = require("./Shortcut"); const { droppointDefaultIcon } = require("./Icons"); const { setTray } = require("./Tray"); +const config = new Store(configOptions); let splashScreen; + app .on("ready", () => { // Splash screen which also helps to run in background and keep app alive @@ -25,12 +30,13 @@ app // splashScreen.hide(); // }, 3000); - if (BrowserWindow.getAllWindows.length === 0) { + setTray(); + setShortcut(); + + if (BrowserWindow.getAllWindows.length === 0 && config.get("spawnOnLaunch")) { const instance = new Instance(); const instanceID = instance.createNewWindow(); if (instanceID !== null) { - setTray(); - setShortcut(); } } }) diff --git a/src/Settings.js b/src/Settings.js index 55d5005..7124332 100644 --- a/src/Settings.js +++ b/src/Settings.js @@ -24,7 +24,7 @@ class Settings { this.settings = new BrowserWindow({ title: "Settings - DropPoint", width: 600, - height: 350, + height: 450, webPreferences: { nodeIntegration: true, preload: path.join(__dirname, "preload.js"), diff --git a/src/Window.js b/src/Window.js index 5c33689..11766a5 100644 --- a/src/Window.js +++ b/src/Window.js @@ -50,14 +50,12 @@ class Instance { * @returns {number} id - Unique ID of the instance | null if not created */ createNewWindow() { - this.config.get("openAtCursorPosition") - ? () => { - const cursorPosition = this.getCursorPos(); - this.windowConfig.x = cursorPosition.x; - this.windowConfig.y = cursorPosition.y; - } - : (this.windowConfig.x = - screen.getPrimaryDisplay().workArea.width / 2 - 100); + if (this.config.get("openAtCursorPosition")) { + const cursorPosition = this.getCursorPos(); + this.windowConfig.x = cursorPosition.x; + this.windowConfig.y = cursorPosition.y; + } + else this.windowConfig.x = screen.getPrimaryDisplay().workArea.width / 2 - 100; this.instance = new BrowserWindow(this.windowConfig); diff --git a/src/configOptions.js b/src/configOptions.js index 30c23b2..4daaa3d 100644 --- a/src/configOptions.js +++ b/src/configOptions.js @@ -1,13 +1,18 @@ const defaultAppConfig = { + spawnOnLaunch: true, alwaysOnTop: true, openAtCursorPosition: false, shortcutAction: "toggle", debug: false, }; const appConfigSchema = { + spawnOnLaunch: { + type: "boolean", + title: "Open a new instance on launch" + }, alwaysOnTop: { type: "boolean", - title: "Always on Top", + title: "Always on top", }, openAtCursorPosition: { type: "boolean", @@ -16,7 +21,7 @@ const appConfigSchema = { shortcutAction: { enum: ["toggle", "spawn"], type: "string", - title: "Shortcut Behaviour", + title: "Shortcut behaviour", }, debug: { type: "boolean",