Convert switchTo to use promises
This commit is contained in:
parent
c6318cb8db
commit
c60f3d0f4f
|
@ -1,3 +1,5 @@
|
||||||
|
import * as util from "./util";
|
||||||
|
|
||||||
let windowCache: chrome.windows.Window[] = [];
|
let windowCache: chrome.windows.Window[] = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,12 +20,19 @@ export function getWindows(callback: (windows: chrome.windows.Window[]) => void)
|
||||||
*
|
*
|
||||||
* @param {number} windowID the tab in which the window is contained.
|
* @param {number} windowID the tab in which the window is contained.
|
||||||
* @param {number} tabID The tab to switch to.
|
* @param {number} tabID The tab to switch to.
|
||||||
* @returns {void}
|
* @returns {PromiseLike<chrome.tabs.Tab>}
|
||||||
*/
|
*/
|
||||||
export function switchTo(windowID: number, tabID: number): void {
|
export function switchTo(windowID: number, tabID: number): PromiseLike<chrome.tabs.Tab> {
|
||||||
chrome.windows.update(windowID, {focused: true}, () => {
|
let curriedWindowUpdate = (windowID: number, options: object) => {
|
||||||
chrome.tabs.update(tabID, {active: true});
|
return (callback: ((win: chrome.windows.Window) => void)) => chrome.windows.update(windowID, options, callback);
|
||||||
});
|
};
|
||||||
|
let curriedTabUpdate = (tabID: number, options: object) => {
|
||||||
|
return (callback: (tab: chrome.tabs.Tab) => void) => chrome.tabs.update(tabID, options, callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
return util.callbackToPromise(curriedWindowUpdate(windowID, {focused: true}))
|
||||||
|
.then((returns: chrome.windows.Window[]) => util.callbackToPromise(curriedTabUpdate(tabID, {active: true})))
|
||||||
|
.then((returns: chrome.tabs.Tab[]) => returns[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue