From 776e7bb5e4630ba6d22bd4ab77a0f90763a446c1 Mon Sep 17 00:00:00 2001 From: jmorganca Date: Sat, 27 Apr 2024 15:57:57 -0400 Subject: [PATCH] app: fix status item icons --- app/AppDelegate.m | 79 ++++----------- app/app_darwin.go | 9 +- app/app_darwin.m | 2 +- app/app_windows.go | 8 +- .../Ollama.app/Contents/Resources/icon.png | Bin 363 -> 382 bytes .../Ollama.app/Contents/Resources/icon@2x.png | Bin 668 -> 691 bytes .../Contents/Resources/iconDark.png | Bin 381 -> 382 bytes .../Contents/Resources/iconDark@2x.png | Bin 768 -> 721 bytes app/lifecycle/lifecycle.go | 92 ------------------ app/{server_unix.go => server_darwin.go} | 2 - scripts/publish.sh | 25 ----- scripts/run_darwin.sh | 1 + 12 files changed, 31 insertions(+), 187 deletions(-) delete mode 100644 app/lifecycle/lifecycle.go rename app/{server_unix.go => server_darwin.go} (96%) delete mode 100755 scripts/publish.sh diff --git a/app/AppDelegate.m b/app/AppDelegate.m index 16bc9202..009bd3aa 100644 --- a/app/AppDelegate.m +++ b/app/AppDelegate.m @@ -22,24 +22,33 @@ // user about what this is doing, and ideally use Touch ID. // or add an alias in the current shell environment, // which wouldn't require any special privileges - dispatch_async(dispatch_get_main_queue(), ^{ - createSymlinkWithAuthorization(); - }); + // dispatch_async(dispatch_get_main_queue(), ^{ + // createSymlinkWithAuthorization(); + // }); // show status menu NSMenu *menu = [[NSMenu alloc] init]; - - NSMenuItem *openSettingsItem = [[NSMenuItem alloc] initWithTitle:@"Settings..." action:@selector(openSettingsWindow) keyEquivalent:@""]; - [menu addItem:openSettingsItem]; - [menu addItem:[NSMenuItem separatorItem]]; [menu addItemWithTitle:@"Quit Ollama" action:@selector(quit) keyEquivalent:@"q"]; self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; + [self.statusItem addObserver:self forKeyPath:@"button.effectiveAppearance" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionInitial context:nil]; + self.statusItem.menu = menu; - NSImage *statusImage = [NSImage imageNamed:@"icon"]; + [self showIcon]; +} + +-(void) showIcon { + NSAppearance* appearance = self.statusItem.button.effectiveAppearance; + NSString* appearanceName = (NSString*)(appearance.name); + NSString* iconName = [[appearanceName lowercaseString] containsString:@"dark"] ? @"iconDark" : @"icon"; + NSImage* statusImage = [NSImage imageNamed:iconName]; [statusImage setTemplate:YES]; self.statusItem.button.image = statusImage; } +-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + [self showIcon]; +} + - (void)openSettingsWindow { if (!self.settingsWindow) { // Create the settings window centered on the screen @@ -66,57 +75,8 @@ } } -#pragma mark - NSToolbarDelegate - -- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSToolbarItemIdentifier)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag { - NSToolbarItem *toolbarItem = [[NSToolbarItem alloc] initWithItemIdentifier:itemIdentifier]; - - if ([itemIdentifier isEqualToString:@"General"]) { - toolbarItem.label = @"General"; - toolbarItem.paletteLabel = @"General"; - toolbarItem.toolTip = @"General Settings"; - toolbarItem.image = [NSImage imageWithSystemSymbolName:@"gear" accessibilityDescription:nil]; // Monochrome symbol - toolbarItem.target = self; - toolbarItem.action = @selector(switchTabs:); - } - - if ([itemIdentifier isEqualToString:@"Networking"]) { - toolbarItem.label = @"Networking"; - toolbarItem.paletteLabel = @"Networking"; - toolbarItem.toolTip = @"Networking Settings"; - toolbarItem.image = [NSImage imageWithSystemSymbolName:@"network" accessibilityDescription:nil]; // Monochrome symbol - toolbarItem.target = self; - toolbarItem.action = @selector(switchTabs:); - } - // Create other items with their respective images and selectors here... - - return toolbarItem; -} - -- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar { - return @[ - NSToolbarFlexibleSpaceItemIdentifier, - @"General", - @"Networking", - NSToolbarFlexibleSpaceItemIdentifier - ]; -} - -- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar { - return @[ - NSToolbarFlexibleSpaceItemIdentifier, - @"General", - @"Networking", - NSToolbarFlexibleSpaceItemIdentifier - ]; -} - -- (void)switchTabs:(NSToolbarItem *)sender { - // Your code to switch tabs based on the sender's identifier -} - - (void)quit { - Quit(); + [NSApp stop:nil]; } @end @@ -132,12 +92,13 @@ int askToMoveToApplications() { [alert setInformativeText:@"Ollama works best when run from the Applications directory."]; [alert addButtonWithTitle:@"Move to Applications"]; [alert addButtonWithTitle:@"Don't move"]; - + [NSApp activateIgnoringOtherApps:YES]; if ([alert runModal] != NSAlertFirstButtonReturn) { return 0; } + // move to applications NSString *applicationsPath = @"/Applications"; NSString *newPath = [applicationsPath stringByAppendingPathComponent:@"Ollama.app"]; diff --git a/app/app_darwin.go b/app/app_darwin.go index bf264038..2f6e5dbb 100644 --- a/app/app_darwin.go +++ b/app/app_darwin.go @@ -33,21 +33,22 @@ func run() { panic(err) } - resources := filepath.Join(filepath.Dir(exe), "..", "Resources") - ctx, cancel := context.WithCancel(context.Background()) var done chan int - done, err = SpawnServer(ctx, filepath.Join(resources, "ollama")) + done, err = SpawnServer(ctx, filepath.Join(filepath.Dir(exe), "..", "Resources", "ollama")) if err != nil { slog.Error(fmt.Sprintf("Failed to spawn ollama server %s", err)) done = make(chan int, 1) done <- 1 } - // Run the native app + // Run the native macOS app + // Note: this will block until the app is closed C.run() + slog.Info("ollama macOS app closed") + cancel() slog.Info("Waiting for ollama server to shutdown...") if done != nil { diff --git a/app/app_darwin.m b/app/app_darwin.m index c2366af7..34ce69d1 100644 --- a/app/app_darwin.m +++ b/app/app_darwin.m @@ -38,4 +38,4 @@ void killOtherInstances() { [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; } } -} \ No newline at end of file +} diff --git a/app/app_windows.go b/app/app_windows.go index b4b84ced..91ff04ab 100644 --- a/app/app_windows.go +++ b/app/app_windows.go @@ -13,10 +13,10 @@ import ( "strings" "syscall" - "github.com/jmorganca/ollama/app/lifecycle" - "github.com/jmorganca/ollama/app/store" - "github.com/jmorganca/ollama/app/tray" - "github.com/jmorganca/ollama/app/updater" + "github.com/ollama/ollama/app/lifecycle" + "github.com/ollama/ollama/app/store" + "github.com/ollama/ollama/app/tray" + "github.com/ollama/ollama/app/updater" ) func init() { diff --git a/app/darwin/Ollama.app/Contents/Resources/icon.png b/app/darwin/Ollama.app/Contents/Resources/icon.png index 1e826e037c63192ad208b14de39c2b2036664170..385972c2034b4b10989e3e5cd0505b2cf28fe1f4 100644 GIT binary patch delta 340 zcmV-a0jvJ&0{#LaiBL{Q4GJ0x0000DNk~Le0000G0000H2nGNE0MxH6#E~I2e-lYW zK~#7Fjg!5V!Y~ko=YI0zvI}(?*|~)40EcAI0dznM&;ev*Km~>hfQ-yg0gw^0`!s@m zLN?5MU!eVyJd%M&bp@A*XUx?~3kqSK$d!!$+u&znmyyt6VaE7L*a~AI7nY&nJsQwp z@mZL0tr`eN=Dtv)84DF>;*PPBe>F*U;lHtgYB|>AspJ}I_hYFqMOau9b>}_&_pXFL zcq0$+$6v8|XgB&W19BFtflc8}SO`1emo*nQYkm?B_!fTPud2z$6Pp54q0Nn!h*aQy z@8D4tb-i!m4#oqk67@F_q&2sfY9G=jIzg4R=8zhoF6S={=)wE+FhH+uDvsw;_gkp} m;Xin$Jt`hthSyDWVQ~eZraL@Ppp-%Y00003`(E_F*3vszzVnyAajg#Z+y!g2g0~B zZ*G6@_D3|76XVU;JAQ4qh)+rYV$LX?SjD&?9!!xV{2n4H1tEp4;|(Jg!pf=KflPQG zRwZrw$Qg;utC2ae1YJo-qn4$$e>suG4f1rQ0=iFTjEGFz;?I#!Yd8*!Cu7IBF}92& zhzW>i#tXW~xJu=i%%-*8AgP3}Ldy|Z8<%Z&WHwnq_wl=eerMFs75$i*&~k;!4Qz5} z-dN7o`79%Id;7MYWA~>DXc1+xW^7YZQ=1^@s6xF)Glks&pINJ&INRCoc!nBh_DFbv24ulK&cZ1Btm zVFJtqlnufL-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(mTe%X&wg t1NX@K6fScc4+%w8u5mwnGxBIRUIE}C?dM_4!chPK002ovPDHLkV1l&uBJcnJ diff --git a/app/darwin/Ollama.app/Contents/Resources/iconDark.png b/app/darwin/Ollama.app/Contents/Resources/iconDark.png index 451cc9d081d104218e1b0b7f4ee0988cb5eeddc8..f3c087b6fcbecf3f181e2623be4ab420d5210d38 100644 GIT binary patch delta 340 zcmV-a0jvJ~0{#LaiBL{Q4GJ0x0000DNk~Le0000G0000G2nGNE03Y-JVUZymEiJz6<^@^2IS0%sEXQ_? z3#4(4Q{-``#S(rU#I;>_Hzf@5ibvg_;!y0VY{UV^5X`Esr(Zh9W%Nr zl${A)oH&v_IbTVXtfQmg{9f13e-X)CAq?E@I9K?ixVeQ^zX@79VRQ*!7ADMoHvOOe)J lTIKiv*5Uc9%H=uhMK@`XTm1R++(Tl>$ zpa(rLYL!&rqQ@fJwTm`E5VfdHv`7TO$5LFl5nPBXS0XM1ABYHwf*_~}qTG!u7kULn z@pV1NIUkJo-ub?naW?+p$IP9XGjr~pbIvGm3{*t?hr50d7ZE_;i40NUVDn6D{w6Jd zJc(p|mbMc1`XcSCq=hyP+?4h)?DbsQCrJx!94L|YHtcm-+Dl0bZ5)VHp!GiyBT)Cu zj1h0N`6&2KBY;`loO%&%lsKDSr84joD64YH@)yBq&8K_jd zN4(VL_`nU~hJ5Dtq@3u1rM_z356Ku;#2sQl`W&Df@h`;LQmFgRNS`&T?c-9)4}O8j zuv^CN6LV1Cm~&juh(+QbaZ1)a6q_z>O$i(|s2TS{UBheQn~ZG{bwnf7FT-PhKcR|H z3WqCYJ3Mp;xp~ilG%Wp1;v>{+sXJPfWy5=1F&z^37I4s=%i~nP^b3i1#0PDD5-NkT z_qhNMwIMg1I%LCos4IxZ*NFz1%V*aDM{#rz!&+9`P0)>I~>Wm+6qWQv3knR0a}W)V))rir+UR}917aUMzwIob!tfG0BCA!=>_0000G?*r1)d|@9bE8hkC_E>;Qd7T;Kg&Md< zKTk^IWYEnKb7wZr%790V60Dc#C!#|awKw`X`xfVcLB0Yr<80Nu)>aVEd5ts0cnaGuY(bWD;4W4pB;IZI5aEQ_GjFA#?uTL?^g+$#b z{T*T+WK#}Ebd_?bnlb1YYsCCGVEhn!fkdC1`oBle$U1A^2PeQ9~y@UqTd{*`S7+m2APlUf2Ofp@0e(MiGQmLF985yOMV z+DJ~nK&DJzqnc+r5w=yB=9&zD?*)(kNvi1)?*y?wfW5a1jGt~>V?>s%9?_A9&EOn( zV~hkerf%WTCF36RA+}D4Pq=5?ObGuM*j*6dOnnU;S>~obfb3I`ZYIXobm@&KgX?+{ zI||AAZdP!>)7IYDe#Q-^aqU8y1JCl0DU&#$?{(_eY$^3?T5t0tQqS=(HJD@MacY;q qo&{?m!^rt!9cU5?YoNhMaDM?F9)--B2MF%~0000/dev/null 2>&1; then - git tag v$VERSION -fi - -git push origin v$VERSION - -# Create a new release. -gh release create -p v$VERSION -t v$VERSION - -# Upload the zip file. -gh release upload v$VERSION ./dist/* --clobber diff --git a/scripts/run_darwin.sh b/scripts/run_darwin.sh index 89a32a2f..f4a736b2 100755 --- a/scripts/run_darwin.sh +++ b/scripts/run_darwin.sh @@ -2,6 +2,7 @@ set -e +rm -rf $TMPDIR/Ollama.app cp -R app/darwin/Ollama.app $TMPDIR/Ollama.app mkdir -p $TMPDIR/Ollama.app/Contents/Resources $TMPDIR/Ollama.app/Contents/MacOS go build -o $TMPDIR/Ollama.app/Contents/Resources/ollama .