From 5ca57e446ac468f3050727c6a79131b86efacd56 Mon Sep 17 00:00:00 2001 From: Lea Anthony Date: Fri, 1 Jan 2021 12:37:16 +1100 Subject: [PATCH] Extra guards during destroy --- ...logicons.c => defaultdialogicons_darwin.c} | 2 +- v2/internal/ffenestri/ffenestri_darwin.c | 10 +++- v2/test/kitchensink/assets/README.md | 59 +++++++++++++++++++ 3 files changed, 69 insertions(+), 2 deletions(-) rename v2/internal/ffenestri/{defaultdialogicons.c => defaultdialogicons_darwin.c} (99%) create mode 100644 v2/test/kitchensink/assets/README.md diff --git a/v2/internal/ffenestri/defaultdialogicons.c b/v2/internal/ffenestri/defaultdialogicons_darwin.c similarity index 99% rename from v2/internal/ffenestri/defaultdialogicons.c rename to v2/internal/ffenestri/defaultdialogicons_darwin.c index 7e3a89e9..0c79a6b5 100644 --- a/v2/internal/ffenestri/defaultdialogicons.c +++ b/v2/internal/ffenestri/defaultdialogicons_darwin.c @@ -1,4 +1,4 @@ -// defaultdialogicons.c +// defaultdialogicons_darwin.c // Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL. // This file was auto-generated. DO NOT MODIFY. diff --git a/v2/internal/ffenestri/ffenestri_darwin.c b/v2/internal/ffenestri/ffenestri_darwin.c index 85d8a2bf..e5cfba9f 100644 --- a/v2/internal/ffenestri/ffenestri_darwin.c +++ b/v2/internal/ffenestri/ffenestri_darwin.c @@ -889,6 +889,10 @@ int releaseNSObject(void *const context, struct hashmap_element_s *const e) { void destroyMenu(struct Application *app) { + if( app->menuAsJSON == NULL ) { + return; + } + // Free menu item hashmap hashmap_destroy(&menuItemMapForApplicationMenu); @@ -908,7 +912,7 @@ void destroyMenu(struct Application *app) { app->processedMenu = NULL; } - // Remove the current Menu + // Remove the menu if we have one id menubar = msg(msg(c("NSApplication"), s("sharedApplication")), s("mainMenu")); Debug(app, "Destroying menubar: %p", menubar); msg(menubar, s("release")); @@ -966,6 +970,10 @@ void freeDialogIconCache(struct Application *app) { void destroyTray(struct Application *app) { + if( app->trayMenuAsJSON == NULL ) { + return; + } + // Release the tray cache images if( hashmap_num_entries(&trayIconCache) > 0 ) { if (0!=hashmap_iterate_pairs(&trayIconCache, releaseNSObject, NULL)) { diff --git a/v2/test/kitchensink/assets/README.md b/v2/test/kitchensink/assets/README.md new file mode 100644 index 00000000..62c25209 --- /dev/null +++ b/v2/test/kitchensink/assets/README.md @@ -0,0 +1,59 @@ +# Assets Directory + +The assets directory is used to house all the assets of your application. + +The structure is: + + * dialog - Icons for dialogs + * tray - Icons for the system tray + * custom - A place for assets you wish to bundle in the application + * mac - MacOS specific files + * linux - Linux specific files + * windows - Windows specific files + +## Dialog Icons + +Place any PNG file in this directory to be able to use them in message dialogs. +The files should have names in the following format: `name[-(light|dark)][2x].png` + +Examples: + +* `mypic.png` - Standard definition icon with ID `mypic` +* `mypic-light.png` - Standard definition icon with ID `mypic`, used when system theme is light +* `mypic-dark.png` - Standard definition icon with ID `mypic`, used when system theme is dark +* `mypic2x.png` - High definition icon with ID `mypic` +* `mypic-light2x.png` - High definition icon with ID `mypic`, used when system theme is light +* `mypic-dark2x.png` - High definition icon with ID `mypic`, used when system theme is dark + +### Order of preference + +Icons are selected with the following order of preference: + +For High Definition displays: +* name-(theme)2x.png +* name2x.png +* name-(theme).png +* name.png + +For Standard Definition displays: +* name-(theme).png +* name.png + +## Tray + +Place any PNG file in this directory to be able to use them as tray icons. +The name of the filename will be the ID to reference the image. + +Example: + +* `mypic.png` - May be referenced using `runtime.Tray.SetIcon("mypic")` + +## Custom + +Any file in this directory will be embedded into the app using the Wails asset bundler. +Assets can be retrieved using the following methods: + +* `wails.Assets().Read(filename string) ([]byte, error)` +* `wails.Assets().String(filename string) (string, error)` + +The filename should include the path to the file relative to the `custom` directory. \ No newline at end of file