Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ const Settings = {
_settings: null,
_chromeStorageListenerInstalled: false,

_managedSettingsKeys: [],

defaultOptions,
newTabDestinations,
vimiumNewTabPageUrl,
Expand Down Expand Up @@ -122,9 +124,14 @@ const Settings = {
);
}

const managed_settings = this.pruneToOptions(await chrome.storage.managed.get(null));
this._managedSettingsKeys = Object.keys(managed_settings);

let result = await chrome.storage.sync.get(null); // Get every key.
result = this.migrateSettingsIfNecessary(result);
result["settingsVersion"] = Utils.getCurrentVersion();

result = Object.assign(result, managed_settings);
this._settings = Object.assign(globalThis.structuredClone(defaultOptions), result);
},

Expand All @@ -151,6 +158,10 @@ const Settings = {
return globalThis.structuredClone(this._settings);
},

getManagedSettingsKeys() {
return globalThis.structuredClone(this._managedSettingsKeys);
},

migratePre2_0(settings) {
// Prior to Vimium version 2.0.0:
// - In chrome.storages.sync, the value of each setting was encoded as a JSON string using
Expand Down Expand Up @@ -240,6 +251,19 @@ const Settings = {
return clonedSettings;
},

// Remove all keys not found in the default options.
pruneToOptions(settings) {
const prunedSettings = {};
for (const k of Object.keys(defaultOptions)) {
let setting = settings[k];

if (setting !== undefined) {
prunedSettings[k] = setting;
}
}
return prunedSettings;
},

// Used only by tests.
async clear() {
this._settings = null;
Expand Down
83 changes: 83 additions & 0 deletions managed_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"type": "object",
"properties": {
"scrollStepSize": {
"type": "integer"
},
"smoothScroll": {
"type": "boolean"
},
"keyMappings": {
"type": "string"
},
"linkHintCharacters": {
"type": "string"
},
"linkHintNumbers": {
"type": "string"
},
"filterLinkHints": {
"type": "boolean"
},
"hideHud": {
"type": "boolean"
},
"hideUpdateNotifications": {
"type": "boolean"
},
"userDefinedLinkHintCss": {
"type": "string"
},
"exclusionRules": {
"type": "array",
"items": {
"type": "object",
"properties": {
"passKeys": {
"type": "string"
},
"pattern": {
"type": "string"
}
}
}
},
"previousPatterns": {
"type": "string"
},
"nextPatterns": {
"type": "string"
},
"searchUrl": {
"type": "string"
},
"searchEngines": {
"type": "string"
},
"newTabDestination": {
"type": "string",
"enum": ["vimiumNewTabPage", "customUrl"]
},
"newTabCustomUrl": {
"type": "string"
},
"openVomnibarOnNewTabPage": {
"type": "boolean"
},
"grabBackFocus": {
"type": "boolean"
},
"regexFindMode": {
"type": "boolean"
},
"waitForEnterForFilteredHints": {
"type": "boolean"
},
"helpDialog_showAdvancedCommands": {
"type": "boolean"
},
"ignoreKeyboardLayout": {
"type": "boolean"
}
}
}
3 changes: 3 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"description": "The Hacker's Browser. Vimium provides keyboard shortcuts for navigation and control in the spirit of Vim.",
"icons": { "16": "icons/icon16.png", "48": "icons/icon48.png", "128": "icons/icon128.png" },
"minimum_chrome_version": "117.0",
"storage": {
"managed_schema": "managed_schema.json"
},
"background": {
"service_worker": "background_scripts/main.js",
"type": "module"
Expand Down
6 changes: 6 additions & 0 deletions pages/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ const OptionsPage = {

const settings = Settings.getSettings();
this.setFormFromSettings(settings);

for (const option of Settings.getManagedSettingsKeys()) {
let elem = this.getOptionEl(option);

elem.setAttribute("disabled", "true");
}
},

getOptionEl(optionName) {
Expand Down