Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 90 additions & 4 deletions electron/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, BrowserWindow, ipcMain, shell, nativeImage } from 'electron';
import { app, BrowserWindow, ipcMain, shell, nativeImage, Tray, Menu } from 'electron';
import { autoUpdater } from 'electron-updater';
import serve from 'electron-serve';
import path from 'path';
Expand All @@ -9,12 +9,18 @@ const loadURL = serve({
scheme: 'app'
});

const gotTheLock = app.requestSingleInstanceLock();

if (!gotTheLock) {
app.quit();
}

const setupDock = () => {
if (process.platform === 'darwin' && app.dock) {
const iconPath = isProd
const iconPath = isProd
? path.join(process.resourcesPath, 'icons', 'app.png')
: path.join(app.getAppPath(), 'public', 'icons', 'app.png');

try {
const dockIcon = nativeImage.createFromPath(iconPath);
if (!dockIcon.isEmpty()) {
Expand All @@ -27,7 +33,66 @@ const setupDock = () => {
}
};

const createTray = () => {
const iconPath = isProd
? path.join(process.resourcesPath, 'icons', process.platform === 'win32' ? 'app.ico' : 'app.png')
: path.join(app.getAppPath(), 'public', 'icons', process.platform === 'win32' ? 'app.ico' : 'app.png');

tray = new Tray(iconPath);

const contextMenu = Menu.buildFromTemplate([
{
label: '顯示視窗',
click: () => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
if (!mainWindow.isVisible()) {
mainWindow.show();
}
mainWindow.focus();
}
}
},
{
label: '隱藏視窗',
click: () => {
if (mainWindow) {
mainWindow.hide();
}
}
},
{ type: 'separator' },
{
label: '退出',
click: () => {
isQuitting = true;
app.quit();
}
}
]);

tray.setToolTip('EQ RTS Map');
tray.setContextMenu(contextMenu);

tray.on('click', () => {
if (mainWindow) {
if (mainWindow.isVisible()) {
mainWindow.hide();
} else {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.show();
mainWindow.focus();
}
}
});
};

let mainWindow: BrowserWindow | null;
let tray: Tray | null = null;
let isQuitting = false;

const createMainWindow = async (): Promise<BrowserWindow> => {
Expand Down Expand Up @@ -125,10 +190,26 @@ autoUpdater.on('error', (err) => {
}
});

app.on('second-instance', () => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}

if (!mainWindow.isVisible()) {
mainWindow.show();
}

mainWindow.focus();
mainWindow.moveTop();
}
});

(async () => {
await app.whenReady();

setupDock();
createTray();

ipcMain.handle('get-app-version', () => {
return app.getVersion();
Expand Down Expand Up @@ -258,7 +339,7 @@ autoUpdater.on('error', (err) => {
})();

app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
if (!tray && process.platform !== 'darwin') {
app.quit();
}
});
Expand All @@ -271,6 +352,11 @@ app.on('will-quit', () => {
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.removeAllListeners();
}

if (tray) {
tray.destroy();
tray = null;
}
});

ipcMain.handle('force-quit', async () => {
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eq-rts-map",
"version": "1.0.0-beta.13",
"version": "1.0.0-rc.2",
"description": "EQ RTS Map",
"author": "ExpTech Studio <ExpTech.tw@gmail.com>",
"type": "module",
Expand All @@ -20,12 +20,11 @@
"dependencies": {
"@electron/remote": "^2.1.3",
"electron-serve": "^3.0.0",
"electron-updater": "^6.6.2"
"electron-updater": "^6.6.2",
"webfft": "^1.0.3"
},
"devDependencies": {
"@radix-ui/react-slot": "^1.2.3",
"electronmon": "^2.0.3",
"wait-on": "^9.0.1",
"@tailwindcss/postcss": "^4.1.14",
"@types/bun": "latest",
"@types/node": "^24.8.1",
Expand All @@ -40,13 +39,13 @@
"cross-env": "^10.1.0",
"electron": "^38.3.0",
"electron-builder": "^26.0.12",
"electronmon": "^2.0.3",
"lucide-react": "^0.546.0",
"maplibre-gl": "^5.9.0",
"next": "^15.5.5",
"next": "15.5.7",
"next-themes": "^0.4.6",
"postcss": "^8.5.6",
"react": "^19.2.0",
"react-chartjs-2": "^5.3.0",
"react-dom": "^19.2.0",
"react-map-gl": "^8.1.0",
"tailwind-merge": "^3.3.1",
Expand All @@ -56,10 +55,11 @@
"ts-node": "^10.9.2",
"tsconfig-paths-webpack-plugin": "^4.2.0",
"typescript": "^5.9.3",
"wait-on": "^9.0.1",
"webpack": "^5.102.1",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-cli": "^6.0.1",
"webpack-merge": "^6.0.1",
"webpack-node-externals": "^3.0.0"
}
}
}
Loading