Skip to content

Commit

Permalink
fix: enable check for update on all supported platforms (janhq#1626)
Browse files Browse the repository at this point in the history
* fix: enable check for update on all supported platforms

* fix: janhq#1622 - wrong no update dialog present

* chore: update user guide url
  • Loading branch information
louis-jan authored Jan 17, 2024
1 parent a5e5545 commit f293e11
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 78 deletions.
2 changes: 1 addition & 1 deletion electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createUserSpace } from './utils/path'
* Managers
**/
import { WindowManager } from './managers/window'
import { log, ModuleManager } from '@janhq/core/node'
import { log } from '@janhq/core/node'

/**
* IPC Handlers
Expand Down
140 changes: 63 additions & 77 deletions electron/utils/menu.ts
Original file line number Diff line number Diff line change
@@ -1,110 +1,96 @@
// @ts-nocheck
import { app, Menu, dialog, shell } from "electron";
const isMac = process.platform === "darwin";
const { autoUpdater } = require("electron-updater");
import { compareSemanticVersions } from "./versionDiff";
import { app, Menu, dialog, shell } from 'electron'
const isMac = process.platform === 'darwin'
import { autoUpdater } from 'electron-updater'
import { compareSemanticVersions } from './versionDiff'

const template: (Electron.MenuItemConstructorOptions | Electron.MenuItem)[] = [
...(isMac
? [
{
label: app.name,
submenu: [
{ role: "about" },
{
label: "Check for Updates...",
click: () =>
autoUpdater.checkForUpdatesAndNotify().then((e) => {
if (
!e ||
compareSemanticVersions(
app.getVersion(),
e.updateInfo.version
) >= 0
)
dialog.showMessageBox({
message: `There are currently no updates available.`,
});
}),
},
{ type: "separator" },
{ role: "services" },
{ type: "separator" },
{ role: "hide" },
{ role: "hideOthers" },
{ role: "unhide" },
{ type: "separator" },
{ role: "quit" },
],
},
]
: []),
{
label: "Edit",
label: app.name,
submenu: [
{ role: 'about' },
{
label: 'Check for Updates...',
click: () =>
// Check for updates and notify user if there are any
autoUpdater.checkForUpdatesAndNotify(),
},
{ type: 'separator' },
{ role: 'services' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' },
],
},
{
label: 'Edit',
submenu: [
{ role: "undo" },
{ role: "redo" },
{ type: "separator" },
{ role: "cut" },
{ role: "copy" },
{ role: "paste" },
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
...(isMac
? [
{ role: "pasteAndMatchStyle" },
{ role: "delete" },
{ role: "selectAll" },
{ type: "separator" },
{ role: 'pasteAndMatchStyle' },
{ role: 'delete' },
{ role: 'selectAll' },
{ type: 'separator' },
{
label: "Speech",
submenu: [{ role: "startSpeaking" }, { role: "stopSpeaking" }],
label: 'Speech',
submenu: [{ role: 'startSpeaking' }, { role: 'stopSpeaking' }],
},
]
: [{ role: "delete" }, { type: "separator" }, { role: "selectAll" }]),
: [{ role: 'delete' }, { type: 'separator' }, { role: 'selectAll' }]),
],
},
{
label: "View",
label: 'View',
submenu: [
{ role: "reload" },
{ role: "forceReload" },
{ role: "toggleDevTools" },
{ type: "separator" },
{ role: "resetZoom" },
{ role: "zoomIn" },
{ role: "zoomOut" },
{ type: "separator" },
{ role: "togglefullscreen" },
{ role: 'reload' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' },
],
},
{
label: "Window",
label: 'Window',
submenu: [
{ role: "minimize" },
{ role: "zoom" },
{ role: 'minimize' },
{ role: 'zoom' },
...(isMac
? [
{ type: "separator" },
{ role: "front" },
{ type: "separator" },
{ role: "window" },
{ type: 'separator' },
{ role: 'front' },
{ type: 'separator' },
{ role: 'window' },
]
: [{ role: "close" }]),
: [{ role: 'close' }]),
],
},
{
role: "help",
role: 'help',
submenu: [
{
label: "Learn More",
label: 'Learn More',
click: async () => {
await shell.openExternal("https://jan.ai/");
await shell.openExternal('https://jan.ai/guides/')
},
},
],
},
];
]

export const setupMenu = () => {
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
};
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
}

0 comments on commit f293e11

Please sign in to comment.