aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-16 10:22:24 -0500
committerGitHub <noreply@github.com>2021-01-16 10:22:24 -0500
commit8766744aa4a94193dd03bba39086e4522914e8ef (patch)
treebfb4a15e264c1fa4f9740bbd763a255e164a51e1 /ext/bg/js/backend.js
parentdc4d659184a61a55083e201438bff7732acece1b (diff)
Popup window options (#1245)
* Add popupWindow options * Add toBoolean converter * Add settings * Use new options * Add test link * Fix window state not working * Make the window section advanced only
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js71
1 files changed, 52 insertions, 19 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 11a17381..d5e5b086 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -818,25 +818,12 @@ class Backend {
// Create a new window
const options = this.getOptions({current: true});
- const {popupWidth, popupHeight} = options.general;
- const popupWindow = await new Promise((resolve, reject) => {
- chrome.windows.create(
- {
- url: baseUrl,
- width: popupWidth,
- height: popupHeight,
- type: 'popup'
- },
- (result) => {
- const error = chrome.runtime.lastError;
- if (error) {
- reject(new Error(error.message));
- } else {
- resolve(result);
- }
- }
- );
- });
+ const createData = this._getSearchPopupWindowCreateData(baseUrl, options);
+ const {popupWindow: {windowState}} = options;
+ const popupWindow = await this._createWindow(createData);
+ if (windowState !== 'normal') {
+ await this._updateWindow(popupWindow.id, {state: windowState});
+ }
const {tabs} = popupWindow;
if (tabs.length === 0) {
@@ -856,6 +843,52 @@ class Backend {
return {tab, created: true};
}
+ _getSearchPopupWindowCreateData(url, options) {
+ const {popupWindow: {width, height, left, top, useLeft, useTop, windowType}} = options;
+ return {
+ url,
+ width,
+ height,
+ left: useLeft ? left : void 0,
+ top: useTop ? top : void 0,
+ type: windowType,
+ state: 'normal'
+ };
+ }
+
+ _createWindow(createData) {
+ return new Promise((resolve, reject) => {
+ chrome.windows.create(
+ createData,
+ (result) => {
+ const error = chrome.runtime.lastError;
+ if (error) {
+ reject(new Error(error.message));
+ } else {
+ resolve(result);
+ }
+ }
+ );
+ });
+ }
+
+ _updateWindow(windowId, updateInfo) {
+ return new Promise((resolve, reject) => {
+ chrome.windows.update(
+ windowId,
+ updateInfo,
+ (result) => {
+ const error = chrome.runtime.lastError;
+ if (error) {
+ reject(new Error(error.message));
+ } else {
+ resolve(result);
+ }
+ }
+ );
+ });
+ }
+
_updateSearchQuery(tabId, text, animate) {
return this._sendMessageTabPromise(
tabId,