From 15b9aa674d73f44fac181706d5bbcb65e98fa1a7 Mon Sep 17 00:00:00 2001 From: Hichem Fantar Date: Fri, 4 Oct 2024 01:48:40 +0100 Subject: [PATCH 1/6] Update index.ts to add toggleAutoStartup function and menu item --- macapp/src/index.ts | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/macapp/src/index.ts b/macapp/src/index.ts index a5d04d5f..f05faeea 100644 --- a/macapp/src/index.ts +++ b/macapp/src/index.ts @@ -1,5 +1,15 @@ import { spawn, ChildProcess } from 'child_process' -import { app, autoUpdater, dialog, Tray, Menu, BrowserWindow, MenuItemConstructorOptions, nativeTheme } from 'electron' +import { + app, + autoUpdater, + dialog, + Tray, + Menu, + BrowserWindow, + MenuItemConstructorOptions, + nativeTheme, + Notification, +} from 'electron' import Store from 'electron-store' import winston from 'winston' import 'winston-daily-rotate-file' @@ -55,6 +65,7 @@ app.on('ready', () => { app.focus({ steal: true }) init() + updateTray() }) function firstRunWindow() { @@ -104,6 +115,21 @@ function updateTrayIcon() { } } +function toggleAutoStartup() { + const currentSettings = app.getLoginItemSettings() + const newOpenAtLogin = !currentSettings.openAtLogin + + app.setLoginItemSettings({ openAtLogin: newOpenAtLogin }) + + const notification = new Notification({ + title: 'Auto Startup', + body: `Auto startup is now ${newOpenAtLogin ? 'enabled' : 'disabled'}`, + }) + notification.show() + + updateTray() +} + function updateTray() { const updateItems: MenuItemConstructorOptions[] = [ { label: 'An update is available', enabled: false }, @@ -114,13 +140,28 @@ function updateTray() { { type: 'separator' }, ] + const isAutoStartupEnabled = app.getLoginItemSettings().openAtLogin + const toggleAutoStartupItem: MenuItemConstructorOptions = { + label: isAutoStartupEnabled ? 'Disable Auto Startup' : 'Enable Auto Startup', + click: () => { + toggleAutoStartup() + }, + } + const menu = Menu.buildFromTemplate([ ...(updateAvailable ? updateItems : []), - { role: 'quit', label: 'Quit Ollama', accelerator: 'Command+Q' }, + toggleAutoStartupItem, + { role: 'about' }, + { role: 'quit', accelerator: 'Command+Q' }, ]) if (!tray) { tray = new Tray(trayIconPath()) + // make sure the tray is updated when clicked to avoid stale info + // e.g. user disables auto startup in system preferences but tray menu still shows it as enabled + tray.on('click', () => { + updateTray() + }) } tray.setToolTip(updateAvailable ? 'An update is available' : 'Ollama') From 13d7a281d2fd1b08b22e5ed1eaf659d248cb6b7d Mon Sep 17 00:00:00 2001 From: Hichem Fantar Date: Fri, 4 Oct 2024 02:24:40 +0100 Subject: [PATCH 2/6] Refactor index.ts to remove unnecessary updateTray() function call --- macapp/src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/macapp/src/index.ts b/macapp/src/index.ts index f05faeea..b4b9bf19 100644 --- a/macapp/src/index.ts +++ b/macapp/src/index.ts @@ -65,7 +65,6 @@ app.on('ready', () => { app.focus({ steal: true }) init() - updateTray() }) function firstRunWindow() { From 6bdf21fb5c873f31c2aefcdae8948363bd385288 Mon Sep 17 00:00:00 2001 From: Hichem Fantar Date: Fri, 4 Oct 2024 04:02:28 +0100 Subject: [PATCH 3/6] autostart info alert --- macapp/src/app.tsx | 69 +++++++++++++++++++++++---------------- macapp/src/index.ts | 4 +-- macapp/tailwind.config.js | 1 + 3 files changed, 44 insertions(+), 30 deletions(-) diff --git a/macapp/src/app.tsx b/macapp/src/app.tsx index 449fc851..3e70f113 100644 --- a/macapp/src/app.tsx +++ b/macapp/src/app.tsx @@ -45,7 +45,7 @@ export default function () { )} {step === Step.CLI && ( <> -
+

Install the command line

> ollama
@@ -74,35 +74,48 @@ export default function () { )} {step === Step.FINISH && ( <> -
+

Run your first model

-
-
-
-                    {command}
-                  
- +
+
+
+
+                      {command}
+                    
+ +
+

+ Run this command in your favorite terminal. +

+
+
+ + {app.getLoginItemSettings().openAtLogin + ? 'Autostart is enabled by default.' + : 'Autostart is disabled by default.'} + +

You can modify this setting in the preferences menu.

-

- Run this command in your favorite terminal. -