nova-betterchat/electron/index.cjs
Jing Hua 4903399d56
feat: desktop app (#169)
* electron

* github actions

* fix publish.yml

* more concise

* update linux target

* gitignore add newline
2023-03-30 13:58:59 +08:00

47 lines
953 B
JavaScript

const path = require('path');
const { app, BrowserWindow } = require('electron');
const isDev = require('electron-is-dev');
if (require('electron-squirrel-startup')) app.quit();
function createWindow() {
let iconPath = '';
if (isDev) {
iconPath = path.join(__dirname, '../public/favicon-516x516.png');
} else {
iconPath = path.join(__dirname, '../dist/favicon-516x516.png');
}
const win = new BrowserWindow({
show: false,
icon: iconPath,
});
win.maximize();
win.show();
win.loadURL(
isDev
? 'http://localhost:5173'
: `file://${path.join(__dirname, '../dist/index.html')}`
);
if (isDev) {
win.webContents.openDevTools({ mode: 'detach' });
}
}
app.whenReady().then(createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});