@@ -136,140 +136,156 @@ class Utils {
136136 }
137137
138138 static Future <void > initTray () async {
139- if ( ! ResponsiveUtil . isDesktop ()) return ;
140- await trayManager. destroy () ;
141- if ( ! ChewieHiveUtil . getBool ( ChewieHiveUtil .showTrayKey)) {
139+ try {
140+ if ( ! ResponsiveUtil . isDesktop ()) return ;
141+ ILogger . debug ( "Initializing tray..." );
142142 await trayManager.destroy ();
143- return ;
144- }
145-
146- // Ensure tray icon display in linux sandboxed environments
147- if (Platform .environment.containsKey ('FLATPAK_ID' ) ||
148- Platform .environment.containsKey ('SNAP' )) {
149- await trayManager.setIcon ('com.cloudchewie.cloudotp' );
150- } else if (ResponsiveUtil .isWindows ()) {
151- await trayManager.setIcon ('assets/logo-transparent.ico' );
152- } else {
153- await trayManager.setIcon ('assets/logo-transparent.png' );
154- }
143+ if (! ChewieHiveUtil .getBool (ChewieHiveUtil .showTrayKey)) {
144+ ILogger .debug ("Tray is disabled, not initializing." );
145+ await trayManager.destroy ();
146+ return ;
147+ }
148+ // Ensure tray icon display in linux sandboxed environments
149+ if (Platform .environment.containsKey ('FLATPAK_ID' ) ||
150+ Platform .environment.containsKey ('SNAP' )) {
151+ await trayManager.setIcon ('com.cloudchewie.cloudotp' );
152+ } else if (ResponsiveUtil .isWindows ()) {
153+ await trayManager.setIcon ('assets/logo-transparent.ico' );
154+ } else {
155+ await trayManager.setIcon ('assets/logo-transparent.png' );
156+ }
155157
156- bool lauchAtStartup = await LaunchAtStartup .instance.isEnabled ();
157- if (! ResponsiveUtil .isLinux ()) {
158- await trayManager.setToolTip (ResponsiveUtil .appName);
158+ bool lauchAtStartup = await LaunchAtStartup .instance.isEnabled ();
159+ if (! ResponsiveUtil .isLinux ()) {
160+ ILogger .debug (
161+ "Setting tray tooltip to app name ${ResponsiveUtil .appName }" );
162+ await trayManager.setToolTip (ResponsiveUtil .appName);
163+ }
164+ Menu menu = Menu (
165+ items: [
166+ MenuItem (
167+ key: TrayKey .checkUpdates.key,
168+ label: appProvider.latestVersion.isNotEmpty
169+ ? appLocalizations.getNewVersion (appProvider.latestVersion)
170+ : appLocalizations.checkUpdates,
171+ ),
172+ MenuItem (
173+ key: TrayKey .shortcutHelp.key,
174+ label: appLocalizations.shortcutHelp,
175+ ),
176+ MenuItem .separator (),
177+ MenuItem (
178+ key: TrayKey .displayApp.key,
179+ label: appLocalizations.displayAppTray,
180+ ),
181+ MenuItem (
182+ key: TrayKey .lockApp.key,
183+ label: appLocalizations.lockAppTray,
184+ ),
185+ ...await getTrayTokenMenuItems (),
186+ MenuItem .separator (),
187+ MenuItem (
188+ key: TrayKey .setting.key,
189+ label: appLocalizations.setting,
190+ ),
191+ MenuItem (
192+ key: TrayKey .officialWebsite.key,
193+ label: appLocalizations.officialWebsiteTray,
194+ ),
195+ MenuItem (
196+ key: TrayKey .about.key,
197+ label: appLocalizations.about,
198+ ),
199+ MenuItem (
200+ key: TrayKey .githubRepository.key,
201+ label: appLocalizations.repoTray,
202+ ),
203+ MenuItem .separator (),
204+ MenuItem .checkbox (
205+ checked: lauchAtStartup,
206+ key: TrayKey .launchAtStartup.key,
207+ label: appLocalizations.launchAtStartup,
208+ ),
209+ MenuItem .separator (),
210+ MenuItem (
211+ key: TrayKey .exitApp.key,
212+ label: appLocalizations.exitAppTray,
213+ ),
214+ ],
215+ );
216+ await trayManager.setContextMenu (menu);
217+ ILogger .debug ("Tray initialized successfully." );
218+ } catch (e, t) {
219+ ILogger .error ("Failed to initialize simple tray" , e, t);
159220 }
160- Menu menu = Menu (
161- items: [
162- MenuItem (
163- key: TrayKey .checkUpdates.key,
164- label: appProvider.latestVersion.isNotEmpty
165- ? appLocalizations.getNewVersion (appProvider.latestVersion)
166- : appLocalizations.checkUpdates,
167- ),
168- MenuItem (
169- key: TrayKey .shortcutHelp.key,
170- label: appLocalizations.shortcutHelp,
171- ),
172- MenuItem .separator (),
173- MenuItem (
174- key: TrayKey .displayApp.key,
175- label: appLocalizations.displayAppTray,
176- ),
177- MenuItem (
178- key: TrayKey .lockApp.key,
179- label: appLocalizations.lockAppTray,
180- ),
181- ...await getTrayTokenMenuItems (),
182- MenuItem .separator (),
183- MenuItem (
184- key: TrayKey .setting.key,
185- label: appLocalizations.setting,
186- ),
187- MenuItem (
188- key: TrayKey .officialWebsite.key,
189- label: appLocalizations.officialWebsiteTray,
190- ),
191- MenuItem (
192- key: TrayKey .about.key,
193- label: appLocalizations.about,
194- ),
195- MenuItem (
196- key: TrayKey .githubRepository.key,
197- label: appLocalizations.repoTray,
198- ),
199- MenuItem .separator (),
200- MenuItem .checkbox (
201- checked: lauchAtStartup,
202- key: TrayKey .launchAtStartup.key,
203- label: appLocalizations.launchAtStartup,
204- ),
205- MenuItem .separator (),
206- MenuItem (
207- key: TrayKey .exitApp.key,
208- label: appLocalizations.exitAppTray,
209- ),
210- ],
211- );
212- await trayManager.setContextMenu (menu);
213221 }
214222
215223 static Future <void > initSimpleTray () async {
216- if ( ! ResponsiveUtil . isDesktop ()) return ;
217- await trayManager. destroy () ;
218- if ( ! ChewieHiveUtil . getBool ( ChewieHiveUtil .showTrayKey)) {
224+ try {
225+ if ( ! ResponsiveUtil . isDesktop ()) return ;
226+ ILogger . debug ( "Initializing simple tray..." );
219227 await trayManager.destroy ();
220- return ;
221- }
228+ if (! ChewieHiveUtil .getBool (ChewieHiveUtil .showTrayKey)) {
229+ ILogger .debug ("Tray is disabled, not initializing." );
230+ await trayManager.destroy ();
231+ return ;
232+ }
222233
223- // Ensure tray icon display in linux sandboxed environments
224- if (Platform .environment.containsKey ('FLATPAK_ID' ) ||
225- Platform .environment.containsKey ('SNAP' )) {
226- await trayManager.setIcon ('com.cloudchewie.cloudotp' );
227- } else if (ResponsiveUtil .isWindows ()) {
228- await trayManager.setIcon ('assets/logo-transparent.ico' );
229- } else {
230- await trayManager.setIcon ('assets/logo-transparent.png' );
231- }
234+ // Ensure tray icon display in linux sandboxed environments
235+ if (Platform .environment.containsKey ('FLATPAK_ID' ) ||
236+ Platform .environment.containsKey ('SNAP' )) {
237+ await trayManager.setIcon ('com.cloudchewie.cloudotp' );
238+ } else if (ResponsiveUtil .isWindows ()) {
239+ await trayManager.setIcon ('assets/logo-transparent.ico' );
240+ } else {
241+ await trayManager.setIcon ('assets/logo-transparent.png' );
242+ }
232243
233- bool lauchAtStartup = await LaunchAtStartup .instance.isEnabled ();
234- if (! ResponsiveUtil .isLinux ()) {
235- await trayManager.setToolTip (ResponsiveUtil .appName);
244+ bool lauchAtStartup = await LaunchAtStartup .instance.isEnabled ();
245+ if (! ResponsiveUtil .isLinux ()) {
246+ await trayManager.setToolTip (ResponsiveUtil .appName);
247+ }
248+ Menu menu = Menu (
249+ items: [
250+ MenuItem (
251+ key: TrayKey .displayApp.key,
252+ label: appLocalizations.displayAppTray,
253+ ),
254+ MenuItem .separator (),
255+ MenuItem (
256+ key: TrayKey .officialWebsite.key,
257+ label: appLocalizations.officialWebsiteTray,
258+ ),
259+ MenuItem (
260+ key: TrayKey .githubRepository.key,
261+ label: appLocalizations.repoTray,
262+ ),
263+ MenuItem .separator (),
264+ MenuItem .checkbox (
265+ checked: lauchAtStartup,
266+ key: TrayKey .launchAtStartup.key,
267+ label: appLocalizations.launchAtStartup,
268+ ),
269+ MenuItem .separator (),
270+ MenuItem (
271+ key: TrayKey .exitApp.key,
272+ label: appLocalizations.exitAppTray,
273+ ),
274+ ],
275+ );
276+ await trayManager.setContextMenu (menu);
277+ ILogger .debug ("Simple tray initialized successfully." );
278+ } catch (e, t) {
279+ ILogger .error ("Failed to initialize simple tray" , e, t);
236280 }
237- Menu menu = Menu (
238- items: [
239- MenuItem (
240- key: TrayKey .displayApp.key,
241- label: appLocalizations.displayAppTray,
242- ),
243- MenuItem .separator (),
244- MenuItem (
245- key: TrayKey .officialWebsite.key,
246- label: appLocalizations.officialWebsiteTray,
247- ),
248- MenuItem (
249- key: TrayKey .githubRepository.key,
250- label: appLocalizations.repoTray,
251- ),
252- MenuItem .separator (),
253- MenuItem .checkbox (
254- checked: lauchAtStartup,
255- key: TrayKey .launchAtStartup.key,
256- label: appLocalizations.launchAtStartup,
257- ),
258- MenuItem .separator (),
259- MenuItem (
260- key: TrayKey .exitApp.key,
261- label: appLocalizations.exitAppTray,
262- ),
263- ],
264- );
265- await trayManager.setContextMenu (menu);
266281 }
267282
268283 static processTrayMenuItemClick (
269284 BuildContext context,
270285 MenuItem menuItem, [
271286 bool isSimple = false ,
272287 ]) async {
288+ ILogger .debug ("Processing tray menu item click: ${menuItem .key }" );
273289 if (menuItem.key == TrayKey .displayApp.key) {
274290 ChewieUtils .displayApp ();
275291 } else if (menuItem.key == TrayKey .shortcutHelp.key) {
0 commit comments