Skip to content

Commit

Permalink
Adding a "Start Minimized" toggle (hainguyents13#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meedtone authored and NotLazy committed Feb 17, 2024
1 parent 5f3983c commit 232fe5f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ const store = new Store();

const StartupHandler = require('./utils/startup_handler');
const ListenHandler = require('./utils/listen_handler');
const StartMinimizedHandler = require('./utils/start_minimized_handler');

const SYSTRAY_ICON = path.join(__dirname, '/assets/system-tray-icon.png');
const home_dir = app.getPath('home');
const user_dir = app.getPath("userData");
const custom_dir = path.join(home_dir, '/mechvibes_custom');
const current_pack_store_id = 'mechvibes-pack';

let start_minimized = store.get('mechvibes-start-minimized') || false;

const os = require("os");
const log = require("electron-log");
if(fs.existsSync(path.join(user_dir, "/remote-logging-opt-in.txt"))){
Expand Down Expand Up @@ -60,7 +63,7 @@ global.current_pack_store_id = current_pack_store_id;
// create custom sound folder if not exists
fs.ensureDirSync(custom_dir);

function createWindow(show = true) {
function createWindow(show = false) {
// Create the browser window.
win = new BrowserWindow({
width: 400,
Expand Down Expand Up @@ -110,6 +113,13 @@ function createWindow(show = true) {
console.log("unresponsive");
})

// condition for start_minimized
if (start_minimized) {
win.close();
} else {
win.show();
}

return win;
}

Expand Down Expand Up @@ -223,7 +233,7 @@ if (!gotTheLock) {
app.on('ready', () => {
app.setAsDefaultProtocolClient('mechvibes');

win = createWindow(true);
win = createWindow();

function createTrayIcon(){
// prevent dupe tray icons
Expand All @@ -237,6 +247,7 @@ if (!gotTheLock) {

const startup_handler = new StartupHandler(app);
const listen_handler = new ListenHandler(app);
const start_minimized_handler = new StartMinimizedHandler(app);

// context menu when hover on tray icon
const contextMenu = Menu.buildFromTemplate([
Expand Down Expand Up @@ -280,6 +291,14 @@ if (!gotTheLock) {
startup_handler.toggle();
},
},
{
label: 'Start Minimized',
type: 'checkbox',
checked: start_minimized_handler.is_enabled,
click: function () {
start_minimized_handler.toggle();
},
},
{
label: 'Quit',
click: function () {
Expand Down Expand Up @@ -366,7 +385,7 @@ app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null){
createWindow();
createWindow(true);
}else{
// on macOS clicking the app icon in the launcher or in finder, triggers activate instead of second-instance for some reason
if (process.platform === 'darwin') {
Expand Down
31 changes: 31 additions & 0 deletions src/utils/start_minimized_handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const Store = require('electron-store');
const store = new Store();

class startMinimizedHandler {
constructor(app) {
this.app = app;
this.MV_MIN_LSID = 'mechvibes-start-minimized';
}

get is_enabled() {
return store.get(this.MV_MIN_LSID);
}

enable() {
store.set(this.MV_MIN_LSID, true);
}

disable() {
store.set(this.MV_MIN_LSID, false);
}

toggle() {
if (this.is_enabled) {
this.disable();
} else {
this.enable();
}
}
}

module.exports = startMinimizedHandler;

0 comments on commit 232fe5f

Please sign in to comment.