| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  | var SysTrayX = { | 
					
						
							| 
									
										
										
										
											2020-05-13 23:19:17 +02:00
										 |  |  |   accounts: [], | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-21 21:38:44 +02:00
										 |  |  |   startupState: undefined, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:37:15 +02:00
										 |  |  |   hideDefaultIcon: false, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 16:51:13 +02:00
										 |  |  |   platformInfo: undefined, | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-27 23:31:41 +02:00
										 |  |  |   browserInfo: undefined, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   version: "0", | 
					
						
							| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-01-04 23:47:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | SysTrayX.Messaging = { | 
					
						
							| 
									
										
										
										
											2020-05-03 23:39:02 +02:00
										 |  |  |   accounts: [], | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |   countType: 0, | 
					
						
							| 
									
										
										
										
											2020-08-02 21:32:09 +02:00
										 |  |  |   closeType: 1, | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |   filters: undefined, | 
					
						
							| 
									
										
										
										
											2020-01-11 22:08:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   init: function () { | 
					
						
							| 
									
										
										
										
											2020-04-03 17:45:20 +02:00
										 |  |  |     // Lookout for storage changes
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     browser.storage.onChanged.addListener(SysTrayX.Messaging.storageChanged); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-27 23:31:41 +02:00
										 |  |  |     //  Send the platform info to app
 | 
					
						
							|  |  |  |     SysTrayX.Messaging.sendPlatformInfo(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //  Send the browser info to app
 | 
					
						
							|  |  |  |     SysTrayX.Messaging.sendBrowserInfo(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-17 22:23:39 +01:00
										 |  |  |     //  Send the window title to app
 | 
					
						
							|  |  |  |     SysTrayX.Messaging.sendTitle(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |     //  Send version to app
 | 
					
						
							|  |  |  |     SysTrayX.Messaging.sendVersion(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:37:15 +02:00
										 |  |  |     //  Send hide default icon preference
 | 
					
						
							|  |  |  |     SysTrayX.Messaging.sendHideDefaultIcon(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     //  Send preferences to app
 | 
					
						
							|  |  |  |     SysTrayX.Messaging.sendPreferences(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |     /* | 
					
						
							| 
									
										
										
										
											2020-05-05 16:44:37 +02:00
										 |  |  |     //  New mail listener (TB76+)
 | 
					
						
							|  |  |  |     if (SysTrayX.browserInfo.majorVersion > 75) { | 
					
						
							|  |  |  |       //
 | 
					
						
							|  |  |  |       //  Mixed results, forgets accounts?, double events?
 | 
					
						
							|  |  |  |       //
 | 
					
						
							|  |  |  |       browser.messages.onNewMailReceived.addListener( | 
					
						
							|  |  |  |         SysTrayX.Messaging.newMail | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |     */ | 
					
						
							| 
									
										
										
										
											2020-05-05 16:44:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-09 18:04:04 +02:00
										 |  |  |     browser.folderChange.onUnreadMailChange.addListener(function (unread) { | 
					
						
							|  |  |  |       SysTrayX.Messaging.unreadCb(unread); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-21 21:02:07 +02:00
										 |  |  |     browser.folderChange.onFolderChange.addListener(function () { | 
					
						
							|  |  |  |       SysTrayX.Messaging.updateFilters(); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |     //  Set the count type in the folderChange listener
 | 
					
						
							|  |  |  |     browser.folderChange.setCountType(Number(SysTrayX.Messaging.countType)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //  Set the filters in the folderChange listener
 | 
					
						
							| 
									
										
										
										
											2020-05-12 21:38:03 +02:00
										 |  |  |     browser.folderChange.setFilters(SysTrayX.Messaging.filters); | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 23:05:20 +01:00
										 |  |  |     //  Try to catch the window state
 | 
					
						
							| 
									
										
										
										
											2020-02-24 23:00:45 +01:00
										 |  |  |     browser.windows.onFocusChanged.addListener(SysTrayX.Window.focusChanged); | 
					
						
							| 
									
										
										
										
											2020-01-04 23:47:26 +01:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-01-11 22:08:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 20:55:27 +02:00
										 |  |  |   onCloseButton: function () { | 
					
						
							| 
									
										
										
										
											2020-06-21 11:12:49 +02:00
										 |  |  |     SysTrayX.Link.postSysTrayXMessage({ window: "minimized_all" }); | 
					
						
							|  |  |  |     /* | 
					
						
							| 
									
										
										
										
											2020-05-10 20:55:27 +02:00
										 |  |  |     browser.windows.update(browser.windows.WINDOW_ID_CURRENT, { | 
					
						
							|  |  |  |       state: "minimized", | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-06-21 11:12:49 +02:00
										 |  |  |     */ | 
					
						
							| 
									
										
										
										
											2020-05-05 16:44:37 +02:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |   //
 | 
					
						
							|  |  |  |   //  Handle a storage change
 | 
					
						
							|  |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   storageChanged: function (changes, area) { | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     //  Get the new preferences
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |     if ("filters" in changes && changes["filters"].newValue) { | 
					
						
							|  |  |  |       SysTrayX.Messaging.filters = changes["filters"].newValue; | 
					
						
							| 
									
										
										
										
											2020-05-12 21:38:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       browser.folderChange.setFilters(SysTrayX.Messaging.filters); | 
					
						
							| 
									
										
										
										
											2020-04-03 17:45:20 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-09 20:22:19 +02:00
										 |  |  |     if ("closeType" in changes && changes["closeType"].newValue) { | 
					
						
							|  |  |  |       SysTrayX.Messaging.closeType = changes["closeType"].newValue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       browser.windowEvent.setCloseType(Number(SysTrayX.Messaging.closeType)); | 
					
						
							| 
									
										
										
										
											2020-05-10 20:55:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-09 20:22:19 +02:00
										 |  |  |       if (SysTrayX.Messaging.closeType !== "0") { | 
					
						
							| 
									
										
										
										
											2020-05-10 20:55:27 +02:00
										 |  |  |         browser.windowEvent.onCloseButtonClick.addListener( | 
					
						
							|  |  |  |           SysTrayX.Messaging.onCloseButton | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         browser.windowEvent.onCloseButtonClick.removeListener( | 
					
						
							|  |  |  |           SysTrayX.Messaging.onCloseButton | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |     if ("countType" in changes && changes["countType"].newValue) { | 
					
						
							|  |  |  |       SysTrayX.Messaging.countType = changes["countType"].newValue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       browser.folderChange.setCountType(Number(SysTrayX.Messaging.countType)); | 
					
						
							| 
									
										
										
										
											2020-04-03 17:45:20 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     if ("addonprefchanged" in changes && changes["addonprefchanged"].newValue) { | 
					
						
							|  |  |  |       //
 | 
					
						
							|  |  |  |       //  Send new preferences to the app
 | 
					
						
							|  |  |  |       //
 | 
					
						
							|  |  |  |       SysTrayX.Messaging.sendPreferences(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       //  Reset flag
 | 
					
						
							|  |  |  |       browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |         addonprefchanged: false, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-13 23:22:11 +01:00
										 |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |   //  Callback for unReadMessages
 | 
					
						
							| 
									
										
										
										
											2020-01-13 23:22:11 +01:00
										 |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   unreadCb: function (count) { | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     SysTrayX.Link.postSysTrayXMessage({ unreadMail: count }); | 
					
						
							| 
									
										
										
										
											2020-01-11 22:08:11 +01:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-21 21:02:07 +02:00
										 |  |  |   //
 | 
					
						
							|  |  |  |   //  Callback for folder changes
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   updateFilters: function (count) { | 
					
						
							|  |  |  |     console.debug("Folder changed"); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-27 23:31:41 +02:00
										 |  |  |   sendBrowserInfo: function () { | 
					
						
							|  |  |  |     const info = SysTrayX.browserInfo; | 
					
						
							| 
									
										
										
										
											2020-05-02 14:49:05 +02:00
										 |  |  |     SysTrayX.Link.postSysTrayXMessage({ browserInfo: info }); | 
					
						
							| 
									
										
										
										
											2020-04-27 23:31:41 +02:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   sendPlatformInfo: function () { | 
					
						
							|  |  |  |     const info = SysTrayX.platformInfo; | 
					
						
							| 
									
										
										
										
											2020-05-02 14:49:05 +02:00
										 |  |  |     SysTrayX.Link.postSysTrayXMessage({ platformInfo: info }); | 
					
						
							| 
									
										
										
										
											2020-04-27 23:31:41 +02:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   sendTitle: function () { | 
					
						
							| 
									
										
										
										
											2020-02-17 22:23:39 +01:00
										 |  |  |     const title = "-" + SysTrayX.Window.startWindow.title.split("-").pop(); | 
					
						
							|  |  |  |     SysTrayX.Link.postSysTrayXMessage({ title: title }); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   sendVersion: function () { | 
					
						
							|  |  |  |     SysTrayX.Link.postSysTrayXMessage({ version: SysTrayX.version }); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:37:15 +02:00
										 |  |  |   sendHideDefaultIcon: function () { | 
					
						
							|  |  |  |     SysTrayX.Link.postSysTrayXMessage({ | 
					
						
							|  |  |  |       hideDefaultIcon: SysTrayX.hideDefaultIcon, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   sendPreferences: function () { | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const getter = browser.storage.sync.get([ | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |       "debug", | 
					
						
							| 
									
										
										
										
											2020-04-07 17:19:02 +02:00
										 |  |  |       "minimizeType", | 
					
						
							| 
									
										
										
										
											2020-06-28 23:23:12 +02:00
										 |  |  |       "closeType", | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |       "startMinimized", | 
					
						
							| 
									
										
										
										
											2020-05-22 22:54:10 +02:00
										 |  |  |       "defaultIconType", | 
					
						
							|  |  |  |       "defaultIconMime", | 
					
						
							|  |  |  |       "defaultIcon", | 
					
						
							| 
									
										
										
										
											2020-06-03 22:46:46 +02:00
										 |  |  |       "hideDefaultIcon", | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |       "iconType", | 
					
						
							|  |  |  |       "iconMime", | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |       "icon", | 
					
						
							| 
									
										
										
										
											2020-04-05 14:39:19 +02:00
										 |  |  |       "showNumber", | 
					
						
							|  |  |  |       "numberColor", | 
					
						
							| 
									
										
										
										
											2020-05-26 22:39:25 +02:00
										 |  |  |       "numberSize", | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |       "countType", | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     ]); | 
					
						
							|  |  |  |     getter.then(this.sendPreferencesStorage, this.onSendPreferecesStorageError); | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   sendPreferencesStorage: function (result) { | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const debug = result.debug || "false"; | 
					
						
							| 
									
										
										
										
											2020-04-11 20:13:11 +02:00
										 |  |  |     const minimizeType = result.minimizeType || "1"; | 
					
						
							| 
									
										
										
										
											2020-08-02 16:59:53 +02:00
										 |  |  |     const closeType = result.closeType || "1"; | 
					
						
							| 
									
										
										
										
											2020-03-01 23:43:01 +01:00
										 |  |  |     const startMinimized = result.startMinimized || "false"; | 
					
						
							| 
									
										
										
										
											2020-05-22 22:54:10 +02:00
										 |  |  |     const defaultIconType = result.defaultIconType || "0"; | 
					
						
							|  |  |  |     const defaultIconMime = result.defaultIconMime || "image/png"; | 
					
						
							|  |  |  |     const defaultIcon = result.defaultIcon || []; | 
					
						
							| 
									
										
										
										
											2020-06-04 17:58:27 +02:00
										 |  |  |     const hideDefaultIcon = result.hideDefaultIcon || "false"; | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const iconType = result.iconType || "0"; | 
					
						
							|  |  |  |     const iconMime = result.iconMime || "image/png"; | 
					
						
							|  |  |  |     const icon = result.icon || []; | 
					
						
							| 
									
										
										
										
											2020-04-05 14:39:19 +02:00
										 |  |  |     const showNumber = result.showNumber || "true"; | 
					
						
							|  |  |  |     const numberColor = result.numberColor || "#000000"; | 
					
						
							| 
									
										
										
										
											2020-06-13 21:31:28 +02:00
										 |  |  |     const numberSize = result.numberSize || "10"; | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |     const countType = result.countType || "0"; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     //  Send it to the app
 | 
					
						
							|  |  |  |     SysTrayX.Link.postSysTrayXMessage({ | 
					
						
							|  |  |  |       preferences: { | 
					
						
							|  |  |  |         debug: debug, | 
					
						
							| 
									
										
										
										
											2020-04-07 17:19:02 +02:00
										 |  |  |         minimizeType: minimizeType, | 
					
						
							| 
									
										
										
										
											2020-06-28 23:23:12 +02:00
										 |  |  |         closeType: closeType, | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |         startMinimized: startMinimized, | 
					
						
							| 
									
										
										
										
											2020-05-22 22:54:10 +02:00
										 |  |  |         defaultIconType: defaultIconType, | 
					
						
							|  |  |  |         defaultIconMime: defaultIconMime, | 
					
						
							|  |  |  |         defaultIcon: defaultIcon, | 
					
						
							| 
									
										
										
										
											2020-06-03 22:46:46 +02:00
										 |  |  |         hideDefaultIcon: hideDefaultIcon, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |         iconType: iconType, | 
					
						
							|  |  |  |         iconMime: iconMime, | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |         icon: icon, | 
					
						
							| 
									
										
										
										
											2020-04-05 14:39:19 +02:00
										 |  |  |         showNumber: showNumber, | 
					
						
							|  |  |  |         numberColor: numberColor, | 
					
						
							| 
									
										
										
										
											2020-05-26 22:39:25 +02:00
										 |  |  |         numberSize: numberSize, | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |         countType: countType, | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-04-21 21:38:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (SysTrayX.startupState) { | 
					
						
							|  |  |  |       //  Send startup state after the prefs
 | 
					
						
							|  |  |  |       //  so the hide is handled conform the prefs
 | 
					
						
							| 
									
										
										
										
											2020-06-28 13:03:53 +02:00
										 |  |  |       if (SysTrayX.startupState === "minimized") { | 
					
						
							|  |  |  |         SysTrayX.Link.postSysTrayXMessage({ window: "minimized_all" }); | 
					
						
							|  |  |  |         //SysTrayX.Link.postSysTrayXMessage({ window: SysTrayX.startupState });
 | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-04-21 21:38:44 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       SysTrayX.startupState = undefined; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-11 22:08:11 +01:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   onSendIconStorageError: function (error) { | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     console.log(`GetIcon Error: ${error}`); | 
					
						
							| 
									
										
										
										
											2020-01-11 22:08:11 +01:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   onGetAccountsStorageError: function (error) { | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     console.log(`GetAccounts Error: ${error}`); | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-01-11 22:08:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-13 23:22:11 +01:00
										 |  |  | //
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | //  Link object. Handles the native messaging to the system tray app
 | 
					
						
							| 
									
										
										
										
											2020-01-13 23:22:11 +01:00
										 |  |  | //
 | 
					
						
							|  |  |  | SysTrayX.Link = { | 
					
						
							|  |  |  |   portSysTrayX: undefined, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   init: function () { | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     //  Connect to the app
 | 
					
						
							| 
									
										
										
										
											2020-01-13 23:22:11 +01:00
										 |  |  |     this.portSysTrayX = browser.runtime.connectNative("SysTray_X"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //  Listen for messages from the app.
 | 
					
						
							|  |  |  |     this.portSysTrayX.onMessage.addListener( | 
					
						
							|  |  |  |       SysTrayX.Link.receiveSysTrayXMessage | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   postSysTrayXMessage: function (object) { | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     //  Send object (will be stringified by postMessage)
 | 
					
						
							|  |  |  |     SysTrayX.Link.portSysTrayX.postMessage(object); | 
					
						
							| 
									
										
										
										
											2020-01-13 23:22:11 +01:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   receiveSysTrayXMessage: function (response) { | 
					
						
							| 
									
										
										
										
											2020-02-03 23:05:20 +01:00
										 |  |  |     if (response["window"]) { | 
					
						
							|  |  |  |       if (response["window"] === "minimized") { | 
					
						
							|  |  |  |         browser.windows.update(SysTrayX.Window.startWindow.id, { | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |           state: "minimized", | 
					
						
							| 
									
										
										
										
											2020-02-03 23:05:20 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (response["window"] === "normal") { | 
					
						
							|  |  |  |         browser.windows.update(SysTrayX.Window.startWindow.id, { | 
					
						
							|  |  |  |           state: "normal", | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |           focused: true, | 
					
						
							| 
									
										
										
										
											2020-02-03 23:05:20 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |     if (response["shutdown"]) { | 
					
						
							| 
									
										
										
										
											2020-05-10 20:55:27 +02:00
										 |  |  |       browser.windowEvent.onCloseButtonClick.removeListener( | 
					
						
							|  |  |  |         SysTrayX.Messaging.onCloseButton | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       SysTrayX.Link.postSysTrayXMessage({ shutdown: "true" }); | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-07 16:19:39 +02:00
										 |  |  |     const kdeIntegration = response["kdeIntegration"]; | 
					
						
							|  |  |  |     if (kdeIntegration) { | 
					
						
							|  |  |  |       browser.storage.sync.set({ | 
					
						
							|  |  |  |         kdeIntegration: kdeIntegration, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     if (response["preferences"]) { | 
					
						
							|  |  |  |       //  Store the preferences from the app
 | 
					
						
							| 
									
										
										
										
											2020-05-22 22:54:10 +02:00
										 |  |  |       const defaultIconMime = response["preferences"].defaultIconMime; | 
					
						
							|  |  |  |       if (defaultIconMime) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							|  |  |  |           defaultIconMime: defaultIconMime, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const defaultIcon = response["preferences"].defaultIcon; | 
					
						
							|  |  |  |       if (defaultIcon) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							|  |  |  |           defaultIcon: defaultIcon, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const defaultIconType = response["preferences"].defaultIconType; | 
					
						
							|  |  |  |       if (defaultIconType) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							|  |  |  |           defaultIconType: defaultIconType, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-03 22:46:46 +02:00
										 |  |  |       const hideDefaultIcon = response["preferences"].hideDefaultIcon; | 
					
						
							|  |  |  |       if (hideDefaultIcon) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							|  |  |  |           hideDefaultIcon: hideDefaultIcon, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |       const iconMime = response["preferences"].iconMime; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |       if (iconMime) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |           iconMime: iconMime, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |       const icon = response["preferences"].icon; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |       if (icon) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |           icon: icon, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |       const iconType = response["preferences"].iconType; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |       if (iconType) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |           iconType: iconType, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-05 14:39:19 +02:00
										 |  |  |       const showNumber = response["preferences"].showNumber; | 
					
						
							|  |  |  |       if (showNumber) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							|  |  |  |           showNumber: showNumber, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const numberColor = response["preferences"].numberColor; | 
					
						
							|  |  |  |       if (numberColor) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							|  |  |  |           numberColor: numberColor, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-26 22:39:25 +02:00
										 |  |  |       const numberSize = response["preferences"].numberSize; | 
					
						
							|  |  |  |       if (numberSize) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							|  |  |  |           numberSize: numberSize, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |       const countType = response["preferences"].countType; | 
					
						
							|  |  |  |       if (countType) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							|  |  |  |           countType: countType, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-07 17:19:02 +02:00
										 |  |  |       const minimizeType = response["preferences"].minimizeType; | 
					
						
							|  |  |  |       if (minimizeType) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							|  |  |  |           minimizeType: minimizeType, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-28 23:23:12 +02:00
										 |  |  |       const closeType = response["preferences"].closeType; | 
					
						
							|  |  |  |       if (closeType) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							|  |  |  |           closeType: closeType, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |       const startMinimized = response["preferences"].startMinimized; | 
					
						
							|  |  |  |       if (startMinimized) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |           startMinimized: startMinimized, | 
					
						
							| 
									
										
										
										
											2020-02-18 00:24:31 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |       const debug = response["preferences"].debug; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |       if (debug) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |           debug: debug, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-01-13 23:22:11 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 23:05:20 +01:00
										 |  |  | SysTrayX.Window = { | 
					
						
							|  |  |  |   startWindow: undefined, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   focusChanged: function (windowId) { | 
					
						
							|  |  |  |     browser.windows.getCurrent().then((win) => { | 
					
						
							| 
									
										
										
										
											2020-02-03 23:05:20 +01:00
										 |  |  |       SysTrayX.Link.postSysTrayXMessage({ window: win.state }); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-02-03 23:05:20 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-24 22:20:30 +01:00
										 |  |  | async function start() { | 
					
						
							| 
									
										
										
										
											2020-02-29 20:36:08 +01:00
										 |  |  |   //  Get the prefered start state
 | 
					
						
							|  |  |  |   const state = await getStartupState(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (state == "minimized") { | 
					
						
							|  |  |  |     browser.windows.update(browser.windows.WINDOW_ID_CURRENT, { | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |       state: "minimized", | 
					
						
							| 
									
										
										
										
											2020-02-29 20:36:08 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-21 21:38:44 +02:00
										 |  |  |   SysTrayX.startupState = state; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-02 21:32:09 +02:00
										 |  |  |   // Get the close type
 | 
					
						
							|  |  |  |   SysTrayX.Messaging.closeType = await getCloseType(); | 
					
						
							|  |  |  |   browser.windowEvent.setCloseType(Number(SysTrayX.Messaging.closeType)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 20:55:27 +02:00
										 |  |  |   //  Intercept close button?
 | 
					
						
							| 
									
										
										
										
											2020-08-09 20:22:19 +02:00
										 |  |  |   if (SysTrayX.Messaging.closeType !== "0") { | 
					
						
							| 
									
										
										
										
											2020-05-10 20:55:27 +02:00
										 |  |  |     browser.windowEvent.onCloseButtonClick.addListener( | 
					
						
							|  |  |  |       SysTrayX.Messaging.onCloseButton | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 19:37:15 +02:00
										 |  |  |   //  Hide the default icon
 | 
					
						
							|  |  |  |   const hideDefaultIcon = await getHideDefaultIcon(); | 
					
						
							|  |  |  |   SysTrayX.hideDefaultIcon = hideDefaultIcon; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-22 21:26:42 +01:00
										 |  |  |   //  Set platform
 | 
					
						
							|  |  |  |   SysTrayX.platformInfo = await browser.runtime | 
					
						
							|  |  |  |     .getPlatformInfo() | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |     .then((info) => info); | 
					
						
							| 
									
										
										
										
											2020-04-21 21:38:44 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-22 21:26:42 +01:00
										 |  |  |   console.log("OS: " + SysTrayX.platformInfo.os); | 
					
						
							|  |  |  |   console.log("Arch: " + SysTrayX.platformInfo.arch); | 
					
						
							|  |  |  |   console.log("Nack-Arch: " + SysTrayX.platformInfo.nacl_arch); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-11 23:31:22 +02:00
										 |  |  |   //  Store platform info
 | 
					
						
							|  |  |  |   browser.storage.sync.set({ | 
					
						
							|  |  |  |     platformInfo: SysTrayX.platformInfo, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-27 23:31:41 +02:00
										 |  |  |   //  Set browser
 | 
					
						
							|  |  |  |   SysTrayX.browserInfo = await browser.runtime | 
					
						
							|  |  |  |     .getBrowserInfo() | 
					
						
							|  |  |  |     .then((info) => info); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-05 16:44:37 +02:00
										 |  |  |   const version = SysTrayX.browserInfo.version.split("."); | 
					
						
							|  |  |  |   SysTrayX.browserInfo.majorVersion = version[0]; | 
					
						
							|  |  |  |   SysTrayX.browserInfo.minorVersion = version[1]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-27 23:31:41 +02:00
										 |  |  |   console.log("Browser: " + SysTrayX.browserInfo.name); | 
					
						
							|  |  |  |   console.log("Vendor: " + SysTrayX.browserInfo.vendor); | 
					
						
							|  |  |  |   console.log("Version: " + SysTrayX.browserInfo.version); | 
					
						
							|  |  |  |   console.log("Build: " + SysTrayX.browserInfo.buildID); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   //  Store browser info
 | 
					
						
							|  |  |  |   browser.storage.sync.set({ | 
					
						
							|  |  |  |     browserInfo: SysTrayX.browserInfo, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-07 16:19:39 +02:00
										 |  |  |   //  Reset KDE integration
 | 
					
						
							|  |  |  |   browser.storage.sync.set({ | 
					
						
							|  |  |  |     kdeIntegration: true, | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 16:51:13 +02:00
										 |  |  |   //  Get addon version
 | 
					
						
							|  |  |  |   SysTrayX.version = browser.runtime.getManifest().version; | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   console.log("Addon version: " + SysTrayX.version); | 
					
						
							| 
									
										
										
										
											2020-04-04 16:51:13 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |   //  Init defaults before everything
 | 
					
						
							| 
									
										
										
										
											2020-01-24 22:20:30 +01:00
										 |  |  |   await getDefaultIcon(); | 
					
						
							| 
									
										
										
										
											2020-05-22 22:54:10 +02:00
										 |  |  |   await getIcon(); | 
					
						
							| 
									
										
										
										
											2020-01-11 22:08:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 23:05:20 +01:00
										 |  |  |   SysTrayX.Window.startWindow = await browser.windows | 
					
						
							|  |  |  |     .getCurrent() | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |     .then((currentWindow) => currentWindow); | 
					
						
							| 
									
										
										
										
											2020-02-03 23:05:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 23:39:02 +02:00
										 |  |  |   //  Get all accounts
 | 
					
						
							|  |  |  |   SysTrayX.Messaging.accounts = await browser.accounts.list(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-13 21:24:29 +02:00
										 |  |  |   // Get the filters (needs the accounts)
 | 
					
						
							| 
									
										
										
										
											2020-05-12 21:38:03 +02:00
										 |  |  |   SysTrayX.Messaging.filters = await getFilters(); | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Get the count type
 | 
					
						
							|  |  |  |   SysTrayX.Messaging.countType = await getCountType(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-24 22:20:30 +01:00
										 |  |  |   //  Setup the link first
 | 
					
						
							|  |  |  |   SysTrayX.Link.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   //  Main start
 | 
					
						
							|  |  |  |   SysTrayX.Messaging.init(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | console.log("Starting SysTray-X"); | 
					
						
							| 
									
										
										
										
											2020-01-04 23:47:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-24 22:20:30 +01:00
										 |  |  | //  Start the add-on
 | 
					
						
							|  |  |  | start(); |