Skip to content

Commit

Permalink
nwjs/tray: fix attaching menu to new tray icon
Browse files Browse the repository at this point in the history
When "closing to tray" and re-launching the application, the sent
"open" event always rebuilds the tray icon when "external commands"
and advanced settings are enabled. The existing tray icon menu object
is re-used in this case and gets attached to the new tray icon object.

For some reason though, the menu is sometimes missing, resulting in
a state where the user can't close the application anymore without
changing the tray icon settings. This is apparently caused by a timing
issue in NW.js.

Increasing the delay when re-attaching the menu seems to fix the issue.
  • Loading branch information
bastimeyer committed May 14, 2023
1 parent 3b3c61a commit 1d9943d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/app/nwjs/Tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "nwjs/Window";
import { platform } from "utils/node/platform";
import t from "translation-key";
import { nextTick } from "process";
import { setTimeout } from "timers";


const { "display-name": displayName } = mainConfig;
Expand Down Expand Up @@ -101,7 +101,8 @@ export default EmberObject.extend( Evented, {
tooltip: displayName
});
this.tray.on( "click", ( ...args ) => this.trigger( "click", ...args ) );
nextTick( () => this.menu.trigger( "update" ) );
// (re-)attaching the menu to the new tray icon requires a certain delay
setTimeout( () => this.menu.trigger( "update" ), 10 );
},

_removeTray() {
Expand Down

0 comments on commit 1d9943d

Please sign in to comment.