Skip to content

Commit

Permalink
🐞fix: PC site mode without refresh the settings page.
Browse files Browse the repository at this point in the history
  • Loading branch information
utubo committed Nov 29, 2024
1 parent 6ab1c61 commit 414c04d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,14 @@ if (typeof browser === 'undefined') {
await chrome.declarativeNetRequest.updateDynamicRules(rules);
onOff = 'ON';
}
if (!arg.isSettingsPage) {
if (arg.tab.url === browser.runtime.getURL('options.html')) {
browser.scripting.executeScript({
target: { tabId: arg.tab.id },
func: () => {
SimpleGesture.refreshUserAgentStatus();
}
});
} else {
await browser.tabs.reload(arg.tab.id);
}
showTextToast(arg.tab.id, `${browser.i18n.getMessage('toggleUserAgent')}: ${onOff}`);
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "3.22.1",
"version": "3.22.2",
"default_locale": "en",
"icons": {
"64": "icon64.png"
Expand Down
2 changes: 1 addition & 1 deletion src/manifest_chrome.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__",
"version": "3.22.1",
"version": "3.22.2",
"default_locale": "en",
"icons": {
"64": "icon64.png"
Expand Down
18 changes: 10 additions & 8 deletions src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ if (!browser.storage.local.set) {
const $customGestureType = byId('customGestureType');
const $customGestureUrl = byId('customGestureUrl');
const $customGestureScript = byId('customGestureScript');
const $userAgentStatus = byId('userAgentStatus');
const $timeout = byId('timeout');
const $strokeSize = byId('strokeSize');
const $bidingForms = allByClass('js-binding');
Expand Down Expand Up @@ -656,20 +657,21 @@ if (!browser.storage.local.set) {
};

// User-Agent switcher ----
const setupToggleUserAgent = async () => {
SimpleGesture.refreshUserAgentStatus = async () => {
const state = await browser.runtime.sendMessage('isUserAgentSwitched');
const $state = byId('userAgentStatus');
$state.checked = state;
$state.addEventListener('input', async () => {
$userAgentStatus.checked = state;
};
const setupToggleUserAgent = async () => {
await SimpleGesture.refreshUserAgentStatus();
$userAgentStatus.addEventListener('input', async () => {
await browser.runtime.sendMessage({
command: 'toggleUserAgent',
force: true,
isSettingsPage: true,
userAgent: $state.checked ? '' : null,
userAgent: $userAgentStatus.checked ? '' : null,
});
$state.checked = await browser.runtime.sendMessage('isUserAgentSwitched');
SimpleGesture.refreshUserAgentStatus();
});
}
};

// edit text values --
const saveBindingValues = () => {
Expand Down

0 comments on commit 414c04d

Please sign in to comment.