start server in both dev and when packaged
This commit is contained in:
parent
2d49197b3b
commit
66bbf05918
2 changed files with 33 additions and 50 deletions
|
@ -38,27 +38,10 @@ if (require('electron-squirrel-startup')) {
|
||||||
|
|
||||||
const ollama = path.join(process.resourcesPath, 'ollama')
|
const ollama = path.join(process.resourcesPath, 'ollama')
|
||||||
|
|
||||||
// if the app is packaged then run the server
|
|
||||||
if (app.isPackaged) {
|
|
||||||
// Start the executable
|
|
||||||
console.log(`Starting server`)
|
|
||||||
const proc = spawn(ollama, ['serve'])
|
|
||||||
proc.stdout.on('data', data => {
|
|
||||||
console.log(`server: ${data}`)
|
|
||||||
})
|
|
||||||
proc.stderr.on('data', data => {
|
|
||||||
console.error(`server: ${data}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
process.on('exit', () => {
|
|
||||||
proc.kill()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function server() {
|
function server() {
|
||||||
const binary = app.isPackaged
|
const binary = app.isPackaged
|
||||||
? path.join(process.resourcesPath, 'ollama')
|
? path.join(process.resourcesPath, 'ollama')
|
||||||
: path.resolve(__dirname, '..', '..', 'ollama')
|
: path.resolve(process.cwd(), '..', 'ollama')
|
||||||
|
|
||||||
console.log(`Starting server`)
|
console.log(`Starting server`)
|
||||||
const proc = spawn(binary, ['serve'])
|
const proc = spawn(binary, ['serve'])
|
||||||
|
@ -118,44 +101,46 @@ app.on('ready', () => {
|
||||||
app.setLoginItemSettings({ openAtLogin: app.getLoginItemSettings().openAtLogin })
|
app.setLoginItemSettings({ openAtLogin: app.getLoginItemSettings().openAtLogin })
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!app.isInApplicationsFolder()) {
|
if (app.isPackaged) {
|
||||||
const chosen = dialog.showMessageBoxSync({
|
if (!app.isInApplicationsFolder()) {
|
||||||
type: 'question',
|
const chosen = dialog.showMessageBoxSync({
|
||||||
buttons: ['Move to Applications', 'Do Not Move'],
|
type: 'question',
|
||||||
message: 'Ollama works best when run from the Applications directory.',
|
buttons: ['Move to Applications', 'Do Not Move'],
|
||||||
defaultId: 0,
|
message: 'Ollama works best when run from the Applications directory.',
|
||||||
cancelId: 1,
|
defaultId: 0,
|
||||||
})
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
installCLI()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createSystemtray()
|
createSystemtray()
|
||||||
|
|
||||||
if (app.isPackaged) {
|
server()
|
||||||
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
|
||||||
|
|
|
@ -4,8 +4,6 @@ import Store from 'electron-store'
|
||||||
|
|
||||||
const store = new Store()
|
const store = new Store()
|
||||||
|
|
||||||
console.log(process.env)
|
|
||||||
|
|
||||||
export const analytics = new Analytics({ writeKey: process.env.TELEMETRY_WRITE_KEY || '<empty>' })
|
export const analytics = new Analytics({ writeKey: process.env.TELEMETRY_WRITE_KEY || '<empty>' })
|
||||||
|
|
||||||
export function id(): string {
|
export function id(): string {
|
||||||
|
|
Loading…
Add table
Reference in a new issue