Skip to content

Commit

Permalink
chore: lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelgomesxyz committed Mar 7, 2023
1 parent 840f5bb commit ab3d2de
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
17 changes: 9 additions & 8 deletions src/common/Messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class _Messaging {

init() {
if (Shared.pageType === 'content') {
this.toExtension({ action: 'connect-content-script' });
void this.toExtension({ action: 'connect-content-script' });
}
}

Expand All @@ -187,16 +187,17 @@ class _Messaging {

async connectContentScript(message: ConnectContentScriptMessage, tabId: number | null) {
if (tabId !== null) {
void Shared.events.dispatch('CONTENT_SCRIPT_CONNECT', null, { tabId });
await Shared.events.dispatch('CONTENT_SCRIPT_CONNECT', null, { tabId });
}
}

private onTabRemoved = async (tabId: number) => {
const values = await SessionStorage.get('injectedContentScriptTabs');
const injectedContentScriptTabs = new Set(values.injectedContentScriptTabs ?? []);
if (injectedContentScriptTabs.has(tabId)) {
void Shared.events.dispatch('CONTENT_SCRIPT_DISCONNECT', null, { tabId });
}
private onTabRemoved = (tabId: number) => {
void SessionStorage.get('injectedContentScriptTabs').then((values) => {
const injectedContentScriptTabs = new Set(values.injectedContentScriptTabs ?? []);
if (injectedContentScriptTabs.has(tabId)) {
void Shared.events.dispatch('CONTENT_SCRIPT_DISCONNECT', null, { tabId });
}
});
};

private onMessage = <T extends MessageRequest>(
Expand Down
14 changes: 7 additions & 7 deletions src/common/ScriptInjector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ class _ScriptInjector {
const id = `${serviceId}-${key}`;

if (Shared.manifestVersion === 3 && tabId !== null) {
browser.scripting
void browser.scripting
.executeScript({
target: { tabId },
func: Shared.functionsToInject[id],
args: [params],
})
.then((results) => {
const value = results[0].result;
resolve(value as T | null);
const value = results[0].result as T | null;
resolve(value);
});
return;
}
Expand All @@ -226,15 +226,15 @@ class _ScriptInjector {
func: Shared.functionsToInject[id],
args: [params],
});
value = results[0].result;
value = results[0].result as T | null;
} else {
value = await Messaging.toContent(
value = (await Messaging.toContent(
{ action: 'inject-function', serviceId, key, url, params },
tabId
);
)) as T | null;
}
void browser.tabs.remove(tabId);
resolve(value as T | null);
resolve(value);

Shared.events.unsubscribe('CONTENT_SCRIPT_CONNECT', null, onScriptConnect);
};
Expand Down
9 changes: 6 additions & 3 deletions src/common/SessionStorage.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import browser from 'webextension-polyfill';
import browser, { Storage as WebExtStorage } from 'webextension-polyfill';
import { Shared } from '@common/Shared';

export interface SessionStorageValues {
injectedContentScriptTabs?: number[];
}

class _SessionStorage {
// @ts-expect-error `session` is a newer key, so it's missing from the types.
instance = Shared.manifestVersion === 3 ? browser.storage.session : browser.storage.local;
instance =
Shared.manifestVersion === 3
? // @ts-expect-error `session` is a newer key, so it's missing from the types.
(browser.storage.session as WebExtStorage.LocalStorageArea)
: browser.storage.local;

async set(values: SessionStorageValues): Promise<void> {
return this.instance.set(values);
Expand Down

0 comments on commit ab3d2de

Please sign in to comment.