Only open the extension page when the version gets updated.
Firefox "reinstalls" extensions when it gets updated so we have to work around it so we only open the extension when the version actually changes.
This commit is contained in:
parent
013bd6a2e3
commit
47e306dcdb
|
@ -1,10 +1,32 @@
|
|||
import {browser} from 'webextension-polyfill-ts';
|
||||
import {
|
||||
defaultSettings,
|
||||
getManifest,
|
||||
getSettings,
|
||||
setSettings,
|
||||
versionAsNumber
|
||||
} from '.';
|
||||
|
||||
// Add listeners to open the options page when:
|
||||
// * The extension icon is clicked.
|
||||
// * The extension is installed.
|
||||
browser.browserAction.onClicked.addListener(openOptionsPage);
|
||||
browser.runtime.onInstalled.addListener(openOptionsPage);
|
||||
browser.runtime.onInstalled.addListener(async () => {
|
||||
const manifest = getManifest();
|
||||
const settings = await getSettings();
|
||||
const versionGotUpdated =
|
||||
versionAsNumber(manifest.version) >
|
||||
versionAsNumber(settings.data.version ?? defaultSettings.data.version!);
|
||||
|
||||
if (versionGotUpdated) {
|
||||
settings.data.version = manifest.version;
|
||||
await setSettings(settings);
|
||||
}
|
||||
|
||||
if (versionGotUpdated || manifest.nodeEnv === 'development') {
|
||||
await openOptionsPage();
|
||||
}
|
||||
});
|
||||
|
||||
async function openOptionsPage() {
|
||||
await browser.runtime.openOptionsPage();
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"manifest_version": 2,
|
||||
"name": "Tildes ReExtended",
|
||||
"description": "An updated and reimagined recreation of Tildes Extended to enhance and improve the experience of Tildes.net.",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"permissions": [
|
||||
"downloads",
|
||||
"storage",
|
||||
|
|
|
@ -56,7 +56,8 @@ export const defaultSettings: Settings = {
|
|||
'~tv'
|
||||
],
|
||||
latestActiveFeatureTab: 'debug',
|
||||
userLabels: []
|
||||
userLabels: [],
|
||||
version: '0.0.0'
|
||||
},
|
||||
features: {
|
||||
autocomplete: true,
|
||||
|
|
|
@ -51,11 +51,13 @@ export async function getSettings(): Promise<Settings> {
|
|||
features: {...defaultSettings.features, ...syncSettings.features}
|
||||
};
|
||||
|
||||
if (window?.TildesReExtended !== undefined) {
|
||||
window.TildesReExtended.debug = settings.features.debug;
|
||||
// If we're in development, force debug output.
|
||||
if (getManifest().nodeEnv === 'development') {
|
||||
window.TildesReExtended.debug = true;
|
||||
}
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
|
|
@ -48,3 +48,4 @@ export * from './groups';
|
|||
export * from './query-selectors';
|
||||
export * from './report-a-bug';
|
||||
export * from './validators';
|
||||
export * from './version';
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
/**
|
||||
* Returns a version string as a number by removing the periods.
|
||||
* @param version
|
||||
*/
|
||||
export function versionAsNumber(version: string): number {
|
||||
return Number(version.replace(/\./g, ''));
|
||||
}
|
Loading…
Reference in New Issue