Skip to content

Commit

Permalink
Moved "Start Minimized" to the tray menu
Browse files Browse the repository at this point in the history
Changes to be committed:
	modified:   src/app.html
	modified:   src/app.js
	modified:   src/main.js
	new file:   src/utils/start_minimized_handler.js
  • Loading branch information
Meedtone committed Jan 17, 2024
1 parent a1b8335 commit 1f50f0b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 44 deletions.
8 changes: 0 additions & 8 deletions src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@
</div>
</td>
</tr>
<tr class="checkbox-group" id="start_minimized_toggle_group" style="display:none">
<td style="width: 50%">Start Minimized</td>
<td style="width: 50%">
<div style="display:grid;grid-template-columns: 1em auto;font-size: 2rem;justify-content:right;">
<input type="checkbox" class="checkbox mb-0" id="start_minimized_toggle" disabled/>
</div>
</td>
</tr>
</tbody>
</table>
<div class="divider"></div>
Expand Down
24 changes: 0 additions & 24 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const remapper = require('./utils/remapper');
const MV_PACK_LSID = remote.getGlobal("current_pack_store_id");
const MV_VOL_LSID = 'mechvibes-volume';
const MV_TRAY_LSID = 'mechvibes-hidden';
const MV_MIN_LSID = 'mechvibes-start-minimized';

const CUSTOM_PACKS_DIR = remote.getGlobal('custom_dir');
const OFFICIAL_PACKS_DIR = path.join(__dirname, 'audio');
Expand Down Expand Up @@ -326,8 +325,6 @@ function packsToOptions(packs, pack_list) {
const volume = document.getElementById('volume');
const tray_icon_toggle = document.getElementById("tray_icon_toggle");
const tray_icon_toggle_group = document.getElementById("tray_icon_toggle_group");
const start_minimized_toggle = document.getElementById("start_minimized_toggle");
const start_minimized_toggle_group = document.getElementById("start_minimized_toggle_group");

// init
app_logo.innerHTML = 'Loading...';
Expand Down Expand Up @@ -375,13 +372,6 @@ function packsToOptions(packs, pack_list) {
tray_icon_toggle.checked = !tray_icon_toggle.checked;
ipcRenderer.send("show_tray_icon", tray_icon_toggle.checked);
store.set(MV_TRAY_LSID, tray_icon_toggle.checked);

// turn off minimized if tray is also off
if(tray_icon_toggle.checked == false){
start_minimized_toggle.checked = false;
ipcRenderer.send("start_minimized", start_minimized_toggle.checked);
store.set(MV_MIN_LSID, start_minimized_toggle.checked);
}
}

// ensure tray icon is reflected
Expand All @@ -390,20 +380,6 @@ function packsToOptions(packs, pack_list) {
}
initTray();

// handle start minimized
console.log(store.get(MV_MIN_LSID));
if (store.get(MV_MIN_LSID) !== undefined){
start_minimized_toggle.checked = store.get(MV_MIN_LSID);
}
start_minimized_toggle_group.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
// toggle checkbox
start_minimized_toggle.checked = !start_minimized_toggle.checked;
ipcRenderer.send("start_minimized", start_minimized_toggle.checked);
store.set(MV_MIN_LSID, start_minimized_toggle.checked);
}

// display volume value
if (store.get(MV_VOL_LSID)) {
volume.value = store.get(MV_VOL_LSID);
Expand Down
27 changes: 15 additions & 12 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ 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';
const start_minimized = store.get('mechvibes-start-minimized') || false;

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

const os = require("os");
const log = require("electron-log");
Expand Down Expand Up @@ -65,7 +67,7 @@ function createWindow(show = false) {
// Create the browser window.
win = new BrowserWindow({
width: 400,
height: 650,
height: 600,
webSecurity: false,
// resizable: false,
// fullscreenable: false,
Expand Down Expand Up @@ -245,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 @@ -288,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 @@ -319,11 +330,6 @@ if (!gotTheLock) {
win.focus();
})
}

// show start minimized button
win.webContents.executeJavaScript(`
document.getElementById('start_minimized_toggle_group').style.display = "";
`);
}

ipcMain.on("show_tray_icon", (event, show) => {
Expand All @@ -332,11 +338,8 @@ if (!gotTheLock) {
}else if(!show && tray !== null){
tray.destroy()
tray = null;

// hide start minimized option
win.webContents.executeJavaScript(`
document.getElementById('start_minimized_toggle_group').style.display = "none";
`);
}else if(!show && tray === null){
createTrayIcon();
}
})

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 1f50f0b

Please sign in to comment.