mirror of https://github.com/msgbyte/tailchat
feat: desktop auto update or notify and menu
parent
2a95505514
commit
02656b34bd
@ -0,0 +1,11 @@
|
||||
import { app } from 'electron';
|
||||
|
||||
const isDev = !app.isPackaged;
|
||||
const webUrl = isDev
|
||||
? 'http://localhost:11011'
|
||||
: 'https://nightly.paw.msgbyte.com';
|
||||
|
||||
export const config = {
|
||||
isDev,
|
||||
webUrl,
|
||||
};
|
@ -0,0 +1,119 @@
|
||||
import {
|
||||
app,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuItemConstructorOptions,
|
||||
shell,
|
||||
} from 'electron';
|
||||
import { config } from './config';
|
||||
import { checkUpdates } from './update';
|
||||
|
||||
const isMac = process.platform === 'darwin';
|
||||
|
||||
const template = [
|
||||
// { role: 'appMenu' }
|
||||
...(isMac
|
||||
? [
|
||||
{
|
||||
label: app.name,
|
||||
submenu: [
|
||||
{ role: 'about' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'services' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'hide' },
|
||||
{ role: 'hideOthers' },
|
||||
{ role: 'unhide' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'quit' },
|
||||
],
|
||||
},
|
||||
]
|
||||
: []),
|
||||
// { role: 'fileMenu' }
|
||||
{
|
||||
label: 'File',
|
||||
submenu: [isMac ? { role: 'close' } : { role: 'quit' }],
|
||||
},
|
||||
// { role: 'editMenu' }
|
||||
{
|
||||
label: 'Edit',
|
||||
submenu: [
|
||||
{ role: 'undo' },
|
||||
{ role: 'redo' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'cut' },
|
||||
{ role: 'copy' },
|
||||
{ role: 'paste' },
|
||||
...(isMac
|
||||
? [
|
||||
{ role: 'pasteAndMatchStyle' },
|
||||
{ role: 'delete' },
|
||||
{ role: 'selectAll' },
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: 'Speech',
|
||||
submenu: [{ role: 'startSpeaking' }, { role: 'stopSpeaking' }],
|
||||
},
|
||||
]
|
||||
: [{ role: 'delete' }, { type: 'separator' }, { role: 'selectAll' }]),
|
||||
],
|
||||
},
|
||||
// { role: 'viewMenu' }
|
||||
{
|
||||
label: 'View',
|
||||
submenu: [
|
||||
{ role: 'reload' },
|
||||
{ role: 'forceReload' },
|
||||
{ role: 'toggleDevTools' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'resetZoom' },
|
||||
{ role: 'zoomIn' },
|
||||
{ role: 'zoomOut' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'togglefullscreen' },
|
||||
],
|
||||
},
|
||||
// { role: 'windowMenu' }
|
||||
{
|
||||
label: 'Window',
|
||||
submenu: [
|
||||
{ role: 'minimize' },
|
||||
{ role: 'zoom' },
|
||||
...(isMac
|
||||
? [
|
||||
{ type: 'separator' },
|
||||
{ role: 'front' },
|
||||
{ type: 'separator' },
|
||||
{ role: 'window' },
|
||||
]
|
||||
: [{ role: 'close' }]),
|
||||
],
|
||||
},
|
||||
{
|
||||
role: 'help',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Github',
|
||||
click: async () => {
|
||||
await shell.openExternal('https://github.com/msgbyte/tailchat');
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '打开网页版',
|
||||
click: async () => {
|
||||
await shell.openExternal(config.webUrl);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '检查更新',
|
||||
click: async () => {
|
||||
await checkUpdates();
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
] as Array<MenuItemConstructorOptions | MenuItem>;
|
||||
|
||||
const menu = Menu.buildFromTemplate(template);
|
||||
Menu.setApplicationMenu(menu);
|
@ -0,0 +1,36 @@
|
||||
import { app } from 'electron';
|
||||
import {
|
||||
setUpdateNotification,
|
||||
checkForUpdates,
|
||||
} from 'electron-update-notifier';
|
||||
import updateElectronApp from 'update-electron-app';
|
||||
import logger from 'electron-log';
|
||||
|
||||
const repo = 'msgbyte/tailchat';
|
||||
|
||||
app.whenReady().then(() => {
|
||||
switch (process.platform) {
|
||||
// case 'darwin': // NOTICE: require codesign
|
||||
case 'win32':
|
||||
updateElectronApp({
|
||||
repo,
|
||||
logger,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
setUpdateNotification({
|
||||
repository: repo, // Optional, use repository field from your package.json when not specified
|
||||
silent: true, // Optional, notify when new version available, otherwise remain silent
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 手动检查更新
|
||||
*/
|
||||
export function checkUpdates(): Promise<void> {
|
||||
return checkForUpdates({
|
||||
repository: repo,
|
||||
silent: false,
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue