1
0

Enhance macOS dock icon handling and error resilience in main.js

This commit is contained in:
2025-09-12 22:46:07 +02:00
parent e5ad9d0edb
commit ab8ee2c361

30
main.js
View File

@@ -1,5 +1,8 @@
const { app, BrowserWindow, ipcMain, dialog, Tray, Menu, shell, clipboard, nativeImage } = require('electron');
app.name = 'Auto-Git';
if (typeof app.setName === 'function') {
try { app.setName('Auto-Git'); } catch (_) {}
}
const { exec } = require('child_process');
const { execSync } = require('child_process'); //just for hack
const http = require('http'); //just for hack
@@ -28,6 +31,16 @@ function resolveAppIconPath() {
}
}
// Create a NativeImage for the dock, trying icns then png fallback
function getDockIconImage() {
const icnsPath = path.join(app.isPackaged ? process.resourcesPath : __dirname, 'assets', 'icon', 'mac', 'icon.icns');
const pngFallback = path.join(app.isPackaged ? process.resourcesPath : __dirname, 'assets', 'icon', 'linux', 'icon.png');
let img = nativeImage.createFromPath(icnsPath);
if (img && !img.isEmpty()) return img;
img = nativeImage.createFromPath(pngFallback);
return img;
}
// Wenn wir gebündelt sind (= gepackte App), erweitern wir den PATH um die typischen Ollama-Verzeichnisse:
if (app.isPackaged) {
// HomebrewPfad (M1/M2): /opt/homebrew/bin, bzw. /usr/local/bin
@@ -1306,12 +1319,9 @@ app.whenReady().then(main);
async function main() {
// On macOS, set dock icon during dev as well
if (process.platform === 'darwin') {
const iconPath = resolveAppIconPath();
try {
const img = nativeImage.createFromPath(iconPath);
if (!img.isEmpty() && app.dock) {
app.dock.setIcon(img);
}
const img = getDockIconImage();
if (app.dock && img && !img.isEmpty()) app.dock.setIcon(img);
} catch (_) { /* ignore */ }
}
@@ -1324,6 +1334,16 @@ async function main() {
const win = createWindow();
// Ensure dock icon stays correct when app is activated (macOS)
if (process.platform === 'darwin') {
app.on('activate', () => {
try {
const img = getDockIconImage();
if (app.dock && img && !img.isEmpty()) app.dock.setIcon(img);
} catch (_) { /* ignore */ }
});
}
async function updateFoldersListener(win) {
let folders = store.get('folders') || [];