diff --git a/main.js b/main.js index 614b1b8..c124e00 100644 --- a/main.js +++ b/main.js @@ -16,11 +16,14 @@ const store = new Store({ selected: null, skymode: true, skipGitPrompt: true, - intelligentCommitThreshold: 100 + intelligentCommitThreshold: 20, + autostart: false, + closeToTray: true } }); let tray = null; +let isQuiting = false; function createTray(win) { const iconPath = path.join(__dirname, 'assets/icon/trayicon.png'); @@ -570,17 +573,16 @@ async function autoCommit(folderPath, message) { app.whenReady().then(() => { const win = createWindow(); - // Menüs - + // Menubar const menu = Menu.buildFromTemplate([ { role: 'appMenu', submenu: [ { label: 'Settings', click: () => openSettings(win) }, - { role: 'quit', label: 'Quit' } + { label: 'Quit', role: 'quit', click: () => { isQuiting = true; app.quit(); } } ] }, - { role: 'editMenu' } // <-- hiermit aktivierst du Copy/Paste via Ctrl+C / Cmd+C + { role: 'editMenu' } ]); Menu.setApplicationMenu(menu); @@ -634,7 +636,7 @@ app.whenReady().then(() => { } }, { type: 'separator' }, - { label: 'Beenden', role: 'quit' } + { label: 'Beenden', click: () => { isQuiting = true; app.quit(); } } ]); } @@ -1016,12 +1018,35 @@ app.whenReady().then(() => { store.set('intelligentCommitThreshold', value); }); + ipcMain.handle('get-autostart', () => store.get('autostart')); + ipcMain.handle('set-autostart', (_e, val) => { + store.set('autostart', val); + // Optional: System-Autostart umschalten (siehe unten) + }); + ipcMain.handle('get-close-to-tray', () => store.get('closeToTray')); + ipcMain.handle('set-close-to-tray', (_e, val) => store.set('closeToTray', val)); + ipcMain.on('close-settings', () => { if (settingsWin) settingsWin.close(); }); + + + ipcMain.handle('set-autostart', (_e, enabled) => { + store.set('autostart', enabled); + app.setLoginItemSettings({ + openAtLogin: !!enabled + }); + }); + + win.webContents.openDevTools({ mode: 'detach' }); + + + + + // … Ende der IPC-Handler … }); @@ -1047,9 +1072,9 @@ ipcMain.on('show-folder-context-menu', (event, folderPath) => { }); // clean up on exit -app.on('window-all-closed', () => { - if (process.platform !== 'darwin'){ - //app.isQuiting = true; - app.quit(); +win.on('close', (e) => { + if (!isQuiting && store.get('closeToTray')) { + e.preventDefault(); + win.hide(); } }); diff --git a/preload.js b/preload.js index 75e54ae..5d74f33 100644 --- a/preload.js +++ b/preload.js @@ -12,6 +12,10 @@ contextBridge.exposeInMainWorld('settingsAPI', { getReadmeModel: () => ipcRenderer.invoke('get-readme-model'), setReadmeModel: (model) => ipcRenderer.invoke('set-readme-model', model), close: () => ipcRenderer.send('close-settings') + getAutostart: () => ipcRenderer.invoke('get-autostart'), + setAutostart: val => ipcRenderer.invoke('set-autostart', val), + getCloseToTray: () => ipcRenderer.invoke('get-close-to-tray'), + setCloseToTray: val => ipcRenderer.invoke('set-close-to-tray', val), }); contextBridge.exposeInMainWorld('electronAPI', { diff --git a/settings.html b/settings.html index f415901..5cef691 100644 --- a/settings.html +++ b/settings.html @@ -149,6 +149,15 @@ const ok = document.getElementById('okBtn'); const cancel = document.getElementById('cancelBtn'); const close = document.getElementById('closeBtn'); + const cbAutostart = document.getElementById('autostart'); + const cbCloseToTray= document.getElementById('closeToTray'); + + const [initialAutostart, initialCloseToTray] = await Promise.all([ + window.settingsAPI.getAutostart(), + window.settingsAPI.getCloseToTray() + ]); + cbAutostart.checked = initialAutostart; + cbCloseToTray.checked = initialCloseToTray; // Initialwerte parallel laden const [initialSky, initialSkip, initialThreshold] = await Promise.all([ @@ -284,7 +293,14 @@
- + +