Skip to content

Commit

Permalink
Move status indicator to browserAction (#487)
Browse files Browse the repository at this point in the history
  • Loading branch information
jph-sendlater authored Nov 26, 2022
1 parent a944fde commit 16ee2d9
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 58 deletions.
4 changes: 2 additions & 2 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@
"description": ""
},
"showStatusPrefLabel": {
"message": "Show Send Later In Status Bar",
"description": ""
"message": "Show text in toolbar button",
"description": "If this setting is enabled, then the toolbar button will say 'Send Later' (or translated equivalent) alongside the icon. If it is disabled, then only the icon will be visible."
},
"userGuideLabel": {
"message": "User guide",
Expand Down
104 changes: 73 additions & 31 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ const SendLater = {
);
}

let composeDetails = await messenger.compose.getComposeDetails(tabId);
// // // Merge the new custom headers into the original headers
// // // Note: this shouldn't be necessary, but it appears that
// // // `setComposeDetails` does not preserve existing headers.
// // let composeDetails = await messenger.compose.getComposeDetails(tabId);
// // for (let hdr of composeDetails.customHeaders) {
// // if (!hdr.name.toLowerCase().startsWith("x-send-later")) {
// // customHeaders.push(hdr);
Expand Down Expand Up @@ -635,21 +635,15 @@ const SendLater = {
let extName = messenger.i18n.getMessage("extensionName");
let nActive = await SLTools.countActiveScheduledMessages();
if (nActive) {
messenger.spacesToolbar.updateButton(
SLStatic.TOOLBAR_ID,
{
title: `${extName} [${messenger.i18n.getMessage("PendingMessage", [nActive])}]`,
badgeText: String(nActive),
}
);
messenger.browserAction.setTitle({title: (
`${extName} [${messenger.i18n.getMessage("PendingMessage", [nActive])}]`
)});
messenger.browserAction.setBadgeText({text: String(nActive)});
} else {
messenger.spacesToolbar.updateButton(
SLStatic.TOOLBAR_ID,
{
title: `${extName} [${messenger.i18n.getMessage("IdleMessage")}]`,
badgeText: "",
}
);
messenger.browserAction.setTitle({title: (
`${extName} [${messenger.i18n.getMessage("IdleMessage")}]`
)});
messenger.browserAction.setBadgeText({text: null});
}
},

Expand Down Expand Up @@ -698,10 +692,17 @@ const SendLater = {
SLStatic.shortDateTimeFormat = preferences.shortDateTimeFormat;
messenger.SL3U.setLogConsoleLevel(SLStatic.logConsoleLevel);

for (let pref of ["customizeDateTime", "longDateTimeFormat", "shortDateTimeFormat", "instanceUUID"])
for (let pref of [
"customizeDateTime", "longDateTimeFormat", "shortDateTimeFormat", "instanceUUID"
]) {
messenger.columnHandler.setPreference(pref, preferences[pref]);
}

SendLater.setQuitNotificationsEnabled(preferences.askQuit);

messenger.browserAction.setLabel({label: (
preferences.showStatus ? messenger.i18n.getMessage("sendlater3header.label") : ""
)});
}).catch(ex => SLStatic.error(ex));

// Initialize drafts folder column
Expand All @@ -715,14 +716,6 @@ const SendLater = {
name: messenger.i18n.getMessage("sendlater3header.label"),
});

// Add spacesToolbar button
await messenger.spacesToolbar.addButton(
SLStatic.TOOLBAR_ID, {
title: messenger.i18n.getMessage("extensionName"),
url: messenger.runtime.getURL("ui/options.html"),
}
);

