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 @@
-
-