prompt to install the ollama cli on macOS

This commit is contained in:
Jeffrey Morgan 2023-07-06 12:02:13 -04:00
parent 926ffa7f8c
commit 4f3cfea646

View file

@ -1,5 +1,5 @@
import { app, BrowserWindow, autoUpdater, dialog } from 'electron' import { app, BrowserWindow, autoUpdater, dialog } from 'electron'
import { spawn } from 'child_process' import { spawn, exec } from 'child_process'
import * as path from 'path' import * as path from 'path'
require('@electron/remote/main').initialize() require('@electron/remote/main').initialize()
@ -39,13 +39,11 @@ const createWindow = (): void => {
// if the app is packaged then run the server // if the app is packaged then run the server
if (app.isPackaged) { if (app.isPackaged) {
const resources = process.resourcesPath const ollama = path.join(process.resourcesPath, 'ollama')
console.log(resources)
// Start the executable // Start the executable
const exec = path.join(resources, 'ollama') console.log(`Starting server`)
console.log(`Starting ${exec}`) const proc = spawn(ollama, ['serve'])
const proc = spawn(exec, ['serve'])
proc.stdout.on('data', data => { proc.stdout.on('data', data => {
console.log(`server: ${data}`) console.log(`server: ${data}`)
}) })
@ -58,10 +56,40 @@ if (app.isPackaged) {
}) })
} }
function installCLI() {
dialog
.showMessageBox({
type: 'info',
title: 'Ollama CLI installation',
message: 'To install the ollama CLI, we need your permission. You will be prompted to confirm.',
buttons: ['OK'],
})
.then(result => {
if (result.response === 0) {
let resourcePath = path.join(process.resourcesPath, 'your_binary')
let command = `
do shell script "ln -F -s ${resourcePath} /usr/local/bin/ollama" with administrator privileges
`
exec(`osascript -e '${command}'`, (error: Error | null, stdout: string, stderr: string) => {
if (error) {
console.error(`exec error: ${error}`)
return
}
console.log(`stdout: ${stdout}`)
console.error(`stderr: ${stderr}`)
})
}
})
}
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs. // Some APIs can only be used after this event occurs.
app.on('ready', createWindow) app.on('ready', () => {
createWindow()
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
@ -91,6 +119,10 @@ setInterval(() => {
autoUpdater.checkForUpdates() autoUpdater.checkForUpdates()
}, 60000) }, 60000)
autoUpdater.on('error', e => {
console.error('update check failed', e)
})
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => { autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
dialog dialog
.showMessageBox({ .showMessageBox({