-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #255 from cowlicks/esm-modules
WIP: Switch from commonjs to ESM
- Loading branch information
Showing
62 changed files
with
840 additions
and
687 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
"use strict"; | ||
|
||
/** | ||
* Simple commonjs-like module system that is compatible with node. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import {activeIcons, inactiveIcons} from './constants.js'; | ||
|
||
import {shim} from './shim.js'; | ||
const {tabsQuery, tabsGet, setIcon, setBadgeText} = shim; | ||
|
||
|
||
async function currentTab() { | ||
const active = true, lastFocusedWindow = true; | ||
return new Promise(resolve => { | ||
tabsQuery({active, lastFocusedWindow}, tabsFirstTry => { | ||
if (tabsFirstTry.length > 0) { | ||
resolve(tabsFirstTry[0]); | ||
} else { // tab not focused | ||
tabsQuery({active}, tabsSecondTry => { | ||
resolve(tabsSecondTry[0]); | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
function errorOccurred(cb = ()=>{}) { | ||
if (typeof chrome !== 'undefined' && chrome.runtime.lastError) { | ||
cb(chrome.runtime.lastError); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
async function tabExists(tabId) { | ||
if (tabId >= 0) { | ||
return await new Promise(resolve => { | ||
tabsGet(tabId, () => { | ||
if (!errorOccurred()) { | ||
resolve(true); | ||
} else { | ||
resolve(false); | ||
} | ||
}); | ||
}); | ||
} else { | ||
return true; | ||
} | ||
} | ||
|
||
// todo after setIcon return's a promise, make this return a promise | ||
async function setTabIconActive(tabId, active) { | ||
if (await tabExists(tabId)) { | ||
let icons = active ? activeIcons : inactiveIcons; | ||
setIcon({tabId: tabId, path: icons}); | ||
} | ||
} | ||
|
||
async function safeSetBadgeText(tabId, text) { | ||
if (await tabExists(tabId)) { | ||
setBadgeText({text, tabId}); | ||
} | ||
} | ||
|
||
export { | ||
currentTab, | ||
errorOccurred, | ||
tabExists, | ||
setTabIconActive, | ||
safeSetBadgeText, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
"use strict"; | ||
|
||
let query_param, | ||
tcos_with_destination, | ||
fixes = {}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.