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 {browser} from 'webextension-polyfill-ts';
|
||||||
|
import {
|
||||||
|
defaultSettings,
|
||||||
|
getManifest,
|
||||||
|
getSettings,
|
||||||
|
setSettings,
|
||||||
|
versionAsNumber
|
||||||
|
} from '.';
|
||||||
|
|
||||||
// Add listeners to open the options page when:
|
// Add listeners to open the options page when:
|
||||||
// * The extension icon is clicked.
|
// * The extension icon is clicked.
|
||||||
// * The extension is installed.
|
// * The extension is installed.
|
||||||
browser.browserAction.onClicked.addListener(openOptionsPage);
|
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() {
|
async function openOptionsPage() {
|
||||||
await browser.runtime.openOptionsPage();
|
await browser.runtime.openOptionsPage();
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Tildes ReExtended",
|
"name": "Tildes ReExtended",
|
||||||
"description": "An updated and reimagined recreation of Tildes Extended to enhance and improve the experience of Tildes.net.",
|
"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": [
|
"permissions": [
|
||||||
"downloads",
|
"downloads",
|
||||||
"storage",
|
"storage",
|
||||||
|
|
|
@ -56,7 +56,8 @@ export const defaultSettings: Settings = {
|
||||||
'~tv'
|
'~tv'
|
||||||
],
|
],
|
||||||
latestActiveFeatureTab: 'debug',
|
latestActiveFeatureTab: 'debug',
|
||||||
userLabels: []
|
userLabels: [],
|
||||||
|
version: '0.0.0'
|
||||||
},
|
},
|
||||||
features: {
|
features: {
|
||||||
autocomplete: true,
|
autocomplete: true,
|
||||||
|
|
|
@ -51,10 +51,12 @@ export async function getSettings(): Promise<Settings> {
|
||||||
features: {...defaultSettings.features, ...syncSettings.features}
|
features: {...defaultSettings.features, ...syncSettings.features}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.TildesReExtended.debug = settings.features.debug;
|
if (window?.TildesReExtended !== undefined) {
|
||||||
// If we're in development, force debug output.
|
window.TildesReExtended.debug = settings.features.debug;
|
||||||
if (getManifest().nodeEnv === 'development') {
|
// If we're in development, force debug output.
|
||||||
window.TildesReExtended.debug = true;
|
if (getManifest().nodeEnv === 'development') {
|
||||||
|
window.TildesReExtended.debug = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return settings;
|
return settings;
|
||||||
|
|
|
@ -48,3 +48,4 @@ export * from './groups';
|
||||||
export * from './query-selectors';
|
export * from './query-selectors';
|
||||||
export * from './report-a-bug';
|
export * from './report-a-bug';
|
||||||
export * from './validators';
|
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