From 35eb5964cc9f5ded9c397985a10f1df5943d5e9f Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Sat, 9 Sep 2023 22:38:32 +0800 Subject: [PATCH] add confVersion to sync new conf to frozen / history pages --- background/key_mappings.ts | 5 +++-- background/page_handlers.ts | 8 +++++--- background/ports.ts | 30 +++++++++++++++++++++--------- background/settings.ts | 23 +++++++++++++++-------- background/store.ts | 4 ++++ background/tools.ts | 4 ++-- background/ui_css.ts | 16 +++++++--------- background/utils.ts | 11 ++++++++++- content/port.ts | 5 +++-- content/request_handlers.ts | 6 ++++-- front/vomnibar.ts | 9 ++++++--- lib/utils.ts | 3 +++ typings/messages.d.ts | 16 +++++++++------- typings/vimium_c.d.ts | 2 +- 14 files changed, 93 insertions(+), 49 deletions(-) diff --git a/background/key_mappings.ts b/background/key_mappings.ts index 4c863e7f3..bf1185689 100644 --- a/background/key_mappings.ts +++ b/background/key_mappings.ts @@ -914,9 +914,10 @@ updateHooks_.keyMappings = (value: string | null): void => { updatesInKeyFSM = !!oldFSM && f(keyFSM_) !== f(oldFSM), updatesInMappedKeys = oldMappedKeys ? !curMapped || f(oldMappedKeys) !== f(curMapped) : !!oldFSM && !!curMapped; (updatesInMappedKeys || updatesInKeyFSM) && settings_.broadcast_({ - N: kBgReq.keyFSM, m: mappedKeyRegistry_, t: mappedKeyTypes_, k: updatesInKeyFSM ? keyFSM_ : null + N: kBgReq.keyFSM, m: mappedKeyRegistry_, t: mappedKeyTypes_, k: updatesInKeyFSM ? keyFSM_ : null, + v: BgUtils_.nextConfUpdate(0) }); if (oldOmniMapKeys ? !curOmniMapped || f(oldOmniMapKeys) !== f(curOmniMapped) : curOmniMapped) { - settings_.broadcastOmni_({ N: kBgReq.omni_updateOptions, d: { m: curOmniMapped } }) + settings_.broadcastOmniConf_({ m: curOmniMapped }) } }; diff --git a/background/page_handlers.ts b/background/page_handlers.ts index d35cc8c73..2c42f4074 100644 --- a/background/page_handlers.ts +++ b/background/page_handlers.ts @@ -1,10 +1,12 @@ import { contentPayload_, evalVimiumUrl_, keyFSM_, keyToCommandMap_, mappedKeyRegistry_, newTabUrls_, restoreSettings_, CONST_, settingsCache_, shownHash_, substitute_, framesForTab_, curTabId_, extAllowList_, OnChrome, reqH_, OnEdge, - storageCache_, os_, framesForOmni_, updateHooks_, Origin2_, CurCVer_ + storageCache_, os_, framesForOmni_, updateHooks_, Origin2_, CurCVer_, omniConfVer_ } from "./store" import { deferPromise_, protocolRe_, safeObj_ } from "./utils" -import { browserWebNav_, browser_, getCurTab, getTabUrl, Q_, runContentScriptsOn_, runtimeError_, tabsCreate, tabsGet } from "./browser" +import { + browserWebNav_, browser_, getCurTab, getTabUrl, Q_, runContentScriptsOn_, runtimeError_, tabsCreate, tabsGet +} from "./browser" import { convertToUrl_, lastUrlType_, reformatURL_ } from "./normalize_urls" import { findUrlInText_, parseSearchEngines_ } from "./parse_urls" import * as settings_ from "./settings" @@ -270,7 +272,7 @@ const pageRequestHandlers_: { /** kPgReq.updateOmniPayload: */ ({ key, val }, port): void => { const tabId = port && port.s && port.s.tabId_ || curTabId_ const omniPort = framesForOmni_.find(i => i.s.tabId_ === tabId) - omniPort && omniPort.postMessage({ N: kBgReq.omni_updateOptions, d: { [key]: val } }) + omniPort && omniPort.postMessage({ N: kBgReq.omni_updateOptions, d: { [key]: val }, v: omniConfVer_ }) }, /** kPgReq.saveToSyncAtOnce: */ (): void => { settingsCache_.vimSync && updateHooks_.vimSync!(true, "vimSync") diff --git a/background/ports.ts b/background/ports.ts index 311b288f9..83afd078c 100644 --- a/background/ports.ts +++ b/background/ports.ts @@ -2,7 +2,7 @@ import { needIcon_, cPort, set_cPort, reqH_, contentPayload_, omniPayload_, innerCSS_, extAllowList_, framesForTab_, findCSS_, framesForOmni_, getNextFakeTabId, curTabId_, vomnibarPage_f, OnChrome, CurCVer_, OnEdge, setIcon_, lastKeptTabId_, keyFSM_, mappedKeyRegistry_, CONST_, mappedKeyTypes_, recencyForTab_, setTeeTask_, OnFirefox, UseZhLang_, blank_, - set_lastKeptTabId_ + set_lastKeptTabId_, omniConfVer_, contentConfVer_ } from "./store" import { asyncIter_, deferPromise_, getOmniSecret_, isNotPriviledged, keys_ } from "./utils" import { @@ -123,10 +123,12 @@ export const OnConnect = (port: Frames.Port, type: PortType): void => { /*#__NOINLINE__*/ _recoverStates(ref, port, type) } else { port.postMessage(type & PortType.confInherited ? { - N: kBgReq.init, c: null as never as SettingsNS.FrontendSettingCache, d: isInactive, f: flags, p: passKeys - } satisfies Omit, keyof BgReq[kBgReq.keyFSM]> as Req.bg : { + N: kBgReq.init, c: null as never as SettingsNS.FrontendSettingCache, d: isInactive, f: flags, p: passKeys, + v: contentConfVer_ + } satisfies Omit, keyof Omit> as Req.bg + : { N: kBgReq.init, c: contentPayload_, d: isInactive, f: flags, - k: keyFSM_!, m: mappedKeyRegistry_, p: passKeys, t: mappedKeyTypes_ + k: keyFSM_!, m: mappedKeyRegistry_, p: passKeys, t: mappedKeyTypes_, v: contentConfVer_ }) if (isInactive) { port.disconnect() @@ -207,8 +209,14 @@ const _onOmniConnect = (port: Frames.Port, type: PortType, isOmniUrl: boolean): if (!OnChrome) { (port as Frames.BrowserPort).sender.tab = null as never } port.onDisconnect.addListener(/*#__NOINLINE__*/ onOmniDisconnect) port.onMessage.addListener(/*#__NOINLINE__*/ onMessage) - type & PortType.reconnect || - port.postMessage({ N: kBgReq.omni_init, l: omniPayload_, s: getOmniSecret_(false) }) + if (type & PortType.reconnect) { + const oldConfVer = type >> PortType.OFFSET_SETTINGS + if (oldConfVer !== omniConfVer_) { + port.postMessage({ N: kBgReq.omni_updateOptions, d: omniPayload_, v: omniConfVer_ }) + } + } else { + port.postMessage({ N: kBgReq.omni_init, l: omniPayload_, s: getOmniSecret_(false), v: omniConfVer_ }) + } return } } else if (port.s.tabId_ < 0 // e.g.: inside a sidebar on MS Edge @@ -699,7 +707,11 @@ const _recoverStates = (frames: Frames.Frames | undefined, port: Port, type: Por : (type & PortType.hasCSS) && Frames.Flags.hasCSS frames || refreshPorts_({ cur_: port, top_: null, ports_: [], lock_: null, flags_: Frames.Flags.HadIFrames }, 0) let flag = type as Frames.Flags - if (!(type & PortType.refreshInBatch)) { + if (type & PortType.refreshInBatch) { /* empty */ } + else if ((type >> PortType.OFFSET_SETTINGS) !== contentConfVer_ + && !(frames && frames.flags_ & Frames.Flags.MASK_UPDATES)) { + flag = Frames.Flags.MASK_UPDATES + } else { if (!(type & PortType.hasFocus) // frame is not focused - on refreshing ports of inactive tabs || !frames || !(frames.flags_ & Frames.Flags.ResReleased)) { // no old data to sync return @@ -708,11 +720,11 @@ const _recoverStates = (frames: Frames.Frames | undefined, port: Port, type: Por if (flag & Frames.Flags.HadIFrames || port.s.frameId_) { refreshPorts_(frames, 0) } } if (flag & Frames.Flags.SettingsUpdated) { - port.postMessage({ N: kBgReq.settingsUpdate, d: contentPayload_ }) + port.postMessage({ N: kBgReq.settingsUpdate, d: contentPayload_, v: contentConfVer_ }) } if (flag & Frames.Flags.KeyMappingsUpdated) { port.postMessage({ N: kBgReq.keyFSM, m: mappedKeyRegistry_, t: mappedKeyTypes_ - , k: flag & Frames.Flags.KeyFSMUpdated ? keyFSM_ : null }) + , k: flag & Frames.Flags.KeyFSMUpdated ? keyFSM_ : null, v: contentConfVer_ }) } if (flag & Frames.Flags.CssUpdated && port.s.flags_ & Frames.Flags.hasCSS) { (port.s.flags_ satisfies Frames.Flags) |= Frames.Flags.hasFindCSS diff --git a/background/settings.ts b/background/settings.ts index 156b3a528..721ee0305 100644 --- a/background/settings.ts +++ b/background/settings.ts @@ -2,9 +2,9 @@ import { contentPayload_, extAllowList_, newTabUrls_, omniPayload_, OnChrome, OnEdge, OnFirefox, framesForOmni_, sync_, IsEdg_, settingsCache_, bgIniting_, set_bgIniting_, CurCVer_, CONST_, OnOther_, onInit_, storageCache_, searchEngines_, set_hasEmptyLocalStorage_, set_newTabUrl_f, newTabUrl_f, set_vomnibarPage_f, updateHooks_,set_CurFFVer_, UseZhLang_, - CurFFVer_, set_os_, os_ + CurFFVer_, set_os_, os_, contentConfVer_ } from "./store" -import { asyncIter_, nextTick_, safeObj_ } from "./utils" +import { asyncIter_, nextTick_, safeObj_, nextConfUpdate } from "./utils" import { browser_, normalizeExtOrigin_, Qs_ } from "./browser" import { convertToUrl_, reformatURL_ } from "./normalize_urls" import { parseSearchEngines_ } from "./parse_urls" @@ -162,7 +162,8 @@ export const broadcast_ = ( request: K extends kBgReq.settingsUpdate ? SettingsUpdateMsg : Req.bg): void => { - if (request.N === kBgReq.settingsUpdate && !request.d) { + const reqName = request.N + if (reqName === kBgReq.settingsUpdate && !(request.d as typeof request.d | null)) { const obj = newSettingsToBroadcast_! const d: BgReq[kBgReq.settingsUpdate]["d"] = (request as Req.bg).d = {} for (const key of obj) { @@ -170,19 +171,25 @@ const _BroadcastSettingsUpdates = ( } newSettingsToBroadcast_ = null } - asyncIterFrames_(request.N === kBgReq.url ? Frames.Flags.UrlUpdated - : request.N === kBgReq.keyFSM ? Frames.Flags.KeyMappingsUpdated | (request.k ? Frames.Flags.KeyFSMUpdated : 0) + const needConfVer = reqName === kBgReq.keyFSM || kBgReq.settingsUpdate + asyncIterFrames_(reqName === kBgReq.url ? Frames.Flags.UrlUpdated + : reqName === kBgReq.keyFSM ? Frames.Flags.KeyMappingsUpdated | (request.k ? Frames.Flags.KeyFSMUpdated : 0) : Frames.Flags.SettingsUpdated , (frames: Frames.Frames): void => { + needConfVer && ((request as Req.bg).v = contentConfVer_) for (const port of frames.ports_) { port.postMessage(request as Req.baseBg as Req.bg) } }) } -export const broadcastOmni_ = (request: Req.bg): void => { +export const broadcastOmniConf_ = (payload: BgVomnibarSpecialReq[kBgReq.omni_updateOptions]["d"] + , excluded?: Port): void => { + const msg: Req.bg = { N: kBgReq.omni_updateOptions, d: payload, v: nextConfUpdate(1) } asyncIter_(framesForOmni_.slice(0), (frame): number => { - framesForOmni_.includes(frame) && frame.postMessage(request) + framesForOmni_.includes(frame) && frame.postMessage(frame !== excluded ? msg : { + N: kBgReq.omni_updateOptions, d: {}, v: msg.v + }) return 1 }) } @@ -252,7 +259,7 @@ Object.assign { onInit_ = _newI export const set_iconData_ = (_newIconData: typeof iconData_): void => { iconData_ = _newIconData } export const set_hasGroupPermission_ff_ = (_newAllowed: boolean | 0): void => { hasGroupPermission_ff_ = _newAllowed } export const set_lastKeptTabId_ = (_newKeptTabId: number): void => { lastKeptTabId_ = _newKeptTabId } +export const set_contentConfVer_ = (_newContConfVer: number): number => { return contentConfVer_ = _newContConfVer } +export const set_omniConfVer_ = (_newOmniConfVer: number): number => { return omniConfVer_ = _newOmniConfVer } export const set_reqH_ = (_newRH: BackendHandlersNS.FgRequestHandlers): void => { reqH_ = _newRH } export const set_bgC_ = (_newBgC: typeof bgC_): void => { bgC_ = _newBgC } diff --git a/background/tools.ts b/background/tools.ts index 6b1e42107..fbe955127 100644 --- a/background/tools.ts +++ b/background/tools.ts @@ -762,10 +762,10 @@ updateHooks_.vomnibarOptions = (options: SettingsNS.BackendSettings["vomnibarOpt MediaWatcher_.update_(MediaNS.kName.PrefersReduceMotion, 1) MediaWatcher_.update_(MediaNS.kName.PrefersColorScheme, 1) } - settings_.broadcastOmni_({ N: kBgReq.omni_updateOptions, d: { + settings_.broadcastOmniConf_({ n: maxMatches, i: queryInterval, s: sizes, t: payload.t - } }) + }) } diff --git a/background/ui_css.ts b/background/ui_css.ts index 0351184a9..b328478a0 100644 --- a/background/ui_css.ts +++ b/background/ui_css.ts @@ -1,11 +1,11 @@ import { findCSS_, innerCSS_, omniPayload_, set_findCSS_, set_innerCSS_, CurCVer_, CurFFVer_, IsEdg_, omniStyleOverridden_, OnChrome, OnEdge, OnFirefox, isHighContrast_ff_, set_isHighContrast_ff_, bgIniting_, CONST_, set_helpDialogData_, - framesForOmni_, settingsCache_, set_omniStyleOverridden_, updateHooks_, storageCache_, installation_ + settingsCache_, set_omniStyleOverridden_, updateHooks_, storageCache_, installation_, contentConfVer_ } from "./store" -import { asyncIter_, fetchFile_, spacesRe_ } from "./utils" +import { fetchFile_, nextConfUpdate, spacesRe_ } from "./utils" import { getFindCSS_cr_, set_getFindCSS_cr_ } from "./browser" -import { ready_, broadcastOmni_, postUpdate_, setInLocal_ } from "./settings" +import { ready_, broadcastOmniConf_, postUpdate_, setInLocal_ } from "./settings" import { asyncIterFrames_ } from "./ports" export declare const enum MergeAction { @@ -208,6 +208,7 @@ export const mergeCSS = (css2Str: string, action: MergeAction | "userDefinedCss" setInLocal_(O, omni2 || null) reloadCSS_(MergeAction.readFromCache, newInnerCSS) if (action !== MergeAction.readFromCache && action !== MergeAction.rebuildWhenInit) { + nextConfUpdate(0) asyncIterFrames_(Frames.Flags.CssUpdated, (frames: Frames.Frames): void => { for (const port of frames.ports_) { const flags = port.s.flags_ @@ -216,10 +217,11 @@ export const mergeCSS = (css2Str: string, action: MergeAction | "userDefinedCss" N: kBgReq.showHUD, H: innerCSS_, f: flags & Frames.Flags.hasFindCSS ? OnChrome ? getFindCSS_cr_!(port.s) : findCSS_ : void 0 }) + port.postMessage({ N: kBgReq.settingsUpdate, d: {}, v: contentConfVer_ }) } } }) - broadcastOmni_({ N: kBgReq.omni_updateOptions, d: { c: omniPayload_.c } }) + broadcastOmniConf_({ c: omniPayload_.c }) } } @@ -240,11 +242,7 @@ export const setOmniStyle_ = (req: FgReq[kFgReq.setOmniStyle], port?: Port): voi } if (styles === curStyles) { return } omniPayload_.t = styles - const request2: Req.bg = { N: kBgReq.omni_updateOptions, d: { t: styles } } - asyncIter_(framesForOmni_.slice(0), (frame): number => { - frame !== port && framesForOmni_.includes(frame) && frame.postMessage(request2) - return 1 - }) + broadcastOmniConf_({ t: styles }, port) } OnChrome && set_getFindCSS_cr_(((sender: Frames.Sender): FindCSS => { diff --git a/background/utils.ts b/background/utils.ts index ae0a7cb72..a7e243c56 100644 --- a/background/utils.ts +++ b/background/utils.ts @@ -1,4 +1,7 @@ -import { CurCVer_, CurFFVer_, framesForTab_, OnChrome, OnEdge, OnFirefox } from "./store" +import { + contentConfVer_, CurCVer_, CurFFVer_, framesForTab_, omniConfVer_, OnChrome, OnEdge, OnFirefox, set_contentConfVer_, + set_omniConfVer_ +} from "./store" export const spacesRe_ = > /\s+/g export const protocolRe_ = /^[a-z][\+\-\.\da-z]+:\/\// @@ -486,3 +489,9 @@ export const splitWhenKeepExpressions = (src: string, sep: string): string[] => results.push(src.slice(lastInd)) return results } + +export const nextConfUpdate = (useOmni: 0 | 1): number => { + let version = useOmni ? omniConfVer_ : contentConfVer_ + version = ((version + 1) & 0xfff) || 1 + return useOmni ? set_omniConfVer_(version) : set_contentConfVer_(version) +} diff --git a/content/port.ts b/content/port.ts index b357a415d..fe178dfe5 100644 --- a/content/port.ts +++ b/content/port.ts @@ -1,6 +1,6 @@ import { injector, safer, timeout_, isAlive_, isTop, set_i18n_getMsg, locHref, OnEdge, OnChrome, OnFirefox, isTY, fgCache, - interval_, setupTimerFunc_cr, noRAF_old_cr_, runtime_ff, isIFrameInAbout_, isLocked_, inherited_, chromeVer_ + interval_, setupTimerFunc_cr, noRAF_old_cr_, runtime_ff, isIFrameInAbout_, isLocked_, inherited_, chromeVer_, confVersion } from "../lib/utils" import { suppressTail_ } from "../lib/keyboard_utils" import { docHasFocus_, rAF_ } from "../lib/dom_utils" @@ -88,7 +88,8 @@ export const runtimeConnect = (function (this: void, extraFlags?: number): void : PortType.reconnect | extraFlags! | PortType.hasCSS * !!style_ui, name = (PortType.isTop === 1 ? isTop : PortType.isTop * isTop) | PortType.aboutIframe * isIFrameInAbout_ | onceFreezed | status - | PortType.hasFocus * docHasFocus_(), + | PortType.hasFocus * docHasFocus_() + | (confVersion << PortType.OFFSET_SETTINGS), data = { name: injector ? injector.$h(name) : OnEdge ? name + PortNameEnum.Delimiter + locHref() : "" + name }, connect = (OnFirefox ? runtime_ff! : api.runtime).connect port_ = (injector ? connect(injector.id, data) : connect(data)) as ContentNS.Port diff --git a/content/request_handlers.ts b/content/request_handlers.ts index 998784d7e..930f14eaf 100644 --- a/content/request_handlers.ts +++ b/content/request_handlers.ts @@ -3,7 +3,7 @@ import { keydownEvents_, set_chromeVer_, set_clickable_, set_fgCache, set_isLocked_, OnChrome, OnFirefox, safeCall, recordLog, set_isEnabled_, set_onWndFocus, onWndFocus, timeout_, safer, set_os_, safeObj, set_keydownEvents_, setupEventListener, interval_, getTime, vApi, clearInterval_, locHref, set_firefoxVer_, firefoxVer_, os_, isAsContent, isIFrameInAbout_, - OnEdge, inherited_, clearTimeout_, setupTimerFunc_cr_mv3, set_weakRef_ff, weakRef_ff, deref_ + OnEdge, inherited_, clearTimeout_, setupTimerFunc_cr_mv3, set_weakRef_ff, weakRef_ff, deref_, set_confVersion } from "../lib/utils" import { set_keyIdCorrectionOffset_old_cr_, handler_stack, suppressTail_ } from "../lib/keyboard_utils" import { @@ -166,7 +166,7 @@ set_requestHandlers([ }, /* kBgReq.msg: */ onPortRes_, /* kBgReq.eval: */ evalIfOK, - /* kBgReq.settingsUpdate: */ ({ d: delta }: BgReq[kBgReq.settingsUpdate]): void => { + /* kBgReq.settingsUpdate: */ ({ d: delta, v: newConfVersion }: BgReq[kBgReq.settingsUpdate]): void => { type Keys = keyof typeof delta; safer(delta); for (const i in delta) { @@ -175,6 +175,7 @@ set_requestHandlers([ (i2 in fgCache) && delete safer(fgCache)[i2] } delta.d != null && hud_box && toggleClass_s(hud_box, "D", !!delta.d) + newConfVersion && set_confVersion(newConfVersion) }, /* kBgReq.focusFrame: */ (req: BgReq[kBgReq.focusFrame]): void => { // Note: .c, .S are ensured to exist @@ -202,6 +203,7 @@ set_requestHandlers([ set_mapKeyTypes(request.t) set_mappedKeys(request.m) mappedKeys && safer(mappedKeys) + set_confVersion(request.v) esc!(HandlerResult.Nothing) // so that passNextKey#normal refreshes nextKeys to the new keyFSM }, /* kBgReq.execute: */ function (request: BaseExecute): void { diff --git a/front/vomnibar.ts b/front/vomnibar.ts index f4677451d..6b6784f5e 100644 --- a/front/vomnibar.ts +++ b/front/vomnibar.ts @@ -1286,6 +1286,7 @@ var VCID_: string | undefined = VCID_ || "", VHost_: string | undefined = VHost_ n = sizes.length > 3 ? +sizes[3] : 0 Vomnibar_.panelWidth_ = M(0.3, m(n || VomnibarNS.PixelData.WindowSizeX, 0.95)); } + VPort_._confVersion = response.v }, OnWndFocus_ (this: void, event: Event): void { const a = Vomnibar_, byCode = a.codeFocusTime_ && performance.now() - a.codeFocusTime_ < 120, @@ -1895,6 +1896,7 @@ VUtils_ = { }, VPort_ = { _port: null as FgPort | null, + _confVersion: 0, postToOwner_: null as never as (this: void , msg: VomnibarNS.FReq[K] & VomnibarNS.Msg) => void | 1, post_ (request: FgReq[K] & Req.baseFg): void { @@ -1915,7 +1917,7 @@ VPort_ = { name === kBgReq.omni_updateOptions ? Vomnibar_.updateOptions_(response) : name === kBgReq.omni_refresh ? !Vomnibar_.isActive_ && response.d ? Vomnibar_.OnUnload_() : Build.MV3 ? (VPort_._port!.disconnect(), VPort_.connect_(PortType.omnibar | PortType.reconnect)) : 0 : - name === kBgReq.injectorRun ? 0 : + name === kBgReq.injectorRun || name === kBgReq.showHUD ? 0 : 0; }, _OnOwnerMessage ({ data: data }: { data: VomnibarNS.CReq[keyof VomnibarNS.CReq] }): void { @@ -1928,6 +1930,7 @@ VPort_ = { }, _ClearPort (this: void): void { VPort_._port = null; }, connect_ (type: PortType): FgPort { + type |= VPort_._confVersion << PortType.OFFSET_SETTINGS const data = { name: VCID_ ? PortNameEnum.Prefix + type + (PortNameEnum.Delimiter + BuildStr.Commit) : Build.BTypes === BrowserType.Edge as number || Build.BTypes & BrowserType.Edge && !!(window as {} as {StyleMedia: unknown}).StyleMedia @@ -2011,7 +2014,7 @@ if (Build.BTypes === BrowserType.Chrome as number ? false : !(Build.BTypes & Bro } location.href = "about:blank" }, 700) - Vomnibar_.secret_ = function (this: void, {l: payload, s: secret}): void { + Vomnibar_.secret_ = function (this: void, { l: payload, s: secret, v: confVersion }): void { Vomnibar_.secret_ = null; if (!secret) { // see https://github.com/philc/vimium/issues/3832 _sec = "2"; unsafeMsg.length = 0 @@ -2034,7 +2037,7 @@ if (Build.BTypes === BrowserType.Chrome as number ? false : !(Build.BTypes & Bro } if (Build.OS & (Build.OS - 1)) { Vomnibar_.os_ = payload.o } Vomnibar_.styles_ = payload.t; - Vomnibar_.updateOptions_({ N: kBgReq.omni_updateOptions, d: payload }) + Vomnibar_.updateOptions_({ N: kBgReq.omni_updateOptions, d: payload, v: confVersion }) _sec = secret; for (const i of unsafeMsg) { if (i[0] === secret) { diff --git a/lib/utils.ts b/lib/utils.ts index 08a288b97..bf8a5d028 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -66,6 +66,9 @@ export function set_noRAF_old_cr_ (_newNoRAF: BOOL): void { noRAF_old_cr_ = _new export let fgCache: OnlyEnsureItemsNonNull export function set_fgCache (_newCache: SettingsNS.FrontendSettingCache): void { fgCache = _newCache as typeof fgCache } +export let confVersion = 0 +export function set_confVersion (_newConfVer: number): void { confVersion = _newConfVer } + export let inherited_: 0 | PortType.confInherited = 0 export function set_inherited_ (_newInherited: typeof inherited_): void { inherited_ = _newInherited } diff --git a/typings/messages.d.ts b/typings/messages.d.ts index 30ac1532f..6e0bdfc71 100644 --- a/typings/messages.d.ts +++ b/typings/messages.d.ts @@ -88,8 +88,8 @@ declare const enum kBgReq { init = START, reset, injectorRun, url, msg, eval, settingsUpdate, focusFrame, exitGrab, keyFSM, execute, showHUD, count, queryForRunKey, suppressForAWhile, refreshPort, - OMNI_MIN = 42, - omni_init = OMNI_MIN, omni_omni, omni_parsed, omni_returnFocus, + COMMON_OMNI_MIN = 42, // there're also injectorRun and showHUD + omni_init = COMMON_OMNI_MIN, omni_omni, omni_parsed, omni_returnFocus, omni_toggleStyle, omni_updateOptions, omni_refresh, omni_runTeeTask, END = "END", // without it, TypeScript will report errors for number indexes } @@ -109,6 +109,8 @@ declare const enum kFgReq { command = "command", id = "id", shortcut = "shortcut", focus = "focus", tip = "tip", } +interface ConfVersionReq { /** configuration version */ v: number } + interface BgReq { [kBgReq.init]: { /** flags */ f: Frames.Flags; @@ -118,7 +120,7 @@ interface BgReq { /** mappedKeys */ m: SafeDict | null; /** keyFSM */ k: KeyFSM; /** mappedKeyTypes */ t: kMapKey; - }; + } & ConfVersionReq [kBgReq.injectorRun]: { /** task */ t: InjectorTask; }; @@ -134,7 +136,7 @@ interface BgReq { /** mappedKeys */ m: SafeDict | null; /** keyMap */ k: KeyFSM | null; /** mappedKeyTypes */ t: kMapKey; - }; + } & ConfVersionReq [kBgReq.showHUD]: { /** kTip */ k?: kTip | 0 /** text */ t?: string; @@ -153,7 +155,7 @@ interface BgReq { [kBgReq.exitGrab]: Req.baseBg; [kBgReq.settingsUpdate]: { /** delta */ d: Partial>; - }; + } & Partial [kBgReq.url]: { /** url */ u?: string; /** use vApi.u */ U: 0 | 1 | 2 | 3 @@ -190,7 +192,7 @@ interface BgVomnibarSpecialReq { [kBgReq.omni_init]: { /** secret */ s: string /** payload */ l: SettingsNS.VomnibarPayload; - }; + } & ConfVersionReq [kBgReq.omni_parsed]: { /** id */ i: number; /** search */ s: FgRes[kFgReq.parseSearchUrl]; @@ -201,7 +203,7 @@ interface BgVomnibarSpecialReq { }; [kBgReq.omni_updateOptions]: { /** delta */ d: Partial>; - }; + } & ConfVersionReq [kBgReq.omni_runTeeTask]: Pick [kBgReq.omni_refresh]: { /** destroy */ d: boolean } } diff --git a/typings/vimium_c.d.ts b/typings/vimium_c.d.ts index 8fb172f99..b4fa52bc9 100644 --- a/typings/vimium_c.d.ts +++ b/typings/vimium_c.d.ts @@ -282,7 +282,7 @@ declare const enum PortNameEnum { declare const enum PortType { initing = 0, isTop = 1, hasFocus = 2, confInherited = 4, reconnect = 8, hasCSS = 16, onceFreezed = 32, aboutIframe = 64, selfPages = 128, omnibar = 256, refreshInBatch = 512, - otherExtension = 1024, Tee = 2048, + otherExtension = 1024, Tee = 2048, OFFSET_SETTINGS = /** log2(4096) */ 12, /** for external extensions like NewTab Adapter */ CloseSelf = 999, }