Skip to content

Commit 1f6999c

Browse files
fix StartupService to work always
1 parent 041dbfa commit 1f6999c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/lib/StartupService.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export class StartupService {
3838
return this.INSTANCE;
3939
}
4040

41+
private _initialized = false;
42+
4143
/**
4244
* For important initializations.
4345
*/
@@ -48,12 +50,26 @@ export class StartupService {
4850
*/
4951
public readonly onStartup = new EventSink<browser.Runtime.OnInstalledDetailsType>();
5052

53+
private callHandlers(details: browser.Runtime.OnInstalledDetailsType) {
54+
if (this._initialized) return;
55+
this._initialized = true;
56+
this.onBeforeStartup.dispatch();
57+
this.onStartup.dispatch(details);
58+
}
59+
5160
private constructor() {
5261
if (extensionService.isBackgroundPage()) {
5362
Asserts.assertTopLevel();
5463
browser.runtime.onInstalled.addListener((details) => {
55-
this.onBeforeStartup.dispatch();
56-
this.onStartup.dispatch(details);
64+
this.callHandlers(details);
65+
});
66+
browser.runtime.onStartup.addListener(() => {
67+
const details: browser.Runtime.OnInstalledDetailsType = {
68+
reason: 'install',
69+
previousVersion: browser.runtime.getManifest().version,
70+
temporary: false,
71+
};
72+
this.callHandlers(details);
5773
});
5874
}
5975
}

0 commit comments

Comments
 (0)