Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thunderbird 78 #647

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# This repository is not maintained.

* Addon for current Thunderbird versions: [Markdown Here Revival](https://addons.thunderbird.net/en-US/thunderbird/addon/markdown-here-revival/)
* Current development: [Gitlab](https://gitlab.com/jfx2006/markdown-here-revival)


# ![Markdown Here logo](https://raw.github.com/adam-p/markdown-here/master/src/common/images/icon48.png) Markdown Here

[**Visit the website.**](http://markdown-here.com)<br>
Expand Down
9 changes: 9 additions & 0 deletions contributors/jfx2006.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
2020-12-31

I hereby agree to the terms of the "Markdown Here Individual Contributor License Agreement", with MD5 checksum 6a31e08cf66139e91c0db5599b6ab084.

I furthermore declare that I am authorized and able to make this agreement and sign this declaration.

Signed,

R Lemley https://github.com/jfx2006
38 changes: 31 additions & 7 deletions src/chrome/backgroundscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ function upgradeCheck() {
});
}

let actionButton

if (messenger === undefined) {
// Running in a browser such as Firefox, Chrome, Safari
// Create the context menu that will signal our main code.
chrome.contextMenus.create({
contexts: ['editable'],
Expand All @@ -59,6 +63,11 @@ chrome.contextMenus.create({
chrome.tabs.sendMessage(tab.id, {action: 'context-click'});
}
});
actionButton = chrome.browserAction
} else {
// Running in a Thunderbird compose window
actionButton = messenger.composeAction
}

// Handle rendering requests from the content script.
// See the comment in markdown-render.js for why we do this.
Expand Down Expand Up @@ -89,11 +98,11 @@ chrome.runtime.onMessage.addListener(function(request, sender, responseCallback)
}
else if (request.action === 'show-toggle-button') {
if (request.show) {
chrome.browserAction.enable(sender.tab.id);
chrome.browserAction.setTitle({
actionButton.enable(sender.tab.id);
actionButton.setTitle({
title: Utils.getMessage('toggle_button_tooltip'),
tabId: sender.tab.id });
chrome.browserAction.setIcon({
actionButton.setIcon({
path: {
"16": Utils.getLocalURL('/common/images/icon16-button-monochrome.png'),
"19": Utils.getLocalURL('/common/images/icon19-button-monochrome.png'),
Expand All @@ -105,11 +114,11 @@ chrome.runtime.onMessage.addListener(function(request, sender, responseCallback)
return false;
}
else {
chrome.browserAction.disable(sender.tab.id);
chrome.browserAction.setTitle({
actionButton.disable(sender.tab.id);
actionButton.setTitle({
title: Utils.getMessage('toggle_button_tooltip_disabled'),
tabId: sender.tab.id });
chrome.browserAction.setIcon({
actionButton.setIcon({
path: {
"16": Utils.getLocalURL('/common/images/icon16-button-disabled.png'),
"19": Utils.getLocalURL('/common/images/icon19-button-disabled.png'),
Expand Down Expand Up @@ -148,10 +157,25 @@ chrome.runtime.onMessage.addListener(function(request, sender, responseCallback)
});

// Add the browserAction (the button in the browser toolbar) listener.
chrome.browserAction.onClicked.addListener(function(tab) {
actionButton.onClicked.addListener(function(tab) {
chrome.tabs.sendMessage(tab.id, {action: 'button-click', });
});

if (messenger !== undefined) {
// Mail Extensions are not able to add composeScripts via manifest.json,
// they must be added via the API.
messenger.composeScripts.register({
"js": [
{file: "../common/utils.js"},
{file: "../common/common-logic.js"},
{file: "../common/jsHtmlToText.js"},
{file: "../common/marked.js"},
{file: "../common/mdh-html-to-text.js"},
{file: "../common/markdown-here.js"},
{file: "contentscript.js"}
]
});
}

/*
Showing an notification after upgrade is complicated by the fact that the
Expand Down
5 changes: 5 additions & 0 deletions src/common/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Change Log
==========

2020-12-31:

* Port Thunderbird support to mail extensions to support Thunderbird 78.5+


2018-09-30: v2.13.4
--------------------

Expand Down
2 changes: 1 addition & 1 deletion src/common/markdown-here.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ function findMarkdownHereWrapper(focusedElem) {
function findMarkdownHereWrappersInRange(range) {
// Adapted from: http://stackoverflow.com/a/1483487/729729
var containerElement = range.commonAncestorContainer;
if (containerElement.nodeType != containerElement.ELEMENT_NODE) {
if (containerElement.nodeType !== containerElement.ELEMENT_NODE) {
containerElement = containerElement.parentNode;
}

Expand Down
2 changes: 0 additions & 2 deletions src/common/options-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

function onLoad() {
/*? if(platform==='safari' || platform==='chrome' || platform==='firefox'){ */
// Chrome/Safari/WebExtensions require us to manually load our content script in order
// to use the button and context menu in the iframe.
if (typeof(safari) !== 'undefined' || typeof(chrome) !== 'undefined') {
Expand All @@ -18,7 +17,6 @@ function onLoad() {
}
document.body.appendChild(contentscript);
}
/*? } */

// The body of the iframe needs to have a (collapsed) selection range for
// Markdown Here to work (simulating focus/cursor).
Expand Down
119 changes: 3 additions & 116 deletions src/common/options-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ var DEFAULTS = {
'gfm-line-breaks-enabled': true
};

/*? if(platform!=='thunderbird'){ */
/*
* Chrome storage helper. Gets around the synchronized value size limit.
* Overall quota limits still apply (or less, but we should stay well within).
Expand Down Expand Up @@ -259,113 +258,6 @@ var ChromeOptionsStore = {
});
}
};
/*? } */

/*? if(platform==='thunderbird'){ */
/*
* Mozilla preferences storage helper
*/

var MozillaOptionsStore = {

get: function(callback) {
var that = this;
this._sendRequest({verb: 'get'}, function(prefsObj) {
that._fillDefaults(prefsObj, callback);
});
},

set: function(obj, callback) {
this._sendRequest({verb: 'set', obj: obj}, callback);
},

remove: function(arrayOfKeys, callback) {
this._sendRequest({verb: 'clear', obj: arrayOfKeys}, callback);
},

// The default values or URLs for our various options.
defaults: {
'local-first-run': true,
'main-css': {'__defaultFromFile__': 'resource://markdown_here_common/default.css', '__mimeType__': 'text/css'},
'syntax-css': {'__defaultFromFile__': 'resource://markdown_here_common/highlightjs/styles/github.css', '__mimeType__': 'text/css'},
'math-enabled': DEFAULTS['math-enabled'],
'math-value': DEFAULTS['math-value'],
'hotkey': DEFAULTS['hotkey'],
'forgot-to-render-check-enabled': DEFAULTS['forgot-to-render-check-enabled'],
'header-anchors-enabled': DEFAULTS['header-anchors-enabled'],
'gfm-line-breaks-enabled': DEFAULTS['gfm-line-breaks-enabled']
},

// This is called both from content and background scripts, and we need vastly
// different code in those cases. When calling from a content script, we need
// to make a request to a background service (found in firefox/chrome/content/background-services.js).
// When called from a background script, we're going to access the browser prefs
// directly. Unfortunately, this means duplicating some code from the background
// service.
_sendRequest: function(data, callback) { // analogue of chrome.runtime.sendMessage
var privileged, prefsBranch, prefKeys, prefsObj, i;

privileged = (typeof(Components) !== 'undefined' && typeof(Components.classes) !== 'undefined');
if (!privileged) {
// This means that this code is being called from a content script.
// We need to send a request from this non-privileged context to the
// privileged background script.
data.action = 'prefs-access';
Utils.makeRequestToPrivilegedScript(
document,
data,
callback);

return;
}

prefsBranch = Components.classes['@mozilla.org/preferences-service;1']
.getService(Components.interfaces.nsIPrefService)
.getBranch('extensions.markdown-here.');

if (data.verb === 'get') {
prefKeys = prefsBranch.getChildList('');
prefsObj = {};

for (i = 0; i < prefKeys.length; i++) {
// All of our legitimate prefs should be strings, but issue #237 suggests
// that things may sometimes get into a bad state. We will check and delete
// and prefs that aren't strings.
// https://github.com/adam-p/markdown-here/issues/237
if (prefsBranch.getPrefType(prefKeys[i]) !== prefsBranch.PREF_STRING) {
prefsBranch.clearUserPref(prefKeys[i]);
continue;
}

prefsObj[prefKeys[i]] = Utils.getMozJsonPref(prefsBranch, prefKeys[i]);
}

callback(prefsObj);
return;
}
else if (data.verb === 'set') {
for (i in data.obj) {
Utils.setMozJsonPref(prefsBranch, i, data.obj[i]);
}

if (callback) callback();
return;
}
else if (data.verb === 'clear') {
if (typeof(data.obj) === 'string') {
data.obj = [data.obj];
}

for (i = 0; i < data.obj.length; i++) {
prefsBranch.clearUserPref(data.obj[i]);
}

if (callback) return callback();
return;
}
}
};
/*? } */


/*? if(platform==='safari'){ */
Expand Down Expand Up @@ -476,10 +368,11 @@ var SafariOptionsStore = {

// Choose which OptionsStore engine we should use.
// (This if-structure is ugly to work around the preprocessor logic.)
/*? if(platform==='chrome' || platform==='firefox'){ */
/*? if(platform==='chrome' || platform==='firefox' || platform==='thunderbird') { */
if (typeof(navigator) !== 'undefined'
&& (navigator.userAgent.indexOf('Chrome') >= 0
|| navigator.userAgent.indexOf('Firefox') >= 0)) {
|| navigator.userAgent.indexOf('Firefox') >= 0
|| navigator.userAgent.indexOf('Thunderbird') >= 0)){
this.OptionsStore = ChromeOptionsStore;
}
/*? } */
Expand All @@ -490,12 +383,6 @@ if (!this.OptionsStore
this.OptionsStore = SafariOptionsStore;
}
/*? } */
/*? if(platform==='thunderbird'){ */
// Thunderbird, Postbox, Icedove
if (!this.OptionsStore) {
this.OptionsStore = MozillaOptionsStore;
}
/*? } */

this.OptionsStore._fillDefaults = function(prefsObj, callback) {
var that = this;
Expand Down
11 changes: 0 additions & 11 deletions src/common/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,6 @@ function onLoad() {
}
});

// Older Thunderbird may try to open this options page in a new ChromeWindow, and it
// won't work. So in that case we need to tell the user how they can actually open the
// options page. This is pretty ungraceful, but few users will encouter it, and fewer as
// time goes on.
setTimeout(function() {
if (!optionsGetSuccessful) {
alert('It looks like you are running an older version of Thunderird.\nOpen the Markdown Here Options via the message window Tools menu.');
window.close();
}
}, 500);

loaded = true;
}
document.addEventListener('DOMContentLoaded', onLoad, false);
Expand Down
Loading