app: remove dialog, icons for updates

This commit is contained in:
Jeffrey Morgan 2023-07-26 14:04:36 -04:00
parent 19d0f2b4cc
commit e751e47d70
10 changed files with 62 additions and 53 deletions

BIN
app/assets/iconTemplate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

View file

Before

Width:  |  Height:  |  Size: 891 B

After

Width:  |  Height:  |  Size: 891 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 403 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 741 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 445 B

View file

@ -19,10 +19,10 @@ const config: ForgeConfig = {
icon: './assets/icon.icns', icon: './assets/icon.icns',
extraResource: [ extraResource: [
'../ollama', '../ollama',
path.join(__dirname, './assets/ollama_icon_16x16Template.png'), path.join(__dirname, './assets/iconTemplate.png'),
path.join(__dirname, './assets/ollama_icon_16x16Template@2x.png'), path.join(__dirname, './assets/iconTemplate@2x.png'),
path.join(__dirname, './assets/ollama_outline_icon_16x16Template.png'), path.join(__dirname, './assets/iconUpdateTemplate.png'),
path.join(__dirname, './assets/ollama_outline_icon_16x16Template@2x.png'), path.join(__dirname, './assets/iconUpdateTemplate@2x.png'),
...(process.platform === 'darwin' ? ['../llama/ggml-metal.metal'] : []), ...(process.platform === 'darwin' ? ['../llama/ggml-metal.metal'] : []),
], ],
...(process.env.SIGN ...(process.env.SIGN

View file

@ -1,5 +1,15 @@
import { spawn } from 'child_process' import { spawn } from 'child_process'
import { app, autoUpdater, dialog, Tray, Menu, BrowserWindow, nativeTheme } from 'electron' import {
app,
autoUpdater,
dialog,
Tray,
Menu,
BrowserWindow,
MenuItemConstructorOptions,
nativeTheme,
systemPreferences,
} from 'electron'
import Store from 'electron-store' import Store from 'electron-store'
import winston from 'winston' import winston from 'winston'
import 'winston-daily-rotate-file' import 'winston-daily-rotate-file'
@ -11,7 +21,7 @@ import { installed } from './install'
require('@electron/remote/main').initialize() require('@electron/remote/main').initialize()
const store = new Store() const store = new Store()
let tray: Tray | null = null
let welcomeWindow: BrowserWindow | null = null let welcomeWindow: BrowserWindow | null = null
declare const MAIN_WINDOW_WEBPACK_ENTRY: string declare const MAIN_WINDOW_WEBPACK_ENTRY: string
@ -61,35 +71,42 @@ function firstRunWindow() {
} }
} }
function createSystemtray() { let tray: Tray | null = null
let iconPath = nativeTheme.shouldUseDarkColors
? path.join(__dirname, '..', '..', 'assets', 'ollama_icon_16x16Template.png')
: path.join(__dirname, '..', '..', 'assets', 'ollama_outline_icon_16x16Template.png')
if (app.isPackaged) { function setTray(updateAvailable: boolean) {
iconPath = nativeTheme.shouldUseDarkColors const menuItemAvailable: MenuItemConstructorOptions = {
? path.join(process.resourcesPath, 'ollama_icon_16x16Template.png') label: 'Restart to update',
: path.join(process.resourcesPath, 'ollama_outline_icon_16x16Template.png') click: () => autoUpdater.quitAndInstall(),
} }
tray = new Tray(iconPath) const menuItemUpToDate: MenuItemConstructorOptions = {
label: 'Ollama is up to date',
enabled: false,
}
nativeTheme.on('updated', function theThemeHasChanged() { const menu = Menu.buildFromTemplate([
if (nativeTheme.shouldUseDarkColors) { ...(updateAvailable
app.isPackaged ? [{ label: 'An update is available', enabled: false }, menuItemAvailable]
? tray.setImage(path.join(process.resourcesPath, 'ollama_icon_16x16Template.png')) : [menuItemUpToDate]),
: tray.setImage(path.join(__dirname, '..', '..', 'assets', 'ollama_icon_16x16Template.png')) { type: 'separator' },
} else { { role: 'quit', label: 'Quit Ollama', accelerator: 'Command+Q' },
app.isPackaged ])
? tray.setImage(path.join(process.resourcesPath, 'ollama_outline_icon_16x16Template.png'))
: tray.setImage(path.join(__dirname, '..', '..', 'assets', 'ollama_outline_icon_16x16Template.png'))
}
})
const contextMenu = Menu.buildFromTemplate([{ role: 'quit', label: 'Quit Ollama', accelerator: 'Command+Q' }]) const iconPath = app.isPackaged
? updateAvailable
? path.join(process.resourcesPath, 'iconUpdateTemplate.png')
: path.join(process.resourcesPath, 'iconTemplate.png')
: updateAvailable
? path.join(__dirname, '..', '..', 'assets', 'iconUpdateTemplate.png')
: path.join(__dirname, '..', '..', 'assets', 'iconTemplate.png')
tray.setContextMenu(contextMenu) if (!tray) {
tray.setToolTip('Ollama') tray = new Tray(iconPath)
}
tray.setToolTip(updateAvailable ? 'An update is available' : 'Ollama')
tray.setContextMenu(menu)
tray.setImage(iconPath)
} }
if (require('electron-squirrel-startup')) { if (require('electron-squirrel-startup')) {
@ -128,6 +145,17 @@ if (process.platform === 'darwin') {
} }
app.on('ready', () => { app.on('ready', () => {
setTray(false)
if (app.isPackaged) {
heartbeat()
autoUpdater.checkForUpdates()
setInterval(() => {
heartbeat()
autoUpdater.checkForUpdates()
}, 60 * 60 * 1000)
}
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
if (app.isPackaged) { if (app.isPackaged) {
if (!app.isInApplicationsFolder()) { if (!app.isInApplicationsFolder()) {
@ -163,7 +191,6 @@ app.on('ready', () => {
} }
} }
createSystemtray()
server() server()
if (store.get('first-time-run') && installed()) { if (store.get('first-time-run') && installed()) {
@ -201,29 +228,10 @@ async function heartbeat() {
}) })
} }
if (app.isPackaged) {
heartbeat()
autoUpdater.checkForUpdates()
setInterval(() => {
heartbeat()
autoUpdater.checkForUpdates()
}, 60 * 60 * 1000)
}
autoUpdater.on('error', e => { autoUpdater.on('error', e => {
console.error(`update check failed - ${e.message}`) console.error(`update check failed - ${e.message}`)
}) })
autoUpdater.on('update-downloaded', (_, releaseNotes, releaseName) => { autoUpdater.on('update-downloaded', () => {
dialog setTray(true)
.showMessageBox({
type: 'info',
buttons: ['Restart Now', 'Later'],
title: 'New update available',
message: process.platform === 'win32' ? releaseNotes : releaseName,
detail: 'A new version of Ollama is available. Restart to apply the update.',
})
.then(returnValue => {
if (returnValue.response === 0) autoUpdater.quitAndInstall()
})
}) })

View file

@ -17,15 +17,16 @@ npm --prefix app run make:sign
# Create a new tag if it doesn't exist. # Create a new tag if it doesn't exist.
if ! git rev-parse v$VERSION >/dev/null 2>&1; then if ! git rev-parse v$VERSION >/dev/null 2>&1; then
git tag v$VERSION git tag v$VERSION
git push origin v$VERSION
fi fi
git push origin v$VERSION
mkdir -p dist mkdir -p dist
cp app/out/make/zip/${OS}/${ARCH}/Ollama-${OS}-${ARCH}-${VERSION}.zip dist/Ollama-${OS}-${ARCH}.zip cp app/out/make/zip/${OS}/${ARCH}/Ollama-${OS}-${ARCH}-${VERSION}.zip dist/Ollama-${OS}-${ARCH}.zip
cp ./ollama dist/ollama-${OS}-${ARCH} cp ./ollama dist/ollama-${OS}-${ARCH}
# Create a new release. # Create a new release.
gh release create -p v$VERSION gh release create -p v$VERSION -t v$VERSION
# Upload the zip file. # Upload the zip file.
gh release upload v$VERSION ./dist/Ollama-${OS}-${ARCH}.zip gh release upload v$VERSION ./dist/Ollama-${OS}-${ARCH}.zip