Skip to content

Commit

Permalink
fix style matching with soft navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
tophf committed Jan 18, 2025
1 parent 93cfa53 commit a543970
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/background/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ export const dataHub = {
};
const data = {__proto__: null};

/** @type {Set<(isDark: boolean) => ?>} */
export const onSchemeChange = new Set();
/** @type {Set<(tabId: number, url: string, oldUrl?: string) => ?>} */
export const onTabUrlChange = new Set();
/** @type {Set<(tabId: number, frameId: number, port: chrome.runtime.Port) => ?>} */
export const onUnload = new Set();
export const onUrl = new Set();
/** @type {Set<(data: Object, type: 'committed'|'history'|'hash') => ?>} */
export const onUrlChange = new Set();

export const uuidIndex = Object.assign(new Map(), {
custom: {},
Expand Down
5 changes: 2 additions & 3 deletions src/background/icon-manager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {kDisableAll, kStyleIds, kUrl} from '@/js/consts';
import {kDisableAll, kStyleIds} from '@/js/consts';
import {__values as __prefs, subscribe} from '@/js/prefs';
import {CHROME, FIREFOX, MOBILE, VIVALDI} from '@/js/ua';
import {debounce, t} from '@/js/util';
Expand Down Expand Up @@ -70,11 +70,10 @@ onUnload.add((tabId, frameId, port) => {
*/
export function updateIconBadge(styleIds, lazyBadge) {
// FIXME: in some cases, we only have to redraw the badge. is it worth a optimization?
const {tab: {id: tabId}, TDM, url} = this.sender;
const {tab: {id: tabId}, TDM} = this.sender;
const frameId = TDM > 0 ? 0 : this.sender.frameId;
const value = styleIds.length ? styleIds.map(Number) : undefined;
tabMan.set(tabId, kStyleIds, frameId, value);
tabMan.set(tabId, kUrl, frameId, value && url);
debounce(refreshStaleBadges, frameId && lazyBadge ? 250 : 0);
staleBadges.add(tabId);
if (!frameId) refreshIcon(tabId, true);
Expand Down
4 changes: 1 addition & 3 deletions src/background/navigation-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import {chromeProtectsNTP} from '@/js/urls';
import {deepEqual} from '@/js/util';
import {ignoreChromeError, MF} from '@/js/util-webext';
import {pingTab, sendTab} from './broadcast';
import {bgBusy} from './common';
import {bgBusy, onUrlChange} from './common';
import tabCache from './tab-manager';

/** @type {Set<(data: Object, type: 'committed'|'history'|'hash') => ?>} */
export const onUrlChange = new Set();
export const webNavigation = chrome.webNavigation;
/** @type {{ url: chrome.events.UrlFilter[] }} */
const WEBNAV_FILTER_STYLABLE = {
Expand Down
8 changes: 4 additions & 4 deletions src/background/tab-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {kApplyPort, kStyleIds, kUrl} from '@/js/consts';
import {onDisconnect} from '@/js/msg';
import {supported} from '@/js/urls';
import {ignoreChromeError} from '@/js/util-webext';
import {bgBusy, bgInit, onUnload, onUrl} from './common';
import {bgBusy, bgInit, onUnload, onTabUrlChange, onUrlChange} from './common';
import {stateDB} from './db';
import {kCommitted, onUrlChange} from './navigation-manager';
import {kCommitted} from './navigation-manager';

/** @typedef {{ url:string, styleIds: {[frameId:string]: number[]} }} StyleIdsFrameMap */
/** @type {Map<number,{ id: number, nonce:Object, url:Object, styleIds: StyleIdsFrameMap }>} */
Expand Down Expand Up @@ -109,9 +109,9 @@ bgBusy.then(() => {
obj[kUrl] = {0: url};
else
(obj[kUrl] ??= {})[frameId] = url;
if (frameId) return;
if (__.MV3) stateDB.put(obj, tabId);
for (const fn of onUrl) fn(tabId, url, oldUrl);
if (frameId) return;
for (const fn of onTabUrlChange) fn(tabId, url, oldUrl);
});
});

Expand Down
6 changes: 3 additions & 3 deletions src/background/usercss-install-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as prefs from '@/js/prefs';
import {FIREFOX} from '@/js/ua';
import * as URLS from '@/js/urls';
import {getHost, RX_META} from '@/js/util';
import {bgBusy, onUrl} from './common';
import {bgBusy, onTabUrlChange} from './common';
import download from './download';
import tabCache, * as tabMan from './tab-manager';
import {openURL} from './tab-util';
Expand All @@ -27,8 +27,8 @@ export function getInstallCode(url) {
}

function toggle(key, val, isInit) {
if (val) onUrl.add(maybeInstall);
else onUrl.delete(maybeInstall);
if (val) onTabUrlChange.add(maybeInstall);
else onTabUrlChange.delete(maybeInstall);
if (!__.MV3 || !isInit) toggleUrlInstaller(val);
}

Expand Down

0 comments on commit a543970

Please sign in to comment.