支持多开实例隔离并默认打开小店

This commit is contained in:
yml2213
2026-08-09 17:25:18 +08:00
parent 6c881e9182
commit a9ad969b64
16 changed files with 385 additions and 27 deletions
+26
View File
@@ -0,0 +1,26 @@
let installed = false
// WebView 的 localStorage 会在同一个应用标识下跨窗口共享;在加载界面前
// 为每个后端实例加前缀,避免选择、监控参数和窗口状态互相覆盖。
export const installInstanceStorage = (instanceName: string) => {
if (installed || typeof Storage === 'undefined') return
installed = true
const suffix = encodeURIComponent(instanceName || '默认实例')
const prefix = `douyu-go:${suffix}:`
const storage = Storage.prototype
const getItem = storage.getItem
const setItem = storage.setItem
const removeItem = storage.removeItem
const key = (value: string) => prefix + value
storage.getItem = function (name: string) {
return getItem.call(this, key(name))
}
storage.setItem = function (name: string, value: string) {
return setItem.call(this, key(name), value)
}
storage.removeItem = function (name: string) {
return removeItem.call(this, key(name))
}
}