// Attach to all existing msgcompose windows
messenger.SL3U.hijackComposeWindowKeyBindings().catch(ex => {
SLStatic.error("SL3U.hijackComposeWindowKeyBindings",ex);
Expand Down Expand Up @@ -778,6 +771,10 @@ const SendLater = {

SendLater.setQuitNotificationsEnabled(preferences.askQuit);

messenger.browserAction.setLabel({label: (
preferences.showStatus ? messenger.i18n.getMessage("sendlater3header.label") : ""
)});

// Note: It's possible to immediately obey a preference change if the
// user has decided to disable the send later column, but when the column
// is being enabled there isn't a simple way to tell whether we're in a
Expand Down Expand Up @@ -1089,6 +1086,53 @@ messenger.runtime.onMessage.addListener(async (message, sender) => {

break;
}
case "getAllSchedules": {
response.schedules = await SLTools.forAllDrafts(
async (draftHdr) => {
return await messenger.messages.getFull(draftHdr.id).then(
async (draftMsg) => {
function getHeader(name) {
return (draftMsg.headers[name]||[])[0];
}
if (getHeader("x-send-later-at")) {
return {
sendAt: getHeader("x-send-later-at"),
recur: getHeader("x-send-later-recur"),
args: getHeader("x-send-later-args"),
cancel: getHeader("x-send-later-cancel-on-reply"),
subject: draftHdr.subject,
recipients: draftHdr.recipients,
}
} else {
return null;
}
}
);
},
false // non-sequential
).then((r) => r.filter(x => x != null));
break;
}
case "showPreferences": {
messenger.runtime.openOptionsPage();
break;
}
case "showUserGuide": {
messenger.windows.openDefaultBrowser('https://extended-thunder.github.io/send-later/');
break;
}
case "showReleaseNotes": {
messenger.windows.openDefaultBrowser("https://github.com/Extended-Thunder/send-later/releases");
break;
}
case "contactAuthor": {
messenger.windows.openDefaultBrowser("https://github.com/Extended-Thunder/send-later/discussions/278");
break;
}
case "donateLink": {
messenger.windows.openDefaultBrowser("https://extended-thunder.github.io/send-later/#support-send-later");
break;
}
default: {
SLStatic.warn(`Unrecognized operation <${message.action}>.`);
}
Expand Down Expand Up @@ -1203,9 +1247,8 @@ function mainLoop() {
// or (⌛ \u231B) (e.g. badgeText = "\u27F3")
let extName = messenger.i18n.getMessage("extensionName");
let isActiveMessage = messenger.i18n.getMessage("CheckingMessage");
messenger.spacesToolbar.updateButton(
SLStatic.TOOLBAR_ID, {title: `${extName} [${isActiveMessage}]`}
);
messenger.browserAction.enable();
messenger.browserAction.setTitle({title: `${extName} [${isActiveMessage}]`});

let doSequential = preferences.throttleDelay > 0;
SLTools.forAllDrafts(SendLater.possiblySendMessage, doSequential).then(() => {
Expand All @@ -1227,10 +1270,9 @@ function mainLoop() {
SendLater.setQuitNotificationsEnabled(false);
let extName = messenger.i18n.getMessage("extensionName");
let disabledMsg = messenger.i18n.getMessage("DisabledMessage");
messenger.spacesToolbar.updateButton(
SLStatic.TOOLBAR_ID,
{title: `${extName} [${disabledMsg}]`, badgeText: "X"}
);
messenger.browserAction.disable();
messenger.browserAction.setTitle({title: `${extName} [${disabledMsg}]`});
messenger.browserAction.setBadgeText({text: null});

SendLater.previousLoop = new Date();
SendLater.loopTimeout = setTimeout(mainLoop, 60000);
Expand Down
23 changes: 12 additions & 11 deletions experiments/legacyColumnImplementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var LegacyColumn = {
{
OnStartRunningUrl() {},
OnStopRunningUrl(url, exitCode) {
SLStatic.debug(
console.debug(
`LegacyColumn.getRawMessage.streamListener.OnStopRunning ` +
`received ${streamListener.inputStream.available()} bytes ` +
`(exitCode: ${exitCode})`
Expand All @@ -58,7 +58,7 @@ var LegacyColumn = {
""
);
}).catch((ex) => {
SLStatic.error(`Error reading message ${messageUri}`,ex);
console.error(`Error reading message ${messageUri}`,ex);
});

const available = streamListener.inputStream.available();
Expand All @@ -69,7 +69,7 @@ var LegacyColumn = {
);
return rawMessage;
} else {
SLStatic.debug(`No data available for message ${messageUri}`);
console.debug(`No data available for message ${messageUri}`);
return null;
}
},
Expand All @@ -93,15 +93,16 @@ var LegacyColumn = {
const msgContentType = this.getStorageLocal(CTPropertyName);
const sendAtStr = hdr.getStringProperty("x-send-later-at");
const msgUuid = hdr.getStringProperty("x-send-later-uuid");
let SLStatic = this.SLStatic;
const incorrectUUIDMsg = this.SLStatic.i18n.getMessage("incorrectUUID");
const encryptionIncompatMsg = this.SLStatic.i18n.getMessage("EncryptionIncompatTitle")
if (!sendAtStr) {
return { valid: false, detail: "Not scheduled" };
} else if (msgUuid !== instanceUUID) {
return { valid: false, detail: `${msgUuid} != ${instanceUUID}`, msg: SLStatic.i18n.getMessage("incorrectUUID") };
return { valid: false, detail: `${msgUuid} != ${instanceUUID}`, msg: incorrectUUIDMsg };
} else if (!msgContentType) {
return { valid: false, detail: "Missing ContentType" };
} else if (/encrypted/i.test(msgContentType)) {
return { valid: false, detail: "Encrypted", msg: SLStatic.i18n.getMessage("EncryptionIncompatTitle") };
return { valid: false, detail: "Encrypted", msg: encryptionIncompatMsg };
}
return { valid: true };
},
Expand Down Expand Up @@ -142,7 +143,7 @@ class MessageViewsCustomColumn {
window.document.getElementById(this.columnId + "-splitter").remove();
window.document.getElementById(this.columnId).remove();
} catch (ex) {
SLStatic.error(ex);
console.error(ex);
}
}

Expand Down Expand Up @@ -190,13 +191,13 @@ class MessageViewsCustomColumn {
}
}
} catch (ex) {
SLStatic.error("Unable to set column visible",ex);
console.error("Unable to set column visible",ex);
}
}

addToWindow(window) {
if (window.document.getElementById(this.columnId)) {
SLStatic.warn("Attempted to add duplicate column", this.columnId);
console.warn("Attempted to add duplicate column", this.columnId);
return;
}
let treecol = window.document.createXULElement("treecol");
Expand Down Expand Up @@ -297,7 +298,7 @@ var columnHandler = class extends ExtensionCommon.ExtensionAPI {
try {
column.destroy();
} catch (ex) {
SLStatic.error("Unable to destroy column:",ex);
console.error("Unable to destroy column:",ex);
}

LegacyColumn = undefined;
Expand Down Expand Up @@ -354,7 +355,7 @@ var columnHandler = class extends ExtensionCommon.ExtensionAPI {
if (column) {
column.setVisible(visible, windowId);
} else {
SLStatic.error("Attempted to update visibility of non-existent column");
console.error("Attempted to update visibility of non-existent column");
}
},
}
Expand Down
11 changes: 10 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

"description": "__MSG_extensionDescription__",

"version": "9.2.2",
"version": "9.2.3",

"homepage_url": "https://github.com/Extended-Thunder/send-later/",

Expand Down Expand Up @@ -93,6 +93,15 @@
"default_title": "__MSG_extensionName__"
},

"browser_action": {
"browser_style": true,
"default_icon": "ui/icons/icon.png",
"default_area": "maintoolbar",
"default_label": "__MSG_extensionName__",
"default_title": "__MSG_extensionName__",
"default_popup": "ui/browserActionPopup.html"
},

"experiment_apis": {
"SL3U": {
"schema": "experiments/sl3u.json",
Expand Down
105 changes: 105 additions & 0 deletions ui/browserActionPopup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body {
font-family: sans-serif;
vertical-align: middle;
padding: 1em 0.5em;
}

.clickable {
background: none!important;
border: none;
padding: 0!important;
color: #069;
text-decoration: underline;
cursor: pointer;
}

button, input[type=button] {
text-align:center;
padding:0.2em;
}

section {
padding: 0.5em 0.25em 0.5em 0em;
}

label {
white-space: nowrap;
}

.div-table {
display: table;
width: auto;
}

.div-table-row {
display: table-row;
width: auto;
clear: both;
}

.div-table-cell {
display: table-cell;
padding: 0 0.2em;
white-space: nowrap;
}

#scheduleTable {
min-height: 5em;
}
</style>
</head>

<body style="padding: 1em;">
<div class="div-table" id="scheduleTable">
<!-- Dynamically populated with active message schedules. -->
</div>

<hr style="margin: 0 auto; width: 70%; color: grey;"/>

<section style="width: 100%;">
<div class="div-table" style="margin: 0 auto;">
<div class="div-table-row">
<div class="div-table-cell" style="text-align: center; padding: 0 0.5em;">
<input type="button"
id="showPrefsButton"
class="clickable localized __MSG_prefwindow.title__"
></input>
</div>
<div class="div-table-cell" style="text-align: center; padding: 0 0.5em;">
<input type="button"
id="showGuideButton"
class="clickable localized __MSG_userGuideLabel__"
></input>
</div>
<div class="div-table-cell" style="text-align: center; padding: 0 0.5em;">
<input type="button"
id="showNotesButton"
class="clickable localized __MSG_releasenotes.value__"
></input>
</div>
<div class="div-table-cell" style="text-align: center; padding: 0 0.5em;">
<input type="button"
id="contactAuthorButton"
class="clickable localized __MSG_contactAuthorLabel__"
></input>
</div>
<div class="div-table-cell" style="text-align: center; padding: 0 0.5em;">
<input type="button"
id="donateButton"
class="clickable localized __MSG_donatelink.value__"
></input>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="/utils/sugar-custom.js"></script>
<script type="text/javascript" src="/utils/static.js"></script>
<script type="text/javascript" src="/ui/localize.js"></script>
<script type="text/javascript" src="/ui/browserActionPopup.js"></script>
</body>
</html>
Loading

0 comments on commit 16ee2d9

Please sign in to comment.