Skip to content

Commit e66cbde

Browse files
authored
Merge pull request #15 from OneNoteDev/feature/reimplement-oninstalled-for-firefox
Reimplement Firefox onInstall logic
2 parents 1dd5bdf + 595885d commit e66cbde

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/scripts/extensions/webExtensionBase/webExtension.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ export class WebExtension extends ExtensionBase<WebExtensionWorker, W3CTab, numb
7474
}
7575

7676
protected onFirstRun() {
77-
// Don't do anything since we're using the onInstalled functionality instead
77+
// Don't do anything since we're using the onInstalled functionality instead, unless it's not available
78+
// then we use our 'missing-clipperId' heuristic
79+
if (!this.onInstalledSupported()) {
80+
this.onInstalled();
81+
}
7882
}
7983

8084
protected checkIfTabMatchesATooltipType(tab: W3CTab, tooltipType: TooltipType): boolean {
@@ -158,7 +162,7 @@ export class WebExtension extends ExtensionBase<WebExtensionWorker, W3CTab, numb
158162

159163
private registerInstallListener() {
160164
// onInstalled is undefined as of Firefox 48
161-
if (WebExtension.browser.runtime.onInstalled) {
165+
if (this.onInstalledSupported()) {
162166
WebExtension.browser.runtime.onInstalled.addListener(details => {
163167
if (details.reason === "install") {
164168
this.onInstalled();
@@ -175,4 +179,8 @@ export class WebExtension extends ExtensionBase<WebExtensionWorker, W3CTab, numb
175179
}
176180
});
177181
}
182+
183+
private onInstalledSupported(): boolean {
184+
return !!WebExtension.browser.runtime.onInstalled;
185+
}
178186
}

0 commit comments

Comments
 (0)