From 7c2bb7642187fd6e68b61627c33a1fd23f5c39fa Mon Sep 17 00:00:00 2001 From: Eva Ho Date: Thu, 6 Jul 2023 16:08:53 -0400 Subject: [PATCH] improve the first time installing experience --- app/src/index.ts | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/app/src/index.ts b/app/src/index.ts index 09d5010c..74e99a52 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -25,7 +25,10 @@ const createSystemtray = () => { }) } - const contextMenu = Menu.buildFromTemplate([{ label: 'Quit', type: 'normal', click: () => app.quit() }]) + + const contextMenu = Menu.buildFromTemplate([ + { role: 'quit', label: 'Quit Ollama', accelerator: 'Command+Q' }, + ]) tray.setContextMenu(contextMenu) tray.setToolTip('Ollama') @@ -90,7 +93,7 @@ function installCLI() { }) .then(result => { if (result.response === 0) { - let command = ` + const command = ` do shell script "ln -F -s ${ollama} /usr/local/bin/ollama" with administrator privileges ` exec(`osascript -e '${command}'`, (error: Error | null, stdout: string, stderr: string) => { @@ -109,8 +112,40 @@ function installCLI() { // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.on('ready', () => { + if (process.platform === 'darwin') { app.dock.hide() + + if (!app.isInApplicationsFolder()) { + const chosen = dialog.showMessageBoxSync({ + type: 'question', + buttons: ['Move to Applications', 'Do Not Move'], + message: 'Move Ollama to the Applications directory?', + defaultId: 0, + cancelId: 1 + }) + + if (chosen === 0) { + try { + app.moveToApplicationsFolder({ + conflictHandler: (conflictType) => { + if (conflictType === 'existsAndRunning') { + dialog.showMessageBoxSync({ + type: 'info', + 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 + } catch (e) { + console.error('Failed to move to applications folder') + console.error(e) + } + } + } } createSystemtray()