| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  | var SysTrayX = { | 
					
						
							| 
									
										
										
										
											2020-03-22 21:26:42 +01:00
										 |  |  |   debugAccounts: false, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 17:45:20 +02:00
										 |  |  |   pollTiming: { | 
					
						
							| 
									
										
										
										
											2020-04-03 21:32:03 +02:00
										 |  |  |     pollStartupDelay: "30", | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |     pollInterval: "30", | 
					
						
							| 
									
										
										
										
											2020-04-03 17:45:20 +02:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 16:51:13 +02:00
										 |  |  |   platformInfo: 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-01-12 15:09:47 +01:00
										 |  |  |   unreadFiltersTest: [ | 
					
						
							|  |  |  |     { unread: true }, | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |     { unread: true, folder: { accountId: "account1", path: "/INBOX" } }, | 
					
						
							| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  |   ], | 
					
						
							| 
									
										
										
										
											2020-01-11 22:08:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   init: function () { | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     //  Get the accounts from the storage
 | 
					
						
							|  |  |  |     SysTrayX.Messaging.getAccounts(); | 
					
						
							| 
									
										
										
										
											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-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-01-22 23:14:46 +01:00
										 |  |  |     //  Send preferences to app
 | 
					
						
							|  |  |  |     SysTrayX.Messaging.sendPreferences(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  |     //    this.unReadMessages(this.unreadFiltersTest).then(this.unreadCb);
 | 
					
						
							| 
									
										
										
										
											2020-04-03 17:45:20 +02:00
										 |  |  |     //    window.setInterval(SysTrayX.Messaging.pollAccounts, 1000);
 | 
					
						
							|  |  |  |     window.setTimeout( | 
					
						
							|  |  |  |       SysTrayX.Messaging.pollAccounts, | 
					
						
							|  |  |  |       SysTrayX.pollTiming.pollStartupDelay * 1000 | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-01-24 23:03:18 +01: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-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
 | 
					
						
							|  |  |  |     SysTrayX.Messaging.getAccounts(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-03 17:45:20 +02:00
										 |  |  |     if ("pollStartupDelay" in changes && changes["pollStartupDelay"].newValue) { | 
					
						
							|  |  |  |       SysTrayX.pollTiming = { | 
					
						
							|  |  |  |         ...SysTrayX.pollTiming, | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |         pollStartupDelay: changes["pollStartupDelay"].newValue, | 
					
						
							| 
									
										
										
										
											2020-04-03 17:45:20 +02:00
										 |  |  |       }; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ("pollInterval" in changes && changes["pollInterval"].newValue) { | 
					
						
							|  |  |  |       SysTrayX.pollTiming = { | 
					
						
							|  |  |  |         ...SysTrayX.pollTiming, | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |         pollInterval: changes["pollInterval"].newValue, | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   //
 | 
					
						
							|  |  |  |   //  Poll the accounts
 | 
					
						
							|  |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   pollAccounts: function () { | 
					
						
							| 
									
										
										
										
											2020-01-13 23:22:11 +01:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     //  Get the unread nessages of the selected accounts
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const filtersDiv = document.getElementById("filters"); | 
					
						
							|  |  |  |     const filtersAttr = filtersDiv.getAttribute("data-filters"); | 
					
						
							| 
									
										
										
										
											2020-01-13 23:22:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 22:16:19 +01:00
										 |  |  |     if (filtersAttr !== "undefined") { | 
					
						
							|  |  |  |       const filters = JSON.parse(filtersAttr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (filters.length > 0) { | 
					
						
							|  |  |  |         SysTrayX.Messaging.unReadMessages(filters).then( | 
					
						
							|  |  |  |           SysTrayX.Messaging.unreadCb | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         SysTrayX.Link.postSysTrayXMessage({ unreadMail: 0 }); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     } else { | 
					
						
							|  |  |  |       SysTrayX.Messaging.unReadMessages([{ unread: true }]).then( | 
					
						
							|  |  |  |         SysTrayX.Messaging.unreadCb | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-04-03 17:45:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Next round...
 | 
					
						
							|  |  |  |     window.setTimeout( | 
					
						
							|  |  |  |       SysTrayX.Messaging.pollAccounts, | 
					
						
							|  |  |  |       SysTrayX.pollTiming.pollInterval * 1000 | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-01-13 23:22:11 +01:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |   //  Use the messages API to get the unread messages (Promise)
 | 
					
						
							|  |  |  |   //  Be aware that the data is only avaiable inside the callback
 | 
					
						
							| 
									
										
										
										
											2020-01-13 23:22:11 +01:00
										 |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   unReadMessages: async function (filters) { | 
					
						
							| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  |     let unreadMessages = 0; | 
					
						
							|  |  |  |     for (let i = 0; i < filters.length; ++i) { | 
					
						
							|  |  |  |       let page = await browser.messages.query(filters[i]); | 
					
						
							|  |  |  |       let unread = page.messages.length; | 
					
						
							| 
									
										
										
										
											2020-01-11 22:08:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  |       while (page.id) { | 
					
						
							|  |  |  |         page = await browser.messages.continueList(page.id); | 
					
						
							| 
									
										
										
										
											2020-01-11 22:08:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  |         unread = unread + page.messages.length; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-01-04 23:47:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  |       unreadMessages = unreadMessages + unread; | 
					
						
							| 
									
										
										
										
											2020-01-04 23:47:26 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  |     return unreadMessages; | 
					
						
							| 
									
										
										
										
											2020-01-04 23:47:26 +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
										 |  |  |   //  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-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 }); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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-02 22:27:34 +02:00
										 |  |  |       "pollStartupDelay", | 
					
						
							|  |  |  |       "pollInterval", | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |       "hideOnMinimize", | 
					
						
							|  |  |  |       "startMinimized", | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |       "iconType", | 
					
						
							|  |  |  |       "iconMime", | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |       "icon", | 
					
						
							| 
									
										
										
										
											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-03 21:32:03 +02:00
										 |  |  |     const pollStartupDelay = result.pollStartupDelay || "30"; | 
					
						
							|  |  |  |     const pollInterval = result.pollInterval || "30"; | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |     const hideOnMinimize = result.hideOnMinimize || "true"; | 
					
						
							| 
									
										
										
										
											2020-03-01 23:43:01 +01:00
										 |  |  |     const startMinimized = result.startMinimized || "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-01-22 23:14:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     //  Send it to the app
 | 
					
						
							|  |  |  |     SysTrayX.Link.postSysTrayXMessage({ | 
					
						
							|  |  |  |       preferences: { | 
					
						
							|  |  |  |         debug: debug, | 
					
						
							| 
									
										
										
										
											2020-04-02 22:27:34 +02:00
										 |  |  |         pollStartupDelay: pollStartupDelay, | 
					
						
							|  |  |  |         pollInterval: pollInterval, | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |         hideOnMinimize: hideOnMinimize, | 
					
						
							|  |  |  |         startMinimized: startMinimized, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |         iconType: iconType, | 
					
						
							|  |  |  |         iconMime: iconMime, | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |         icon: icon, | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											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-01-22 23:14:46 +01:00
										 |  |  |   //
 | 
					
						
							|  |  |  |   //  Get the accounts from the storage
 | 
					
						
							|  |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   getAccounts: function () { | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const getter = browser.storage.sync.get(["accounts", "filters"]); | 
					
						
							| 
									
										
										
										
											2020-01-13 22:50:50 +01:00
										 |  |  |     getter.then(this.getAccountsStorage, this.onGetAccountsStorageError); | 
					
						
							| 
									
										
										
										
											2020-01-04 23:47:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  |     if (SysTrayX.debugAccounts) { | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |       const accountsDiv = document.getElementById("accounts"); | 
					
						
							| 
									
										
										
										
											2020-01-04 23:47:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |       const accountsAttr = accountsDiv.getAttribute("data-accounts"); | 
					
						
							| 
									
										
										
										
											2020-01-24 22:20:30 +01:00
										 |  |  |       console.debug(`Accounts attr: ${accountsAttr}`); | 
					
						
							| 
									
										
										
										
											2020-01-11 22:08:11 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |       const accounts = JSON.parse(accountsAttr); | 
					
						
							| 
									
										
										
										
											2020-01-24 22:20:30 +01:00
										 |  |  |       console.debug(`Accounts poll: ${accounts.length}`); | 
					
						
							| 
									
										
										
										
											2020-01-12 15:09:47 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   //  Get the accounts from the storage and
 | 
					
						
							|  |  |  |   //  make them available in the background HTML
 | 
					
						
							|  |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |   getAccountsStorage: function (result) { | 
					
						
							| 
									
										
										
										
											2020-03-02 22:16:19 +01:00
										 |  |  |     const accounts = result.accounts || undefined; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     //  Store them in the background HTML
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const accountsDiv = document.getElementById("accounts"); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     accountsDiv.setAttribute("data-accounts", JSON.stringify(accounts)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 22:16:19 +01:00
										 |  |  |     const filters = result.filters || undefined; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     //  Store them in the background HTML
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const filtersDiv = document.getElementById("filters"); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     filtersDiv.setAttribute("data-filters", JSON.stringify(filters)); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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"]) { | 
					
						
							|  |  |  |       console.log("Shutdown received: " + response["shutdown"]); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     if (response["preferences"]) { | 
					
						
							|  |  |  |       //  Store the preferences from the app
 | 
					
						
							| 
									
										
										
										
											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-02-29 19:04:43 +01:00
										 |  |  |       const hideOnMinimize = response["preferences"].hideOnMinimize; | 
					
						
							|  |  |  |       if (hideOnMinimize) { | 
					
						
							| 
									
										
										
										
											2020-02-18 00:24:31 +01:00
										 |  |  |         browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |           hideOnMinimize: hideOnMinimize, | 
					
						
							| 
									
										
										
										
											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-04-02 22:27:34 +02:00
										 |  |  |       const pollStartupDelay = response["preferences"].pollStartupDelay; | 
					
						
							|  |  |  |       if (pollStartupDelay) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |           pollStartupDelay: pollStartupDelay, | 
					
						
							| 
									
										
										
										
											2020-04-02 22:27:34 +02:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const pollInterval = response["preferences"].pollInterval; | 
					
						
							|  |  |  |       if (pollInterval) { | 
					
						
							|  |  |  |         browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-04-04 19:34:19 +02:00
										 |  |  |           pollInterval: pollInterval, | 
					
						
							| 
									
										
										
										
											2020-04-02 22:27:34 +02: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-03 17:45:20 +02:00
										 |  |  |   // Get the poll timing
 | 
					
						
							|  |  |  |   SysTrayX.pollTiming = await getPollTiming(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-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-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-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-01-24 22:20:30 +01:00
										 |  |  |   //  Setup the link first
 | 
					
						
							|  |  |  |   SysTrayX.Link.init(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-29 20:36:08 +01:00
										 |  |  |   //  Send current state
 | 
					
						
							|  |  |  |   SysTrayX.Link.postSysTrayXMessage({ window: state }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-24 22:20:30 +01:00
										 |  |  |   //  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(); |