quit sooner with single instance lock
This commit is contained in:
parent
f93ffb9695
commit
963c20254e
1 changed files with 40 additions and 40 deletions
|
@ -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() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SingleInstanceLock) {
|
app.on('ready', () => {
|
||||||
app.quit()
|
if (process.platform === 'darwin') {
|
||||||
} else {
|
app.dock.hide()
|
||||||
app.on('ready', () => {
|
|
||||||
if (process.platform === 'darwin') {
|
|
||||||
app.dock.hide()
|
|
||||||
|
|
||||||
if (!app.isInApplicationsFolder()) {
|
if (!app.isInApplicationsFolder()) {
|
||||||
const chosen = dialog.showMessageBoxSync({
|
const chosen = dialog.showMessageBoxSync({
|
||||||
type: 'question',
|
type: 'question',
|
||||||
buttons: ['Move to Applications', 'Do Not Move'],
|
buttons: ['Move to Applications', 'Do Not Move'],
|
||||||
message: 'Ollama works best when run from the Applications directory.',
|
message: 'Ollama works best when run from the Applications directory.',
|
||||||
defaultId: 0,
|
defaultId: 0,
|
||||||
cancelId: 1,
|
cancelId: 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (chosen === 0) {
|
if (chosen === 0) {
|
||||||
try {
|
try {
|
||||||
app.moveToApplicationsFolder({
|
app.moveToApplicationsFolder({
|
||||||
conflictHandler: conflictType => {
|
conflictHandler: conflictType => {
|
||||||
if (conflictType === 'existsAndRunning') {
|
if (conflictType === 'existsAndRunning') {
|
||||||
dialog.showMessageBoxSync({
|
dialog.showMessageBoxSync({
|
||||||
type: 'info',
|
type: 'info',
|
||||||
message: 'Cannot move to Applications directory',
|
message: 'Cannot move to Applications directory',
|
||||||
detail:
|
detail:
|
||||||
'Another version of Ollama is currently running from your Applications directory. Close it first and try again.',
|
'Another version of Ollama is currently running from your Applications directory. Close it first and try again.',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to move to applications folder')
|
console.error('Failed to move to applications folder')
|
||||||
console.error(e)
|
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
|
||||||
|
|
Loading…
Add table
Reference in a new issue