Commit 963c2025 authored by Jeffrey Morgan's avatar Jeffrey Morgan
Browse files

quit sooner with single instance lock

parent f93ffb96
...@@ -8,7 +8,11 @@ import { analytics, id } from './telemetry' ...@@ -8,7 +8,11 @@ import { analytics, id } from './telemetry'
require('@electron/remote/main').initialize() require('@electron/remote/main').initialize()
let tray: Tray | null = null let tray: Tray | null = null
const SingleInstanceLock = app.requestSingleInstanceLock() const SingleInstanceLock = app.requestSingleInstanceLock()
if (!SingleInstanceLock) {
app.quit()
}
const createSystemtray = () => { const createSystemtray = () => {
let brightModeIconPath = path.join(__dirname, '..', '..', 'assets', 'ollama_icon_dark_16x16.png') let brightModeIconPath = path.join(__dirname, '..', '..', 'assets', 'ollama_icon_dark_16x16.png')
...@@ -108,53 +112,49 @@ function installCLI() { ...@@ -108,53 +112,49 @@ function installCLI() {
}) })
} }
if (!SingleInstanceLock) { app.on('ready', () => {
app.quit() if (process.platform === 'darwin') {
} else { app.dock.hide()
app.on('ready', () => {
if (process.platform === 'darwin') { if (!app.isInApplicationsFolder()) {
app.dock.hide() const chosen = dialog.showMessageBoxSync({
type: 'question',
if (!app.isInApplicationsFolder()) { buttons: ['Move to Applications', 'Do Not Move'],
const chosen = dialog.showMessageBoxSync({ message: 'Ollama works best when run from the Applications directory.',
type: 'question', defaultId: 0,
buttons: ['Move to Applications', 'Do Not Move'], cancelId: 1,
message: 'Ollama works best when run from the Applications directory.', })
defaultId: 0,
cancelId: 1, if (chosen === 0) {
}) try {
app.moveToApplicationsFolder({
if (chosen === 0) { conflictHandler: conflictType => {
try { if (conflictType === 'existsAndRunning') {
app.moveToApplicationsFolder({ dialog.showMessageBoxSync({
conflictHandler: conflictType => { type: 'info',
if (conflictType === 'existsAndRunning') { message: 'Cannot move to Applications directory',
dialog.showMessageBoxSync({ detail:
type: 'info', 'Another version of Ollama is currently running from your Applications directory. Close it first and try again.',
message: 'Cannot move to Applications directory', })
detail: }
'Another version of Ollama is currently running from your Applications directory. Close it first and try again.', return true
}) },
} })
return true return
}, } catch (e) {
}) console.error('Failed to move to applications folder')
return console.error(e)
} catch (e) {
console.error('Failed to move to applications folder')
console.error(e)
}
} }
} }
} }
}
createSystemtray() createSystemtray()
if (app.isPackaged) { if (app.isPackaged) {
installCLI() installCLI()
} }
}) })
}
// Quit when all windows are closed, except on macOS. There, it's common // Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits // for applications and their menu bar to stay active until the user quits
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment