Skip to content

Commit

Permalink
Added basic Thunderbird support
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Reimer committed Oct 8, 2015
1 parent d9b3a1d commit 7501447
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
9 changes: 9 additions & 0 deletions platform/firefox/install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,14 @@
<maxVersion>9.9</maxVersion>
</r:Description>
</targetApplication>

<!-- Thunderbird -->
<targetApplication>
<r:Description>
<id>{{3550f703-e582-4d05-9a08-453d09bdfdc6}}</id>
<minVersion>38.3</minVersion>
<maxVersion>45.0</maxVersion>
</r:Description>
</targetApplication>
</r:Description>
</r:RDF>
26 changes: 22 additions & 4 deletions platform/firefox/vapi-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const {Services} = Cu.import('resource://gre/modules/Services.jsm', null);
var vAPI = self.vAPI = self.vAPI || {};
vAPI.firefox = true;
vAPI.fennec = Services.appinfo.ID === '{aa3c5121-dab2-40e2-81ca-7ea25febc110}';
vAPI.thunderbird = Services.appinfo.ID === '{3550f703-e582-4d05-9a08-453d09bdfdc6}';

/******************************************************************************/

Expand Down Expand Up @@ -524,7 +525,10 @@ vAPI.storage = (function() {
/******************************************************************************/

var getTabBrowser = function(win) {
return vAPI.fennec && win.BrowserApp || win.gBrowser || null;
return vAPI.fennec && win.BrowserApp ||
vAPI.thunderbird && win.document.getElementById('tabmail') ||
win.gBrowser ||
null;
};

/******************************************************************************/
Expand Down Expand Up @@ -729,7 +733,7 @@ vAPI.tabs.open = function(details) {
}
}

var win = Services.wm.getMostRecentWindow('navigator:browser');
var win = Services.wm.getMostRecentWindow(vAPI.thunderbird && 'mail:3pane' || 'navigator:browser');
var tabBrowser = getTabBrowser(win);

if ( vAPI.fennec ) {
Expand All @@ -750,6 +754,12 @@ vAPI.tabs.open = function(details) {
return;
}

if ( vAPI.thunderbird ) {
tabBrowser.openTab('contentTab', { contentPage: details.url, background: !details.active });
// TODO: Should be possible to move tabs on Thunderbird
return;
}

if ( details.index === -1 ) {
details.index = tabBrowser.browsers.indexOf(tabBrowser.selectedBrowser) + 1;
}
Expand Down Expand Up @@ -876,6 +886,9 @@ var tabWatcher = (function() {
var tabIdGenerator = 1;

var indexFromBrowser = function(browser) {
if (vAPI.thunderbird) // TODO: Add support for this
return -1;

var win = getOwnerWindow(browser);
if ( !win ) {
return -1;
Expand Down Expand Up @@ -966,13 +979,18 @@ var tabWatcher = (function() {
};

var currentBrowser = function() {
var win = Services.wm.getMostRecentWindow('navigator:browser');
var win = Services.wm.getMostRecentWindow(vAPI.thunderbird && 'mail:3pane' || 'navigator:browser');
// https://github.com/gorhill/uBlock/issues/399
// getTabBrowser() can return null at browser launch time.
var tabBrowser = getTabBrowser(win);
if ( tabBrowser === null ) {
return null;
}
if (vAPI.thunderbird) {
// Directly at startup the first tab may not be initialized
if (tabBrowser.tabInfo.length == 0) return null;
return tabBrowser.getBrowserForSelectedTab();
}
return browserFromTarget(tabBrowser.selectedTab);
};

Expand Down Expand Up @@ -1186,7 +1204,7 @@ vAPI.setIcon = function(tabId, iconStatus, badge) {
// If badge is undefined, then setIcon was called from the TabSelect event
var win = badge === undefined
? iconStatus
: Services.wm.getMostRecentWindow('navigator:browser');
: vAPI.thunderbird && Services.wm.getMostRecentWindow('mail:3pane') || Services.wm.getMostRecentWindow('navigator:browser');
var curTabId = tabWatcher.tabIdFromTarget(getTabBrowser(win).selectedTab);
var tb = vAPI.toolbarButton;

Expand Down

0 comments on commit 7501447

Please sign in to comment.