From 783b16220da2b8c3e1588bfae6e4018388aeebe4 Mon Sep 17 00:00:00 2001 From: Musa Ahmed Date: Thu, 18 Jan 2024 15:31:51 -0500 Subject: [PATCH 1/2] Added option to handle file links --- src/services/window-service.ts | 96 ++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/src/services/window-service.ts b/src/services/window-service.ts index 14f2339..0269b9d 100644 --- a/src/services/window-service.ts +++ b/src/services/window-service.ts @@ -1,54 +1,62 @@ import * as browser from "webextension-polyfill"; class WindowService { - /** - * Get a list of all currently open, regular windows - */ - static getAllWindows(): Promise { - return new Promise((resolve, reject) => { - browser.windows - .getAll({ windowTypes: ["normal"] }) - .then(resolve) - .catch(reject); - }); - } + /** + * Get a list of all currently open, regular windows + */ + static getAllWindows(): Promise { + return new Promise((resolve, reject) => { + browser.windows + .getAll({ windowTypes: ["normal"] }) + .then(resolve) + .catch(reject); + }); + } - /** - * Get the currently focused window - */ - static getCurrentWindow(): Promise { - return new Promise((resolve, reject) => { - browser.windows - .getCurrent({ populate: true }) - .then(resolve) - .catch(reject); - }); - } + /** + * Get the currently focused window + */ + static getCurrentWindow(): Promise { + return new Promise((resolve, reject) => { + browser.windows + .getCurrent({ populate: true }) + .then(resolve) + .catch(reject); + }); + } - /** - * Create a new window with tabs for the specified list of urls - */ - static createWindow(urls: string[]): Promise { - return new Promise((resolve, reject) => { - const payload = { - url: urls, - }; + /** + * Create a new window with tabs for the specified list of urls + */ + static createWindow(urls: string[]): Promise { + return new Promise((resolve, reject) => { + let sanitized = urls.map((url) => { + if (url.startsWith("file")) { + url = url.replace("file://", ""); + return `http://localhost:3000/?path=${url}`; + } + return url; + }); - browser.windows.create(payload).then(resolve).catch(reject); - }); - } + const payload = { + url: sanitized, + }; - /** - * Close the specified window - */ - static closeWindow(id: number): Promise { - return new Promise((resolve, reject) => { - browser.windows - .remove(id) - .then(() => resolve(undefined)) - .catch(reject); - }); - } + browser.windows.create(payload).then(resolve).catch(reject); + }); + } + + /** + * Close the specified window + */ + static closeWindow(id: number): Promise { + return new Promise((resolve, reject) => { + browser.windows + .remove(id) + .then(() => resolve(undefined)) + .catch(reject); + }); + } } export default WindowService; From 679c50eb8afaaca1a2edee02051563aa1cc068be Mon Sep 17 00:00:00 2001 From: Musa Ahmed Date: Thu, 18 Jan 2024 15:36:23 -0500 Subject: [PATCH 2/2] fixed spacing --- src/services/window-service.ts | 102 ++++++++++++++++----------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/services/window-service.ts b/src/services/window-service.ts index 0269b9d..3d7f6b2 100644 --- a/src/services/window-service.ts +++ b/src/services/window-service.ts @@ -1,62 +1,62 @@ import * as browser from "webextension-polyfill"; class WindowService { - /** - * Get a list of all currently open, regular windows - */ - static getAllWindows(): Promise { - return new Promise((resolve, reject) => { - browser.windows - .getAll({ windowTypes: ["normal"] }) - .then(resolve) - .catch(reject); - }); - } + /** + * Get a list of all currently open, regular windows + */ + static getAllWindows(): Promise { + return new Promise((resolve, reject) => { + browser.windows + .getAll({ windowTypes: ["normal"] }) + .then(resolve) + .catch(reject); + }); + } + + /** + * Get the currently focused window + */ + static getCurrentWindow(): Promise { + return new Promise((resolve, reject) => { + browser.windows + .getCurrent({ populate: true }) + .then(resolve) + .catch(reject); + }); + } - /** - * Get the currently focused window - */ - static getCurrentWindow(): Promise { - return new Promise((resolve, reject) => { - browser.windows - .getCurrent({ populate: true }) - .then(resolve) - .catch(reject); + /** + * Create a new window with tabs for the specified list of urls + */ + static createWindow(urls: string[]): Promise { + return new Promise((resolve, reject) => { + let sanitized = urls.map((url) => { + if (url.startsWith("file")) { + url = url.replace("file://", ""); + return `http://localhost:3000/?path=${url}`; + } + return url; }); - } - /** - * Create a new window with tabs for the specified list of urls - */ - static createWindow(urls: string[]): Promise { - return new Promise((resolve, reject) => { - let sanitized = urls.map((url) => { - if (url.startsWith("file")) { - url = url.replace("file://", ""); - return `http://localhost:3000/?path=${url}`; - } - return url; - }); + const payload = { + url: sanitized, + }; - const payload = { - url: sanitized, - }; + browser.windows.create(payload).then(resolve).catch(reject); + }); + } - browser.windows.create(payload).then(resolve).catch(reject); - }); - } - - /** - * Close the specified window - */ - static closeWindow(id: number): Promise { - return new Promise((resolve, reject) => { - browser.windows - .remove(id) - .then(() => resolve(undefined)) - .catch(reject); - }); - } + /** + * Close the specified window + */ + static closeWindow(id: number): Promise { + return new Promise((resolve, reject) => { + browser.windows + .remove(id) + .then(() => resolve(undefined)) + .catch(reject); + }); + } } export default WindowService;