Enhance macOS dock icon handling and error resilience in main.js
This commit is contained in:
30
main.js
30
main.js
@@ -1,5 +1,8 @@
|
|||||||
const { app, BrowserWindow, ipcMain, dialog, Tray, Menu, shell, clipboard, nativeImage } = require('electron');
|
const { app, BrowserWindow, ipcMain, dialog, Tray, Menu, shell, clipboard, nativeImage } = require('electron');
|
||||||
app.name = 'Auto-Git';
|
app.name = 'Auto-Git';
|
||||||
|
if (typeof app.setName === 'function') {
|
||||||
|
try { app.setName('Auto-Git'); } catch (_) {}
|
||||||
|
}
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
const { execSync } = require('child_process'); //just for hack
|
const { execSync } = require('child_process'); //just for hack
|
||||||
const http = require('http'); //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:
|
// Wenn wir gebündelt sind (= gepackte App), erweitern wir den PATH um die typischen Ollama-Verzeichnisse:
|
||||||
if (app.isPackaged) {
|
if (app.isPackaged) {
|
||||||
// Homebrew‐Pfad (M1/M2): /opt/homebrew/bin, bzw. /usr/local/bin
|
// Homebrew‐Pfad (M1/M2): /opt/homebrew/bin, bzw. /usr/local/bin
|
||||||
@@ -1306,12 +1319,9 @@ app.whenReady().then(main);
|
|||||||
async function main() {
|
async function main() {
|
||||||
// On macOS, set dock icon during dev as well
|
// On macOS, set dock icon during dev as well
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
const iconPath = resolveAppIconPath();
|
|
||||||
try {
|
try {
|
||||||
const img = nativeImage.createFromPath(iconPath);
|
const img = getDockIconImage();
|
||||||
if (!img.isEmpty() && app.dock) {
|
if (app.dock && img && !img.isEmpty()) app.dock.setIcon(img);
|
||||||
app.dock.setIcon(img);
|
|
||||||
}
|
|
||||||
} catch (_) { /* ignore */ }
|
} catch (_) { /* ignore */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1324,6 +1334,16 @@ async function main() {
|
|||||||
|
|
||||||
const win = createWindow();
|
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) {
|
async function updateFoldersListener(win) {
|
||||||
let folders = store.get('folders') || [];
|
let folders = store.get('folders') || [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user