Skip to content

Commit

Permalink
fix: deprecated apis MV3 (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
ueokande authored Mar 16, 2023
1 parent 36164c3 commit 8e267a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 58 deletions.
28 changes: 0 additions & 28 deletions src/background/presenters/Notifier.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { injectable } from "inversify";

const NOTIFICATION_ID_UPDATE = "vimmatic-update";
const NOTIFICATION_ID_INVALID_SETTINGS = "vimmatic-update-invalid-settings";

export default interface Notifier {
notifyUpdated(version: string, onclick: () => void): Promise<void>;

notifyInvalidSettings(error: Error, onclick: () => void): Promise<void>;
}

@injectable()
Expand All @@ -31,29 +28,4 @@ export class NotifierImpl implements NotifierImpl {
message,
});
}

async notifyInvalidSettings(
error: Error,
onclick: () => void
): Promise<void> {
const title = `Loading settings failed`;
// eslint-disable-next-line max-len
const message = `The default settings are used due to the last saved settings is invalid. Check your current settings from the add-on preference: ${error.message}`;

const listener = (id: string) => {
if (id !== NOTIFICATION_ID_INVALID_SETTINGS) {
return;
}
onclick();
chrome.notifications.onClicked.removeListener(listener);
};
chrome.notifications.onClicked.addListener(listener);

chrome.notifications.create(NOTIFICATION_ID_INVALID_SETTINGS, {
type: "basic",
iconUrl: chrome.extension.getURL("resources/icon_48x48.png"),
title,
message,
});
}
}
34 changes: 4 additions & 30 deletions src/background/presenters/ToolbarPresenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,13 @@ export default interface ToolbarPresenter {
export class ToolbarPresenterImpl {
async setEnabled(enabled: boolean): Promise<void> {
const path = enabled
? "resources/enabled_32x32.png"
: "resources/disabled_32x32.png";
? "../resources/enabled_32x32.png"
: "../resources/disabled_32x32.png";

// chrome.action is supported on v3 api
if (
typeof chrome.action !== "undefined" &&
typeof chrome.action.setIcon === "function"
) {
return chrome.action.setIcon({ path });
}

// firefox does not support chrome.action
if (
typeof chrome.browserAction !== "undefined" &&
typeof chrome.browserAction.setIcon === "function"
) {
// v2 api on chromium requires callback on the 2nd argument
return new Promise((resolve) =>
chrome.browserAction.setIcon({ path }, resolve)
);
}
return chrome.action.setIcon({ path });
}

onClick(listener: (arg: chrome.tabs.Tab) => void): void {
// chrome.action is supported on v3 api
if (typeof chrome.action !== "undefined") {
chrome.action.onClicked.addListener(listener);
return;
}

// firefox does not support chrome.action
if (typeof chrome.browserAction !== "undefined") {
chrome.action.onClicked.addListener(listener);
}
chrome.action.onClicked.addListener(listener);
}
}

0 comments on commit 8e267a7

Please # to comment.