Defer showing changelog untill browser restart. Make changelog easier to identify with the extension (better title, logo) (#1233)

* Deferr showing changelog untill browser restart.

Make changelog easier to identify with the extension (better title, logo)

* Deferr showing changelog untill browser restart.

Make changelog easier to identify with the extension (better title, logo)
This commit is contained in:
Dmitrii Selivanov authored and GitHub committed 2025-10-24 15:31:55 +02:00
1 parent 00242eaef0
commit 590a764bd6
25 files changed
+246 -4

No files matched your search

+102 -3
View File
@@ -5,6 +5,7 @@ const voteDisabledIconName = config.voteDisabledIconName;
const defaultIconName = config.defaultIconName;
let api;
const CHANGELOG_STORAGE_KEY = "lastShownChangelogVersion";
const PENDING_CHANGELOG_STORAGE_KEY = "pendingChangelogVersion";
/** stores extension's global config */
let extConfig = { ...config.defaultExtConfig };
@@ -251,9 +252,76 @@ function openChangelogTab(version) {
}
}
function scheduleChangelogVersion(version) {
const storage = api?.storage?.local;
if (!storage || typeof storage.set !== "function") {
return false;
}
try {
const valueToStore = version || true;
storage.set({ [PENDING_CHANGELOG_STORAGE_KEY]: valueToStore }, () => {
if (api.runtime.lastError) {
console.debug("Failed to persist pending changelog version:", api.runtime.lastError.message);
}
});
return true;
} catch (error) {
console.debug("Storage set failed for pending changelog version", error);
return false;
}
}
function clearPendingChangelogVersion() {
const storage = api?.storage?.local;
if (!storage || typeof storage.remove !== "function") {
return;
}
try {
storage.remove(PENDING_CHANGELOG_STORAGE_KEY, () => {
if (api.runtime.lastError) {
console.debug("Failed to clear pending changelog version:", api.runtime.lastError.message);
}
});
} catch (error) {
console.debug("Storage remove failed for pending changelog version", error);
}
}
function showPendingChangelogIfNeeded() {
const storage = api?.storage?.local;
if (!storage || typeof storage.get !== "function") {
return;
}
try {
storage.get([PENDING_CHANGELOG_STORAGE_KEY, CHANGELOG_STORAGE_KEY], (result) => {
if (api.runtime.lastError) {
console.debug("Changelog storage read failed:", api.runtime.lastError.message);
return;
}
const pendingValue = result?.[PENDING_CHANGELOG_STORAGE_KEY];
if (pendingValue === undefined || pendingValue === null || pendingValue === "") {
return;
}
const lastShownValue = result?.[CHANGELOG_STORAGE_KEY];
if (lastShownValue !== undefined && lastShownValue !== null && lastShownValue !== "") {
clearPendingChangelogVersion();
return;
}
openChangelogTab(typeof pendingValue === "string" ? pendingValue : null);
});
} catch (error) {
console.debug("Storage get failed for pending changelog version", error);
}
}
function persistChangelogVersion(version) {
const storage = api?.storage?.local;
if (!storage || typeof storage.set !== "function") {
clearPendingChangelogVersion();
return;
}
try {
@@ -261,7 +329,9 @@ function persistChangelogVersion(version) {
storage.set({ [CHANGELOG_STORAGE_KEY]: valueToStore }, () => {
if (api.runtime.lastError) {
console.debug("Failed to persist changelog version:", api.runtime.lastError.message);
return;
}
clearPendingChangelogVersion();
});
} catch (error) {
console.debug("Storage set failed for changelog version", error);
@@ -285,6 +355,7 @@ function maybeShowChangelog(details) {
const manifest = api.runtime.getManifest();
const currentVersion = manifest?.version;
const storage = api?.storage?.local;
const isInstall = reason === "install";
const showChangelog = () => {
openChangelogTab(currentVersion || null);
@@ -296,19 +367,41 @@ function maybeShowChangelog(details) {
}
try {
storage.get(CHANGELOG_STORAGE_KEY, (result) => {
storage.get([CHANGELOG_STORAGE_KEY, PENDING_CHANGELOG_STORAGE_KEY], (result) => {
if (api.runtime.lastError) {
console.debug("Changelog storage read failed:", api.runtime.lastError.message);
showChangelog();
return;
}
const hasStoredValue = (value) => value !== undefined && value !== null && value !== "";
const lastShownValue = result?.[CHANGELOG_STORAGE_KEY];
if (lastShownValue !== undefined && lastShownValue !== null && lastShownValue !== "") {
const pendingValue = result?.[PENDING_CHANGELOG_STORAGE_KEY];
if (isInstall) {
if (hasStoredValue(pendingValue)) {
clearPendingChangelogVersion();
}
if (!hasStoredValue(lastShownValue)) {
showChangelog();
}
return;
}
showChangelog();
if (hasStoredValue(lastShownValue)) {
return;
}
if (hasStoredValue(pendingValue)) {
if (currentVersion && pendingValue !== currentVersion) {
scheduleChangelogVersion(currentVersion);
}
return;
}
if (!scheduleChangelogVersion(currentVersion || null)) {
showChangelog();
}
});
} catch (error) {
console.debug("Storage get failed for changelog version", error);
@@ -320,6 +413,12 @@ api.runtime.onInstalled.addListener((details) => {
maybeShowChangelog(details);
});
if (api?.runtime?.onStartup && typeof api.runtime.onStartup.addListener === "function") {
api.runtime.onStartup.addListener(() => {
showPendingChangelogIfNeeded();
});
}
// api.storage.sync.get(['lastShowChangelogVersion'], (details) => {
// if (extConfig.showUpdatePopup === true &&
// details.lastShowChangelogVersion !== chrome.runtime.getManifest().version