1
0

Refactor settings menu and add autostart/close-to-tray options

This commit is contained in:
2025-05-25 00:02:04 +02:00
parent d72f661548
commit 84e133ac10
3 changed files with 56 additions and 11 deletions

45
main.js
View File

@@ -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();
}
});

View File

@@ -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', {

View File

@@ -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 @@
<!-- Hier kommt das Model-Selector-HTML rein -->
<div id="ollama-model-selectors"></div>
</div>
<label class="option">
<input type="checkbox" id="autostart" />
Launch on System start
</label>
<label class="option">
<input type="checkbox" id="closeToTray" checked />
Close to Tray
</label>
<!-- Weitere Optionen in Zukunft hier hinzufügen -->
</div>
<div class="buttons">