diff --git a/.gitignore b/.gitignore index 86c2fc7..43baa73 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -*.xpi - +/*.xpi +/SysTray-X diff --git a/README.md b/README.md index 48b369e..4f287bc 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ The add-on and system tray application can do: - custom new mail icon - display number of unread mails - show / hide Thunderbird (minimize) -- to be implemented: remove from task bar when minimized +- minimizing hides to tray +- minimize on startup - to be implemented: start a new mail - to be implemented: open the last used account diff --git a/README.references.txt b/README.references.txt index 50aadf9..3f2a55c 100644 --- a/README.references.txt +++ b/README.references.txt @@ -1,3 +1,116 @@ +# diff --git a/webext/background.js b/webext/background.js index 98d0517..068ff88 100644 --- a/webext/background.js +++ b/webext/background.js @@ -1,5 +1,3 @@ -console.log("Starting background.js"); - var SysTrayX = { debugAccounts: false }; @@ -11,17 +9,18 @@ SysTrayX.Messaging = { ], init: function() { - console.log("Enabling Messaging"); - // Get the accounts from the storage SysTrayX.Messaging.getAccounts(); browser.storage.onChanged.addListener(SysTrayX.Messaging.storageChanged); + // Send the window title to app + SysTrayX.Messaging.sendTitle(); + // Send preferences to app SysTrayX.Messaging.sendPreferences(); // this.unReadMessages(this.unreadFiltersTest).then(this.unreadCb); - window.setInterval(SysTrayX.Messaging.pollAccounts, 10000); + window.setInterval(SysTrayX.Messaging.pollAccounts, 1000); // Send the app a close command if the window closes browser.windows.onRemoved.addListener(SysTrayX.Window.closed); @@ -34,14 +33,10 @@ SysTrayX.Messaging = { // Handle a storage change // storageChanged: function(changes, area) { - console.debug("Changes in store"); - // Get the new preferences SysTrayX.Messaging.getAccounts(); if ("addonprefchanged" in changes && changes["addonprefchanged"].newValue) { - console.debug("Sending preference"); - // // Send new preferences to the app // @@ -52,36 +47,28 @@ SysTrayX.Messaging = { addonprefchanged: false }); } - - /* - var changedItems = Object.keys(changes); - for (var item of changedItems) { - console.log(item + " has changed:"); - console.log("Old value: "); - console.log(changes[item].oldValue); - console.log("New value: "); - console.log(changes[item].newValue); - } -*/ }, // // Poll the accounts // pollAccounts: function() { - console.debug("Polling"); - // // Get the unread nessages of the selected accounts // const filtersDiv = document.getElementById("filters"); const filtersAttr = filtersDiv.getAttribute("data-filters"); - const filters = JSON.parse(filtersAttr); - if (filters.length > 0) { - SysTrayX.Messaging.unReadMessages(filters).then( - SysTrayX.Messaging.unreadCb - ); + 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 }); + } } else { SysTrayX.Messaging.unReadMessages([{ unread: true }]).then( SysTrayX.Messaging.unreadCb @@ -118,11 +105,16 @@ SysTrayX.Messaging = { SysTrayX.Link.postSysTrayXMessage({ unreadMail: count }); }, - sendPreferences: function() { - console.debug("Send preferences"); + sendTitle: function() { + const title = "-" + SysTrayX.Window.startWindow.title.split("-").pop(); + SysTrayX.Link.postSysTrayXMessage({ title: title }); + }, + sendPreferences: function() { const getter = browser.storage.sync.get([ "debug", + "hideOnMinimize", + "startMinimized", "iconType", "iconMime", "icon" @@ -131,22 +123,19 @@ SysTrayX.Messaging = { }, sendPreferencesStorage: function(result) { - console.debug("Get preferences from storage"); - const debug = result.debug || "false"; + const hideOnMinimize = result.hideOnMinimize || "true"; + const startMinimized = result.startMinimized || "false"; const iconType = result.iconType || "0"; const iconMime = result.iconMime || "image/png"; const icon = result.icon || []; - console.log(`Debug ${debug}`); - console.log(`Type ${iconType}`); - console.log(`Mime ${iconMime}`); - console.log(icon); - // Send it to the app SysTrayX.Link.postSysTrayXMessage({ preferences: { debug: debug, + hideOnMinimize: hideOnMinimize, + startMinimized: startMinimized, iconType: iconType, iconMime: iconMime, icon: icon @@ -162,8 +151,6 @@ SysTrayX.Messaging = { // Get the accounts from the storage // getAccounts: function() { - console.debug("Get accounts"); - const getter = browser.storage.sync.get(["accounts", "filters"]); getter.then(this.getAccountsStorage, this.onGetAccountsStorageError); @@ -183,15 +170,13 @@ SysTrayX.Messaging = { // make them available in the background HTML // getAccountsStorage: function(result) { - console.debug("Get accounts from storage"); - - const accounts = result.accounts || []; + const accounts = result.accounts || undefined; // Store them in the background HTML const accountsDiv = document.getElementById("accounts"); accountsDiv.setAttribute("data-accounts", JSON.stringify(accounts)); - const filters = result.filters || []; + const filters = result.filters || undefined; // Store them in the background HTML const filtersDiv = document.getElementById("filters"); @@ -225,11 +210,7 @@ SysTrayX.Link = { }, receiveSysTrayXMessage: function(response) { - console.log(`Received: ${response}`); - if (response["window"]) { - console.log("Window received: " + response["window"]); - if (response["window"] === "minimized") { browser.windows.update(SysTrayX.Window.startWindow.id, { state: "minimized" @@ -244,10 +225,12 @@ SysTrayX.Link = { } } + if (response["shutdown"]) { + console.log("Shutdown received: " + response["shutdown"]); + } + if (response["preferences"]) { // Store the preferences from the app - console.log("Preferences received"); - const iconMime = response["preferences"].iconMime; if (iconMime) { browser.storage.sync.set({ @@ -269,6 +252,20 @@ SysTrayX.Link = { }); } + const hideOnMinimize = response["preferences"].hideOnMinimize; + if (hideOnMinimize) { + browser.storage.sync.set({ + hideOnMinimize: hideOnMinimize + }); + } + + const startMinimized = response["preferences"].startMinimized; + if (startMinimized) { + browser.storage.sync.set({ + startMinimized: startMinimized + }); + } + const debug = response["preferences"].debug; if (debug) { browser.storage.sync.set({ @@ -282,60 +279,42 @@ SysTrayX.Link = { SysTrayX.Window = { startWindow: undefined, - closed: function() { - // Window closed - console.debug("Shutting down"); - + closed: function(windowId) { + // Window closed // Send it to the app - SysTrayX.Link.postSysTrayXMessage({ - shutdown: "" - }); + SysTrayX.Link.postSysTrayXMessage({ shutdown: "true" }); }, focusChanged: function(windowId) { - console.debug("Win focus changed"); - browser.windows.getCurrent().then(win => { SysTrayX.Link.postSysTrayXMessage({ window: win.state }); }); - - /* - if (windowId === -1) { - // Assume minimized - SysTrayX.Link.postSysTrayXMessage({ - window: "minimized" - }); - } else { - browser.windows.get(windowId, function(win) { - SysTrayX.Link.postSysTrayXMessage({ - window: win.state - }); - }); - } -*/ } }; async function start() { - // Init defaults before everything + // Get the prefered start state + const state = await getStartupState(); + + if (state == "minimized") { + browser.windows.update(browser.windows.WINDOW_ID_CURRENT, { + state: "minimized" + }); + } + + // Init defaults before everything await getDefaultIcon(); SysTrayX.Window.startWindow = await browser.windows .getCurrent() .then(currentWindow => currentWindow); - console.debug("Window focus: " + SysTrayX.Window.startWindow.focused); - console.debug("Window name: " + SysTrayX.Window.startWindow.title); - console.debug("Window name: " + SysTrayX.Window.startWindow.state); - - // browser.windows.update(currentWindow.id, { state: "minimized" }); - // browser.windows.update(currentWindow.id, { state: "normal", focused: true }); - - // ?? browser.windows.update(currentWindow.id, { state: "docked" }); - // Setup the link first SysTrayX.Link.init(); + // Send current state + SysTrayX.Link.postSysTrayXMessage({ window: state }); + // Main start SysTrayX.Messaging.init(); } @@ -344,5 +323,3 @@ console.log("Starting SysTray-X"); // Start the add-on start(); - -console.log("End SysTray-X"); diff --git a/webext/icons/Thunderbird.png b/webext/icons/Thunderbird.png new file mode 100644 index 0000000..b594533 Binary files /dev/null and b/webext/icons/Thunderbird.png differ diff --git a/webext/js/defaults.js b/webext/js/defaults.js index deb70f0..0d1313e 100644 --- a/webext/js/defaults.js +++ b/webext/js/defaults.js @@ -49,8 +49,21 @@ async function getDefaultIcon() { const iconDiv = document.getElementById("icon"); iconDiv.setAttribute("data-icon-mime", iconMime); iconDiv.setAttribute("data-icon", iconBase64); - - console.debug("Default: " + iconMime); - console.debug("Default: " + iconBase64); } } + +// +// Get window startup state +// +async function getStartupState() { + function getStartupState(result) { + return result.startMinimized == "true" ? "minimized" : "normal"; + } + + function onStartupStateError() { + return "normal"; + } + + const getState = browser.storage.sync.get("startMinimized"); + return await getState.then(getStartupState, onStartupStateError); +} diff --git a/webext/js/options_accounts.js b/webext/js/options_accounts.js index 5727e11..7978365 100644 --- a/webext/js/options_accounts.js +++ b/webext/js/options_accounts.js @@ -22,9 +22,9 @@ SysTrayX.Accounts = { let accounts = new Object(); for (let i = 0; i < mailAccount.length; i++) { - console.debug("SysTrayX accounts id: " + mailAccount[i].id); - console.debug("SysTrayX accounts name: " + mailAccount[i].name); - console.debug("SysTrayX accounts type: " + mailAccount[i].type); + // console.debug("SysTrayX accounts id: " + mailAccount[i].id); + // console.debug("SysTrayX accounts name: " + mailAccount[i].name); + // console.debug("SysTrayX accounts type: " + mailAccount[i].type); if (!accounts[mailAccount[i].type]) { accounts[mailAccount[i].type] = []; @@ -66,7 +66,9 @@ SysTrayX.Accounts = { typeInput.setAttribute("value", JSON.stringify(accounts[prop][i])); typeInput.setAttribute("checked", "true"); typeLi.appendChild(typeInput); - const typeText = document.createTextNode(" " + accounts[prop][i].name); + const typeText = document.createTextNode( + " " + accounts[prop][i].name + ); typeLi.appendChild(typeText); typeUl.appendChild(typeLi); } @@ -77,8 +79,6 @@ SysTrayX.Accounts = { // Restore saved selection function setAccounts(result) { - console.debug("Restore account selection"); - const treeBase = document.getElementById("accountsTree"); const accounts = result.accounts || []; for (let i = 0; i < accounts.length; ++i) { @@ -89,8 +89,6 @@ SysTrayX.Accounts = { checkbox.checked = accounts[i].checked; } } - - console.debug("Restore account selection done"); } function onError(error) { diff --git a/webext/js/options_iconform.js b/webext/js/options_iconform.js index 49f7dbe..0e23576 100644 --- a/webext/js/options_iconform.js +++ b/webext/js/options_iconform.js @@ -1,10 +1,10 @@ function fileSelected() { const input = document.getElementById("selectedFileIconType"); - if (input.files.length > 0) { - console.debug("Selected file: " + input.files[0].name); - console.debug("Selected file type: " + input.files[0].type); - } + // if (input.files.length > 0) { + // console.debug("Selected file: " + input.files[0].name); + // console.debug("Selected file type: " + input.files[0].type); + // } function storeFile() { const buffer = new Uint8Array(fr.result); @@ -21,9 +21,7 @@ function fileSelected() { iconDiv.setAttribute("data-icon-mime", input.files[0].type); const image = document.getElementById("customIconImage"); - image.setAttribute("src", `data:${input.files[0].type};base64,${base64}` ); - - console.log(base64); + image.setAttribute("src", `data:${input.files[0].type};base64,${base64}`); } fr = new FileReader(); diff --git a/webext/manifest.json b/webext/manifest.json index d037a97..ad0ff10 100644 --- a/webext/manifest.json +++ b/webext/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, - "name": "__MSG_extensionName__", - "description": "__MSG_extensionDescription__", + "name": "__MSG_extension_name__", + "description": "__MSG_extension_description__", "version": "0.1", "author": "Maxime Rijnders", "homepage_url": "https://github.com/Ximi1970/systray-x", diff --git a/webext/options.html b/webext/options.html index ccb17f5..5fc1277 100644 --- a/webext/options.html +++ b/webext/options.html @@ -9,33 +9,20 @@ -
-
- Display debug - window
-
-
-
- - - + + + +

