mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(electron): make macOS dev dock icon setup non-fatal
This commit is contained in:
+24
-5
@@ -1,5 +1,5 @@
|
|||||||
import './log.js';
|
import './log.js';
|
||||||
import { app, BrowserWindow, Menu, MenuItem, Tray, shell, dialog, nativeTheme, ipcMain, clipboard } from 'electron';
|
import { app, BrowserWindow, Menu, MenuItem, Tray, shell, dialog, nativeTheme, nativeImage, ipcMain, clipboard } from 'electron';
|
||||||
import { automateUploadMedia } from './media-upload-automation.js';
|
import { automateUploadMedia } from './media-upload-automation.js';
|
||||||
import isDev from 'electron-is-dev';
|
import isDev from 'electron-is-dev';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
@@ -318,14 +318,33 @@ const createMainWindow = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setDevDockIcon = () => {
|
||||||
|
if (process.platform !== 'darwin' || !isDev || !app.dock) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const iconCandidates = [path.join(dirname, '..', 'public', 'icon.icns'), path.join(dirname, '..', 'public', 'icon.png')];
|
||||||
|
for (const iconPath of iconCandidates) {
|
||||||
|
try {
|
||||||
|
const icon = nativeImage.createFromPath(iconPath);
|
||||||
|
if (icon.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
app.dock.setIcon(icon);
|
||||||
|
return;
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(`[Electron Main] Failed to set dock icon from ${iconPath}`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.warn(`[Electron Main] Could not load any dock icon (${iconCandidates.join(', ')})`);
|
||||||
|
};
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
// Set app name and dock icon for development mode on macOS
|
// Set app name and dock icon for development mode on macOS
|
||||||
if (process.platform === 'darwin' && isDev) {
|
if (process.platform === 'darwin' && isDev) {
|
||||||
app.setName('5chan');
|
app.setName('5chan');
|
||||||
if (app.dock) {
|
setDevDockIcon();
|
||||||
const iconPath = path.join(dirname, '..', 'public', 'icon.icns');
|
|
||||||
app.dock.setIcon(iconPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createMainWindow();
|
createMainWindow();
|
||||||
|
|||||||
Reference in New Issue
Block a user