fyne-io / systray

a cross platfrom Go library to place an icon and menu in the notification area
Apache License 2.0
245 stars 49 forks source link

Proposal for #39 #40

Closed EssGeeEich closed 1 year ago

EssGeeEich commented 1 year ago

This fixes bug #39 on Windows.

Not being familiar with Darwin, I have made some changes that I believe make sense, but they need a double-check. Moreover, I didn't dig deep with Linux since I'm currently unable to test.

TODO:

andydotxyz commented 1 year ago

Looks like a good start, thanks

andydotxyz commented 1 year ago

I was just working on macOS for this and it seems like the parent parameter is not needed. The following code worked in my tests:

- (void) add_separator:(NSNumber*) menuID
{
  NSMenuItem* menuItem = find_menu_item(menu, menuID);
  if (menuItem != NULL) {
    [menuItem.submenu addItem: [NSMenuItem separatorItem]];
  } else {
    [menu addItem: [NSMenuItem separatorItem]];
  }
}

(FYI there are Darwin compile errors in the current code, but using the above, and returning the C function to:

void add_separator(int menuId, int parentId) {
  NSNumber *pId = [NSNumber numberWithInt:parentId];
  runInMainThread(@selector(add_separator:), (id)pId);
}

fixes it :).

andydotxyz commented 1 year ago

I completed this but couldn't push onto this PR, so I included the commit as the base of #41 - hopefully we can get it in v2.3.2.

andydotxyz commented 1 year ago

Closing in favour of #41