| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  | var SysTrayX = { | 
					
						
							| 
									
										
										
										
											2020-04-11 20:13:11 +02:00
										 |  |  |   platformInfo: undefined, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   version: 0, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | SysTrayX.SaveOptions = { | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   start: function (e) { | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     e.preventDefault(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // Save accounts and filters
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const treeBase = document.getElementById("accountsTree"); | 
					
						
							| 
									
										
										
										
											2020-05-03 23:39:02 +02:00
										 |  |  |     const accounts = treeBase.querySelectorAll( | 
					
						
							|  |  |  |       'input[type="checkbox"][name*="account"]' | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 23:39:02 +02:00
										 |  |  |     let checkedFolders = []; | 
					
						
							|  |  |  |     accounts.forEach((account) => { | 
					
						
							|  |  |  |       if (account.checked || account.indeterminate) { | 
					
						
							|  |  |  |         //  Find all selected folders
 | 
					
						
							|  |  |  |         const folders = Array.from( | 
					
						
							|  |  |  |           account.parentNode.querySelectorAll( | 
					
						
							|  |  |  |             'input[type="checkbox"]:not([name^="account"]):not([name^="parent-"])' | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         ).filter((folder) => folder.checked); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         checkedFolders = checkedFolders.concat(folders); | 
					
						
							| 
									
										
										
										
											2020-01-12 01:15:19 +01:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-05-03 23:39:02 +02:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 23:39:02 +02:00
										 |  |  |     let filters = []; | 
					
						
							|  |  |  |     checkedFolders.forEach((folder) => { | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |       const mailFolderExt = JSON.parse(folder.value); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 23:39:02 +02:00
										 |  |  |       filters.push({ | 
					
						
							|  |  |  |         unread: true, | 
					
						
							| 
									
										
										
										
											2020-05-12 21:38:03 +02:00
										 |  |  |         folder: mailFolderExt, | 
					
						
							| 
									
										
										
										
											2020-05-03 23:39:02 +02:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |     //  Store extended query filters
 | 
					
						
							| 
									
										
										
										
											2020-04-01 23:33:08 +02:00
										 |  |  |     browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |       filters: filters, | 
					
						
							| 
									
										
										
										
											2020-04-01 23:33:08 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     //  Save debug state
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |     const debug = document.querySelector('input[name="debug"]').checked; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |       debug: `${debug}`, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-07 17:19:02 +02:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     // Save minimize preferences
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2020-04-11 20:13:11 +02:00
										 |  |  |     const minimizeType = document.querySelector( | 
					
						
							|  |  |  |       'input[name="minimizeType"]:checked' | 
					
						
							|  |  |  |     ).value; | 
					
						
							| 
									
										
										
										
											2020-04-07 17:19:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     //  Store minimize preferences
 | 
					
						
							|  |  |  |     browser.storage.sync.set({ | 
					
						
							|  |  |  |       minimizeType: minimizeType, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     //  Save start minimized state
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2020-05-10 21:47:41 +02:00
										 |  |  |     const startMinimized = document.querySelector( | 
					
						
							|  |  |  |       'input[name="startMinimized"]' | 
					
						
							|  |  |  |     ).checked; | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |     browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |       startMinimized: `${startMinimized}`, | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-02-18 00:24:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 20:55:27 +02:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     //  Save minimize on close state
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     let minimizeOnClose = document.querySelector( | 
					
						
							|  |  |  |       'input[name="minimizeOnClose"]' | 
					
						
							|  |  |  |     ).checked; | 
					
						
							|  |  |  |     browser.storage.sync.set({ | 
					
						
							|  |  |  |       minimizeOnClose: `${minimizeOnClose}`, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     // Save icon preferences
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const iconType = document.querySelector('input[name="iconType"]:checked') | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |       .value; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //  Store icon type
 | 
					
						
							|  |  |  |     browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |       iconType: iconType, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |     const iconDiv = document.getElementById("icon"); | 
					
						
							|  |  |  |     const iconBase64 = iconDiv.getAttribute("data-icon"); | 
					
						
							|  |  |  |     const iconMime = iconDiv.getAttribute("data-icon-mime"); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     //  Store icon (base64)
 | 
					
						
							|  |  |  |     browser.storage.sync.set({ | 
					
						
							|  |  |  |       iconMime: iconMime, | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |       icon: iconBase64, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //  Mark add-on preferences changed
 | 
					
						
							|  |  |  |     browser.storage.sync.set({ | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |       addonprefchanged: true, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-04-05 14:39:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     //  Save enable number state
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2020-05-10 21:47:41 +02:00
										 |  |  |     const showNumber = document.querySelector('input[name="showNumber"]') | 
					
						
							|  |  |  |       .checked; | 
					
						
							| 
									
										
										
										
											2020-04-05 14:39:19 +02:00
										 |  |  |     browser.storage.sync.set({ | 
					
						
							|  |  |  |       showNumber: `${showNumber}`, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     //  Save number color
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2020-05-10 21:47:41 +02:00
										 |  |  |     const numberColor = document.querySelector('input[name="numberColor"]') | 
					
						
							|  |  |  |       .value; | 
					
						
							| 
									
										
										
										
											2020-04-05 14:39:19 +02:00
										 |  |  |     browser.storage.sync.set({ | 
					
						
							|  |  |  |       numberColor: `${numberColor}`, | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     // Save count type preferences
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     const countType = document.querySelector('input[name="countType"]:checked') | 
					
						
							|  |  |  |       .value; | 
					
						
							|  |  |  |     browser.storage.sync.set({ | 
					
						
							|  |  |  |       countType: countType, | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-01-11 17:17:01 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | SysTrayX.RestoreOptions = { | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   start: function () { | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     //  Restore debug state
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const getDebug = browser.storage.sync.get("debug"); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     getDebug.then( | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.setDebug, | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.onDebugError | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-07 17:19:02 +02:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     //  Restore minimize type
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2020-04-11 23:31:22 +02:00
										 |  |  |     const getMinimizeType = browser.storage.sync.get([ | 
					
						
							|  |  |  |       "platformInfo", | 
					
						
							|  |  |  |       "minimizeType", | 
					
						
							|  |  |  |     ]); | 
					
						
							| 
									
										
										
										
											2020-04-07 17:19:02 +02:00
										 |  |  |     getMinimizeType.then( | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.setMinimizeType, | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.onMinimizeTypeError | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     //  Restore start minimized
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     const getStartMinimized = browser.storage.sync.get("startMinimized"); | 
					
						
							|  |  |  |     getStartMinimized.then( | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.setStartMinimized, | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.onStartMinimizedError | 
					
						
							| 
									
										
										
										
											2020-02-18 00:24:31 +01:00
										 |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 20:55:27 +02:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     //  Restore minimize on close
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     const getMinimizeOnClose = browser.storage.sync.get("minimizeOnClose"); | 
					
						
							|  |  |  |     getMinimizeOnClose.then( | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.setMinimizeOnClose, | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.onMinimizeOnCloseError | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     //  Restore icon type
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const getIconType = browser.storage.sync.get("iconType"); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     getIconType.then( | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.setIconType, | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.onIconTypeError | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     //  Restore icon
 | 
					
						
							|  |  |  |     //
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const getIcon = browser.storage.sync.get(["iconMime", "icon"]); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     getIcon.then( | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.setIcon, | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.onIconError | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-04-01 23:33:08 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 23:39:02 +02:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     //  Restore filters
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     const getFilters = browser.storage.sync.get("filters"); | 
					
						
							|  |  |  |     getFilters.then( | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.setFilters, | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.onFiltersError | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-05 14:39:19 +02:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     //  Restore enable number state
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     const getShowNumber = browser.storage.sync.get("showNumber"); | 
					
						
							|  |  |  |     getShowNumber.then( | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.setShowNumber, | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.onShowNumberError | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     //  Restore number color
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     const getNumberColor = browser.storage.sync.get("numberColor"); | 
					
						
							|  |  |  |     getNumberColor.then( | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.setNumberColor, | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.onNumberColorError | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     //  Restore count type
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     const getCountType = browser.storage.sync.get("countType"); | 
					
						
							|  |  |  |     getCountType.then( | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.setCountType, | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.onCountTypeError | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   //  Restore debug state callbacks
 | 
					
						
							|  |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   setDebug: function (result) { | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const debug = result.debug || "false"; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const checkbox = document.querySelector(`input[name="debug"]`); | 
					
						
							|  |  |  |     checkbox.checked = debug === "true"; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   onDebugError: function (error) { | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     console.log(`Debug Error: ${error}`); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-07 17:19:02 +02:00
										 |  |  |   //
 | 
					
						
							|  |  |  |   //  Restore minimize type callbacks
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   setMinimizeType: function (result) { | 
					
						
							| 
									
										
										
										
											2020-04-11 23:31:22 +02:00
										 |  |  |     const platformInfo = result.platformInfo || { os: "linux" }; | 
					
						
							| 
									
										
										
										
											2020-04-11 20:13:11 +02:00
										 |  |  |     const minimizeType = result.minimizeType || "1"; | 
					
						
							| 
									
										
										
										
											2020-04-11 23:31:22 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Tweak option for platform
 | 
					
						
							|  |  |  |     if (platformInfo.os === "win") { | 
					
						
							|  |  |  |       document.getElementById("minimizemethod1label").innerHTML = | 
					
						
							|  |  |  |         "Minimize to tray"; | 
					
						
							|  |  |  |       document | 
					
						
							|  |  |  |         .getElementById("minimizemethod2") | 
					
						
							|  |  |  |         .setAttribute("style", "display:none;"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (minimizeType === "2") { | 
					
						
							|  |  |  |         minimizeType = "1"; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-11 20:13:11 +02:00
										 |  |  |     const radioButton = document.querySelector( | 
					
						
							|  |  |  |       `input[name="minimizeType"][value="${minimizeType}"]` | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-04-07 17:19:02 +02:00
										 |  |  |     radioButton.checked = true; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onMinimizeTypeError: function (error) { | 
					
						
							|  |  |  |     console.log(`Minimize type Error: ${error}`); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |   //
 | 
					
						
							|  |  |  |   //  Restore hide on minimize callbacks
 | 
					
						
							|  |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   setStartMinimized: function (result) { | 
					
						
							| 
									
										
										
										
											2020-03-01 21:15:41 +01:00
										 |  |  |     const startMinimized = result.startMinimized || "false"; | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const checkbox = document.querySelector(`input[name="startMinimized"]`); | 
					
						
							|  |  |  |     checkbox.checked = startMinimized === "true"; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   onStartMinimizedError: function (error) { | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |     console.log(`startMinimized Error: ${error}`); | 
					
						
							| 
									
										
										
										
											2020-02-18 00:24:31 +01:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-10 20:55:27 +02:00
										 |  |  |   //
 | 
					
						
							|  |  |  |   //  Restore minimize on close callbacks
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   setMinimizeOnClose: function (result) { | 
					
						
							|  |  |  |     const minimizeOnClose = result.minimizeOnClose || "true"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const checkbox = document.querySelector(`input[name="minimizeOnClose"]`); | 
					
						
							|  |  |  |     checkbox.checked = minimizeOnClose === "true"; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onMinimizeOnCloseError: function (error) { | 
					
						
							|  |  |  |     console.log(`minimizeOnClose Error: ${error}`); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |   //
 | 
					
						
							|  |  |  |   //  Restore icon type callbacks
 | 
					
						
							|  |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   setIconType: function (result) { | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const iconType = result.iconType || "0"; | 
					
						
							| 
									
										
										
										
											2020-04-11 20:13:11 +02:00
										 |  |  |     const radioButton = document.querySelector( | 
					
						
							|  |  |  |       `input[name="iconType"][value="${iconType}"]` | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     radioButton.checked = true; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   onIconTypeError: function (error) { | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     console.log(`Icon type Error: ${error}`); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   //  Restore icon
 | 
					
						
							|  |  |  |   //
 | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   setIconMime: function (result) { | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const iconMime = result.iconMime || ""; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const valid = iconMime !== ""; | 
					
						
							|  |  |  |     if (valid) { | 
					
						
							|  |  |  |       const iconDiv = document.getElementById("icon"); | 
					
						
							|  |  |  |       iconDiv.setAttribute("data-icon-mime", iconMime); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return valid; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   setIconData: function (result) { | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const iconBase64 = result.icon || ""; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const valid = iconBase64 !== ""; | 
					
						
							|  |  |  |     if (valid) { | 
					
						
							|  |  |  |       const iconDiv = document.getElementById("icon"); | 
					
						
							|  |  |  |       iconDiv.setAttribute("data-icon", iconBase64); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return valid; | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   updateIconImage: function () { | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const iconDiv = document.getElementById("icon"); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     icon_mime = iconDiv.getAttribute("data-icon-mime"); | 
					
						
							|  |  |  |     icon_data = iconDiv.getAttribute("data-icon"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const image = document.getElementById("customIconImage"); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     image.setAttribute("src", `data:${icon_mime};base64,${icon_data}`); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   setIcon: function (result) { | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const validMime = SysTrayX.RestoreOptions.setIconMime(result); | 
					
						
							|  |  |  |     const validData = SysTrayX.RestoreOptions.setIconData(result); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     if (validMime && validData) { | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.updateIconImage(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   onIconError: function (error) { | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     console.log(`Icon Error: ${error}`); | 
					
						
							| 
									
										
										
										
											2020-04-01 23:33:08 +02:00
										 |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-05 14:39:19 +02:00
										 |  |  |   //
 | 
					
						
							|  |  |  |   //  Restore enable number state
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   setShowNumber: function (result) { | 
					
						
							|  |  |  |     const showNumber = result.showNumber || "true"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const checkbox = document.querySelector(`input[name="showNumber"]`); | 
					
						
							|  |  |  |     checkbox.checked = showNumber === "true"; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onShowNumberError: function (error) { | 
					
						
							|  |  |  |     console.log(`showNumber Error: ${error}`); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   //  Restore number color
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   setNumberColor: function (result) { | 
					
						
							|  |  |  |     const numberColor = result.numberColor || "#000000"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const input = document.querySelector(`input[name="numberColor"]`); | 
					
						
							|  |  |  |     input.value = numberColor; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onNumberColorError: function (error) { | 
					
						
							|  |  |  |     console.log(`numberColor Error: ${error}`); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |   //
 | 
					
						
							|  |  |  |   //  Restore count type
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   setCountType: function (result) { | 
					
						
							|  |  |  |     const countType = result.countType || "0"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const radioButton = document.querySelector( | 
					
						
							|  |  |  |       `input[name="countType"][value="${countType}"]` | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     radioButton.checked = true; | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onCountTypeError: function (error) { | 
					
						
							|  |  |  |     console.log(`countType Error: ${error}`); | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 23:39:02 +02:00
										 |  |  |   //
 | 
					
						
							|  |  |  |   //  Restore filters callbacks
 | 
					
						
							|  |  |  |   //
 | 
					
						
							|  |  |  |   setFilters: function (result) { | 
					
						
							|  |  |  |     let filters = result.filters || undefined; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     //  No filters stored?
 | 
					
						
							|  |  |  |     if (filters == undefined) { | 
					
						
							|  |  |  |       //  Create default filters
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const treeBase = document.getElementById("accountsTree"); | 
					
						
							|  |  |  |       const accountsBoxes = treeBase.querySelectorAll( | 
					
						
							|  |  |  |         'input[type="checkbox"][name*="account"]' | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       let accounts = []; | 
					
						
							|  |  |  |       accountsBoxes.forEach((acoountbox) => { | 
					
						
							|  |  |  |         const value = JSON.parse(acoountbox.value); | 
					
						
							|  |  |  |         accounts.push({ folders: value.folders }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       filters = []; | 
					
						
							|  |  |  |       accounts.forEach((account) => { | 
					
						
							|  |  |  |         const inbox = account.folders.filter( | 
					
						
							|  |  |  |           (folder) => folder.type == "inbox" | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (inbox.length > 0) { | 
					
						
							| 
									
										
										
										
											2020-05-21 12:12:10 +02:00
										 |  |  |           let folder = { | 
					
						
							|  |  |  |             ...inbox[0], | 
					
						
							|  |  |  |             accountName: account.name, | 
					
						
							|  |  |  |             path: "/" + inbox[0].name, | 
					
						
							|  |  |  |           }; | 
					
						
							|  |  |  |           delete folder.type; | 
					
						
							|  |  |  |           delete folder.subFolders; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-03 23:39:02 +02:00
										 |  |  |           filters.push({ | 
					
						
							|  |  |  |             unread: true, | 
					
						
							| 
									
										
										
										
											2020-05-21 12:12:10 +02:00
										 |  |  |             folder: folder, | 
					
						
							| 
									
										
										
										
											2020-05-03 23:39:02 +02:00
										 |  |  |           }); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (filters) { | 
					
						
							|  |  |  |       const treeBase = document.getElementById("accountsTree"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       filters.forEach((filter) => { | 
					
						
							|  |  |  |         const folder = filter.folder; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const account = treeBase.querySelector( | 
					
						
							|  |  |  |           `input[name=${folder.accountId}]` | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         const checkboxes = Array.from( | 
					
						
							|  |  |  |           account.parentNode.querySelectorAll( | 
					
						
							|  |  |  |             'input[type="checkbox"]:not([name^="account"]):not([name^="parent-"])' | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         checkboxes.forEach((checkbox) => { | 
					
						
							|  |  |  |           const value = JSON.parse(checkbox.value); | 
					
						
							|  |  |  |           if (value.path === folder.path) { | 
					
						
							|  |  |  |             checkbox.checked = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             const event = document.createEvent("HTMLEvents"); | 
					
						
							|  |  |  |             event.initEvent("change", false, true); | 
					
						
							|  |  |  |             checkbox.dispatchEvent(event); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onFiltersError: function (error) { | 
					
						
							|  |  |  |     console.log(`Filters Error: ${error}`); | 
					
						
							|  |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SysTrayX.StorageChanged = { | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   changed: function (changes, area) { | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     //  Try to keep the preferences of the add-on and the app in sync
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  |     const changedItems = Object.keys(changes); | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let changed_icon = false; | 
					
						
							|  |  |  |     let changed_icon_mime = false; | 
					
						
							|  |  |  |     for (let item of changedItems) { | 
					
						
							|  |  |  |       if (item === "iconMime") { | 
					
						
							|  |  |  |         SysTrayX.RestoreOptions.setIconMime({ | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |           iconMime: changes[item].newValue, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (item === "icon") { | 
					
						
							|  |  |  |         SysTrayX.RestoreOptions.setIcon({ icon: changes[item].newValue }); | 
					
						
							|  |  |  |         changed_icon = true; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (item === "iconType") { | 
					
						
							|  |  |  |         SysTrayX.RestoreOptions.setIconType({ | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |           iconType: changes[item].newValue, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |         changed_icon_mime = true; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-04-05 14:39:19 +02:00
										 |  |  |       if (item === "showNumber") { | 
					
						
							|  |  |  |         SysTrayX.RestoreOptions.setShowNumber({ | 
					
						
							|  |  |  |           showNumber: changes[item].newValue, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if (item === "numberColor") { | 
					
						
							|  |  |  |         SysTrayX.RestoreOptions.setNumberColor({ | 
					
						
							|  |  |  |           numberColor: changes[item].newValue, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-05-09 17:10:54 +02:00
										 |  |  |       if (item === "countType") { | 
					
						
							|  |  |  |         SysTrayX.RestoreOptions.setCountType({ | 
					
						
							|  |  |  |           countType: changes[item].newValue, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-04-07 17:19:02 +02:00
										 |  |  |       if (item === "minimizeType") { | 
					
						
							|  |  |  |         SysTrayX.RestoreOptions.setMinimizeType({ | 
					
						
							|  |  |  |           minimizeType: changes[item].newValue, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-02-29 19:04:43 +01:00
										 |  |  |       if (item === "startMinimized") { | 
					
						
							|  |  |  |         SysTrayX.RestoreOptions.setStartMinimized({ | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |           startMinimized: changes[item].newValue, | 
					
						
							| 
									
										
										
										
											2020-02-18 00:24:31 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-05-10 20:55:27 +02:00
										 |  |  |       if (item === "minimizeOnClose") { | 
					
						
							|  |  |  |         SysTrayX.RestoreOptions.setMinimizeOnClose({ | 
					
						
							|  |  |  |           minimizeOnClose: changes[item].newValue, | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |       if (item === "debug") { | 
					
						
							|  |  |  |         SysTrayX.RestoreOptions.setDebug({ | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |           debug: changes[item].newValue, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-05 00:54:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     if (changed_icon_mime && changed_icon) { | 
					
						
							|  |  |  |       SysTrayX.RestoreOptions.updateIconImage(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-09 21:03:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |     //
 | 
					
						
							|  |  |  |     //  Update element
 | 
					
						
							|  |  |  |     //
 | 
					
						
							|  |  |  |     document.getElementById("debugselect").className = "active"; | 
					
						
							|  |  |  |     document.getElementById("iconselect").className = "active"; | 
					
						
							| 
									
										
										
										
											2020-04-07 17:19:02 +02:00
										 |  |  |     document.getElementById("minimizeselect").className = "active"; | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  |   }, | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2020-01-05 00:54:40 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-23 23:28:52 +01:00
										 |  |  | //
 | 
					
						
							|  |  |  | //  Main
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2020-04-04 18:02:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | //  Get addon version
 | 
					
						
							|  |  |  | SysTrayX.version = browser.runtime.getManifest().version; | 
					
						
							|  |  |  | document.getElementById("VersioHomeLink").href = | 
					
						
							|  |  |  |   "https://github.com/Ximi1970/systray-x/releases/tag/" + SysTrayX.version; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  | document.addEventListener("DOMContentLoaded", SysTrayX.RestoreOptions.start); | 
					
						
							| 
									
										
										
										
											2020-01-09 21:03:06 +01:00
										 |  |  | document | 
					
						
							|  |  |  |   .querySelector('[name="saveform"]') | 
					
						
							| 
									
										
										
										
											2020-01-22 23:14:46 +01:00
										 |  |  |   .addEventListener("submit", SysTrayX.SaveOptions.start); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | browser.storage.onChanged.addListener(SysTrayX.StorageChanged.changed); |