Repository navigation
Expand file tree
/
Copy pathmigrations.js
More file actions
76 lines (63 loc) · 2.93 KB
/
Copy pathmigrations.js
File metadata and controls
76 lines (63 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"use strict";
import { debug } from "./lib/utils.js";
import { parseOverrides, SYNC_MODE_IGNORE, SYNC_MODE_RESTORE } from "./common.js";
export const CURRENT_CONFIG_VERSION = 37;
// Convert action values from numbers (0/1) to strings ("IGNORE"/"RESTORE")
function normalizeActionToString(action) {
if (action === SYNC_MODE_IGNORE || action === "IGNORE") return "IGNORE";
if (action === SYNC_MODE_RESTORE || action === "RESTORE") return "RESTORE";
return action;
}
// Converts old override format to new format
// - Converts action values from numbers (0/1) to strings ("IGNORE"/"RESTORE")
// - Converts { query: { title } } format to flat { title } format
function migrateOverrides(overrides) {
Object.values(overrides).forEach((wshos) => {
if (!Array.isArray(wshos)) return;
wshos.forEach((o) => {
// Convert action to string format expected by state-matcher.js
if (o.action !== undefined) {
o.action = normalizeActionToString(o.action);
}
// Convert old { query: { title } } format to new { title } format
if (o.query && o.query.title !== undefined) {
o.title = o.query.title;
delete o.query;
}
});
});
return overrides;
}
// Main migration entry point - call this on extension enable
export function migrateSettings(settings) {
const configVersion = settings.get_int("config-version");
if (configVersion >= CURRENT_CONFIG_VERSION) return;
// Check if this is a fresh install (no data to migrate)
const savedWindows = settings.get_string("saved-windows");
const overridesStr = settings.get_string("overrides");
const isFreshInstall = configVersion === 0 &&
(savedWindows === "{}" || savedWindows === "[]" || savedWindows === "") &&
(overridesStr === "{}" || overridesStr === "");
if (isFreshInstall) {
debug("migrations", "Fresh install detected, skipping migration");
settings.set_int("config-version", CURRENT_CONFIG_VERSION);
return;
}
debug("migrations", `Migrating settings from version ${configVersion} to ${CURRENT_CONFIG_VERSION}`);
if (configVersion < 36) {
// Clear saved windows - format is incompatible between versions
settings.set_string("saved-windows", "{}");
// Migrate overrides: convert action numbers to strings and query format to flat format
const overrides = migrateOverrides(parseOverrides(overridesStr));
settings.set_string("overrides", JSON.stringify(overrides));
debug("migrations", "Migration complete: saved windows cleared, overrides converted to new format");
}
if (configVersion < 37) {
// v37: Added LIFO connector preference for monitor selection
// Clear saved windows since old configs don't have connectorPreference field
// and monitor selection behavior has changed
settings.set_string("saved-windows", "{}");
debug("migrations", "Migration v37: saved windows cleared for connector preference feature");
}
settings.set_int("config-version", CURRENT_CONFIG_VERSION);
}