|
1 | | -const KEY = "openclaw.control.settings.v1"; |
| 1 | +const SETTINGS_KEY_PREFIX = "openclaw.control.settings.v1:"; |
2 | 2 | const LEGACY_TOKEN_SESSION_KEY = "openclaw.control.token.v1"; |
3 | 3 | const TOKEN_SESSION_KEY_PREFIX = "openclaw.control.token.v1:"; |
4 | 4 | const MAX_SCOPED_SESSION_ENTRIES = 10; |
5 | 5 |
|
| 6 | +function settingsKeyForGateway(gatewayUrl: string): string { |
| 7 | + return `${SETTINGS_KEY_PREFIX}${normalizeGatewayTokenScope(gatewayUrl)}`; |
| 8 | +} |
| 9 | + |
6 | 10 | type ScopedSessionSelection = { |
7 | 11 | sessionKey: string; |
8 | 12 | lastActiveSessionKey: string; |
@@ -188,7 +192,9 @@ export function loadSettings(): UiSettings { |
188 | 192 | }; |
189 | 193 |
|
190 | 194 | try { |
191 | | - const raw = storage?.getItem(KEY); |
| 195 | + // First check for legacy key (no scope), then check for scoped key |
| 196 | + const scopedKey = settingsKeyForGateway(defaults.gatewayUrl); |
| 197 | + const raw = storage?.getItem(scopedKey) ?? storage?.getItem(SETTINGS_KEY_PREFIX + "default") ?? storage?.getItem("openclaw.control.settings.v1"); |
192 | 198 | if (!raw) { |
193 | 199 | return defaults; |
194 | 200 | } |
@@ -256,9 +262,11 @@ function persistSettings(next: UiSettings) { |
256 | 262 | persistSessionToken(next.gatewayUrl, next.token); |
257 | 263 | const storage = getSafeLocalStorage(); |
258 | 264 | const scope = normalizeGatewayTokenScope(next.gatewayUrl); |
| 265 | + const scopedKey = settingsKeyForGateway(next.gatewayUrl); |
259 | 266 | let existingSessionsByGateway: Record<string, ScopedSessionSelection> = {}; |
260 | 267 | try { |
261 | | - const raw = storage?.getItem(KEY); |
| 268 | + // Try to migrate from legacy key or other scopes |
| 269 | + const raw = storage?.getItem(scopedKey) ?? storage?.getItem(SETTINGS_KEY_PREFIX + "default") ?? storage?.getItem("openclaw.control.settings.v1"); |
262 | 270 | if (raw) { |
263 | 271 | const parsed = JSON.parse(raw) as PersistedUiSettings; |
264 | 272 | if (parsed.sessionsByGateway && typeof parsed.sessionsByGateway === "object") { |
@@ -294,5 +302,5 @@ function persistSettings(next: UiSettings) { |
294 | 302 | sessionsByGateway, |
295 | 303 | ...(next.locale ? { locale: next.locale } : {}), |
296 | 304 | }; |
297 | | - storage?.setItem(KEY, JSON.stringify(persisted)); |
| 305 | + storage?.setItem(scopedKey, JSON.stringify(persisted)); |
298 | 306 | } |
0 commit comments