Skip to content

Commit 83ece91

Browse files
feat: Inform user when Chrome autoupdates (#2277)
Co-authored-by: April Sylph <28949509+AprilSylph@users.noreply.github.com>
1 parent 7550006 commit 83ece91

4 files changed

Lines changed: 42 additions & 4 deletions

File tree

src/content_scripts/main.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@
107107
document.documentElement.append(script);
108108
});
109109

110+
/**
111+
* Shows an informative modal if the extension context is invalidated (e.g. after extension is autoupdated
112+
* or manually disabled in Chromium). Should do nothing in Firefox, which stops running all extension
113+
* context javascript immediately.
114+
*/
115+
const warnOnExtensionContextInvalidated = async () => {
116+
const { showContextInvalidatedModal } = await import(browser.runtime.getURL('/utils/modals.js'));
117+
118+
const isExtensionContextValid = () => { try { browser.runtime.getURL(''); return true; } catch { return false; } };
119+
120+
let failures = 0;
121+
const intervalID = setInterval(() => {
122+
failures = isExtensionContextValid() ? 0 : failures + 1;
123+
if (failures >= 5 && !document.getElementById('xkit-modal')) {
124+
showContextInvalidatedModal();
125+
clearInterval(intervalID);
126+
}
127+
}, 1000);
128+
};
129+
110130
const init = async function () {
111131
$('style.xkit, link.xkit').remove();
112132

@@ -130,6 +150,8 @@
130150
installedFeatures
131151
.filter(featureName => enabledFeatures.includes(featureName))
132152
.forEach(runFeature);
153+
154+
warnOnExtensionContextInvalidated();
133155
};
134156

135157
const waitForReactLoaded = async function () {

src/features/mass_deleter/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { button, form, input, label, small, span } from '../../utils/dom.js';
22
import { megaEdit } from '../../utils/mega_editor.js';
3-
import { createBlogSpan, modalCancelButton, modalCompleteButton, showErrorModal, showModal } from '../../utils/modals.js';
3+
import { createBlogSpan, hideModal, modalCancelButton, modalCompleteButton, showErrorModal, showModal } from '../../utils/modals.js';
44
import { addSidebarItem, removeSidebarItem } from '../../utils/sidebar.js';
55
import { dateTimeFormat } from '../../utils/text_format.js';
66
import { apiFetch } from '../../utils/tumblr_helpers.js';
@@ -131,7 +131,8 @@ const deleteDrafts = async function ({ blogName, before }) {
131131
'Refresh the page to see the result.',
132132
],
133133
buttons: [
134-
button({ class: 'blue', click: () => location.reload() }, ['Refresh']),
134+
button({ click: hideModal }, ['Close']),
135+
button({ class: 'blue', click: () => location.reload() }, ['Refresh Now']),
135136
],
136137
});
137138
};
@@ -225,7 +226,8 @@ const clearQueue = async function ({ blogName }) {
225226
'Refresh the page to see the result.',
226227
],
227228
buttons: [
228-
button({ class: 'blue', click: () => location.reload() }, ['Refresh']),
229+
button({ click: hideModal }, ['Close']),
230+
button({ class: 'blue', click: () => location.reload() }, ['Refresh Now']),
229231
],
230232
});
231233
};

src/features/mass_privater/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ const privatePosts = async ({ uuid, name, tags, before }) => {
236236
],
237237
buttons: [
238238
dom('button', null, { click: hideModal }, ['Close']),
239-
dom('button', { class: 'blue' }, { click: () => location.reload() }, ['Refresh']),
239+
dom('button', { class: 'blue' }, { click: () => location.reload() }, ['Refresh Now']),
240240
],
241241
});
242242
};

src/utils/modals.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,19 @@ export const withModalOnError = func =>
7272
}
7373
};
7474

75+
export const showContextInvalidatedModal = () =>
76+
showModal({
77+
title: 'XKit Rewritten has become unloaded.',
78+
message: [
79+
'If this is unexpected, this is likely due to your browser automatically applying an XKit version update.',
80+
'\n\n',
81+
'Outdated XKit modifications will be updated/removed after you refresh this Tumblr tab.',
82+
],
83+
buttons: [
84+
dom('button', null, { click: hideModal }, ['Close']),
85+
dom('button', { class: 'blue' }, { click: () => location.reload() }, ['Refresh Now']),
86+
],
87+
});
88+
7589
export const createTagSpan = tag => dom('span', { class: 'xkit-modal-tag' }, null, [tag]);
7690
export const createBlogSpan = name => dom('span', { class: 'xkit-modal-blog' }, null, [name]);

0 commit comments

Comments
 (0)