Windows

-

Windows options here

- -

Please select your option:

- Option 1
- Option 2
- Option 3
- -

Please check the boxes:

- Check 1
- Check 2
- Check 3
+ Minimizing + window hides to tray
+ Start + application minimized
@@ -96,6 +83,18 @@ +
+
+

Debug options

+
+
+ Display debug + window
+
+
+
+
+
diff --git a/webext/options.js b/webext/options.js index 902518d..57e7710 100644 --- a/webext/options.js +++ b/webext/options.js @@ -4,23 +4,9 @@ SysTrayX.SaveOptions = { start: function(e) { e.preventDefault(); - console.debug("Save preferences"); - - browser.storage.sync.set({ - optionsRadioTest: document.querySelector( - 'input[name="options_test"]:checked' - ).value, - optionsCheck1: document.querySelector('input[name="check1"]').checked, - optionsCheck2: document.querySelector('input[name="check2"]').checked, - optionsCheck3: document.querySelector('input[name="check3"]').checked - }); - // // Save accounts and filters // - - console.debug("Store accounts and filters"); - const treeBase = document.getElementById("accountsTree"); const inputs = treeBase.querySelectorAll("input"); let accounts = []; @@ -34,9 +20,6 @@ SysTrayX.SaveOptions = { let inboxMailFolder = account.folders.find(obj => obj.type === "inbox"); if (inboxMailFolder) { - console.debug("Filter Id: " + inboxMailFolder.accountId); - console.debug("Filter Path: " + inboxMailFolder.path); - filters.push({ unread: true, folder: inboxMailFolder @@ -55,8 +38,6 @@ SysTrayX.SaveOptions = { filters: filters }); - console.debug("Store accounts and filters done"); - // // Save debug state // @@ -64,14 +45,28 @@ SysTrayX.SaveOptions = { browser.storage.sync.set({ debug: `${debug}` }); - console.debug("Store debug state: " + `${debug}`); + + // + // Save hide on minimize state + // + let hideOnMinimize = document.querySelector('input[name="hideOnMinimize"]') + .checked; + browser.storage.sync.set({ + hideOnMinimize: `${hideOnMinimize}` + }); + + // + // Save start minimized state + // + let startMinimized = document.querySelector('input[name="startMinimized"]') + .checked; + browser.storage.sync.set({ + startMinimized: `${startMinimized}` + }); // // Save icon preferences // - - console.debug("Store icon preferences"); - const iconType = document.querySelector('input[name="iconType"]:checked') .value; @@ -90,8 +85,6 @@ SysTrayX.SaveOptions = { icon: iconBase64 }); - console.debug("Store icon preferences done"); - // Mark add-on preferences changed browser.storage.sync.set({ addonprefchanged: true @@ -101,32 +94,6 @@ SysTrayX.SaveOptions = { SysTrayX.RestoreOptions = { start: function() { - console.debug("Restore preferences"); - - // - // Test 1 - // - const getRadioTest = browser.storage.sync.get("optionsRadioTest"); - getRadioTest.then( - SysTrayX.RestoreOptions.setCurrentRadioChoice, - SysTrayX.RestoreOptions.onError - ); - - // - // Test 2 - // - const getCheckTest = browser.storage.sync.get([ - "optionsCheck1", - "optionsCheck2", - "optionsCheck3" - ]); - getCheckTest.then( - SysTrayX.RestoreOptions.setCurrentCheckChoice, - SysTrayX.RestoreOptions.onError - ); - - console.debug("Restore icon preferences"); - // // Restore debug state // @@ -136,6 +103,24 @@ SysTrayX.RestoreOptions = { SysTrayX.RestoreOptions.onDebugError ); + // + // Restore hide on minimize + // + const getHideOnMinimize = browser.storage.sync.get("hideOnMinimize"); + getHideOnMinimize.then( + SysTrayX.RestoreOptions.setHideOnMinimize, + SysTrayX.RestoreOptions.onHideOnMinimizeError + ); + + // + // Restore start minimized + // + const getStartMinimized = browser.storage.sync.get("startMinimized"); + getStartMinimized.then( + SysTrayX.RestoreOptions.setStartMinimized, + SysTrayX.RestoreOptions.onStartMinimizedError + ); + // // Restore icon type // @@ -153,36 +138,6 @@ SysTrayX.RestoreOptions = { SysTrayX.RestoreOptions.setIcon, SysTrayX.RestoreOptions.onIconError ); - - console.debug("Restore icon preferences done"); - }, - - // - // Test 1 Callback - // - setCurrentRadioChoice: function(result) { - const selector = result.optionsRadioTest || "Option1"; - const radioButton = document.querySelector(`[value=${selector}]`); - radioButton.checked = true; - }, - - // - // Test 2 Callback - // - setCurrentCheckChoice: function(result) { - const checkbox1 = document.querySelector('[name="check1"]'); - checkbox1.checked = result.optionsCheck1 || false; - const checkbox2 = document.querySelector('[name="check2"]'); - checkbox2.checked = result.optionsCheck2 || false; - const checkbox3 = document.querySelector('[name="check3"]'); - checkbox3.checked = result.optionsCheck3 || false; - }, - - // - // Test 1+2 error callback - // - onError: function(error) { - console.log(`Error: ${error}`); }, // @@ -191,8 +146,6 @@ SysTrayX.RestoreOptions = { setDebug: function(result) { const debug = result.debug || "false"; - console.debug("Debug: " + debug); - const checkbox = document.querySelector(`input[name="debug"]`); checkbox.checked = debug === "true"; }, @@ -201,6 +154,34 @@ SysTrayX.RestoreOptions = { console.log(`Debug Error: ${error}`); }, + // + // Restore hide on minimize callbacks + // + setHideOnMinimize: function(result) { + const hideOnMinimize = result.hideOnMinimize || "true"; + + const checkbox = document.querySelector(`input[name="hideOnMinimize"]`); + checkbox.checked = hideOnMinimize === "true"; + }, + + onHideOnMinimizeError: function(error) { + console.log(`hideOnMinimize Error: ${error}`); + }, + + // + // Restore hide on minimize callbacks + // + setStartMinimized: function(result) { + const startMinimized = result.startMinimized || "false"; + + const checkbox = document.querySelector(`input[name="startMinimized"]`); + checkbox.checked = startMinimized === "true"; + }, + + onStartMinimizedError: function(error) { + console.log(`startMinimized Error: ${error}`); + }, + // // Restore icon type callbacks // @@ -287,6 +268,16 @@ SysTrayX.StorageChanged = { }); changed_icon_mime = true; } + if (item === "hideOnMinimize") { + SysTrayX.RestoreOptions.setHideOnMinimize({ + hideOnMinimize: changes[item].newValue + }); + } + if (item === "startMinimized") { + SysTrayX.RestoreOptions.setStartMinimized({ + startMinimized: changes[item].newValue + }); + } if (item === "debug") { SysTrayX.RestoreOptions.setDebug({ debug: changes[item].newValue