Darkreader: Migrate to a new patch that persists non-policy settings.
This commit is contained in:
parent
acaddf5a27
commit
d2e5cfb8f2
|
@ -2,15 +2,18 @@
|
||||||
__findFile,
|
__findFile,
|
||||||
buildNpmPackage,
|
buildNpmPackage,
|
||||||
fetchFromGitHub,
|
fetchFromGitHub,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
buildNpmPackage rec {
|
buildNpmPackage rec {
|
||||||
version = "4.9.96";
|
version = "4.9.99";
|
||||||
pname = "dark-reader";
|
pname = "dark-reader";
|
||||||
npmDepsHash = "sha256-dSuCL8GZXiksqVQ+TypzOdAROn3q30ExaGCJu72GLyY=";
|
npmDepsHash = "sha256-m41HkwgbeRRmxJALQFJl/grYjjIqFOc47ltaesob1FA=";
|
||||||
|
env.ESBUILD_BINARY_PATH = lib.getExe pkgs.esbuild;
|
||||||
patches = [ <patch/darkreader/Policy.patch> ];
|
patches = [ <patch/darkreader/Policy.patch> ];
|
||||||
src = fetchFromGitHub {
|
src = fetchFromGitHub {
|
||||||
hash = "sha256-2AYIFVTTMns1u0jKk3XeFuYdC1MfG9aOCMjAfZtlXuI=";
|
hash = "sha256-K375/4qOyE1Tp/T5V5uCGcNd1IVVbT1Pjdnq/8oRHj0=";
|
||||||
owner = "darkreader";
|
owner = "darkreader";
|
||||||
repo = "darkreader";
|
repo = "darkreader";
|
||||||
rev = "v${version}";
|
rev = "v${version}";
|
||||||
|
|
|
@ -1,90 +1,84 @@
|
||||||
diff --git a/src/background/user-storage.ts b/src/background/user-storage.ts
|
diff --git a/src/background/user-storage.ts b/src/background/user-storage.ts
|
||||||
index b582fb5..ca9c0dc 100644
|
index 54612fb3b1f6..298e5032fc94 100644
|
||||||
--- a/src/background/user-storage.ts
|
--- a/src/background/user-storage.ts
|
||||||
+++ b/src/background/user-storage.ts
|
+++ b/src/background/user-storage.ts
|
||||||
@@ -2,7 +2,7 @@ import {DEFAULT_SETTINGS, DEFAULT_THEME} from '../defaults';
|
@@ -5,7 +5,7 @@ import {PromiseBarrier} from '../utils/promise-barrier';
|
||||||
import {debounce} from '../utils/debounce';
|
|
||||||
import {isURLMatched} from '../utils/url';
|
import {isURLMatched} from '../utils/url';
|
||||||
import type {UserSettings} from '../definitions';
|
import {validateSettings} from '../utils/validation';
|
||||||
|
|
||||||
-import {readSyncStorage, readLocalStorage, writeSyncStorage, writeLocalStorage, removeSyncStorage, removeLocalStorage} from './utils/extension-api';
|
-import {readSyncStorage, readLocalStorage, writeSyncStorage, writeLocalStorage, removeSyncStorage, removeLocalStorage} from './utils/extension-api';
|
||||||
+import {readManagedStorage, readSyncStorage, readLocalStorage, writeSyncStorage, writeLocalStorage, removeSyncStorage, removeLocalStorage} from './utils/extension-api';
|
+import {readManagedStorage, readSyncStorage, readLocalStorage, writeSyncStorage, writeLocalStorage, removeSyncStorage, removeLocalStorage} from './utils/extension-api';
|
||||||
import {logWarn} from './utils/log';
|
import {logWarn} from './utils/log';
|
||||||
import {PromiseBarrier} from '../utils/promise-barrier';
|
|
||||||
import {validateSettings} from '../utils/validation';
|
|
||||||
@@ -82,7 +82,11 @@ export default class UserStorage {
|
|
||||||
}
|
|
||||||
UserStorage.loadBarrier = new PromiseBarrier();
|
|
||||||
|
|
||||||
- let local = await readLocalStorage(DEFAULT_SETTINGS);
|
|
||||||
+ const managed = await readManagedStorage(DEFAULT_SETTINGS);
|
@@ -78,12 +78,7 @@ export default class UserStorage {
|
||||||
+ const {errors: managedCfgErrors} = validateSettings(managed);
|
return settings;
|
||||||
+ managedCfgErrors.forEach((err) => logWarn(err));
|
}
|
||||||
+
|
|
||||||
+ let local = await readLocalStorage(managed);
|
- private static async loadSettingsFromStorage(): Promise<UserSettings> {
|
||||||
|
- if (UserStorage.loadBarrier) {
|
||||||
|
- return await UserStorage.loadBarrier.entry();
|
||||||
|
- }
|
||||||
|
- UserStorage.loadBarrier = new PromiseBarrier();
|
||||||
|
-
|
||||||
|
+ private static async loadSettingsFromStorageWithoutManaged(): Promise<UserSettings> {
|
||||||
|
let local = await readLocalStorage(DEFAULT_SETTINGS);
|
||||||
|
|
||||||
if (local.schemeVersion < 2) {
|
if (local.schemeVersion < 2) {
|
||||||
const sync = await readSyncStorage({schemeVersion: 0});
|
@@ -113,10 +108,8 @@ export default class UserStorage {
|
||||||
@@ -102,7 +106,7 @@ export default class UserStorage {
|
if (local.syncSettings == null) {
|
||||||
await writeSyncStorage({schemeVersion: 2, ...syncTransformed});
|
|
||||||
await removeSyncStorage(Object.keys(deprecatedDefaults));
|
|
||||||
|
|
||||||
- local = await readLocalStorage(DEFAULT_SETTINGS);
|
|
||||||
+ local = await readLocalStorage(managed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -112,30 +116,30 @@ export default class UserStorage {
|
|
||||||
local.syncSettings = DEFAULT_SETTINGS.syncSettings;
|
local.syncSettings = DEFAULT_SETTINGS.syncSettings;
|
||||||
}
|
}
|
||||||
|
+
|
||||||
if (!local.syncSettings) {
|
if (!local.syncSettings) {
|
||||||
- UserStorage.migrateAutomationSettings(local);
|
- UserStorage.migrateAutomationSettings(local);
|
||||||
- UserStorage.fillDefaults(local);
|
- UserStorage.fillDefaults(local);
|
||||||
- UserStorage.loadBarrier.resolve(local);
|
- UserStorage.loadBarrier.resolve(local);
|
||||||
- return local;
|
return local;
|
||||||
+ UserStorage.migrateAutomationSettings(managed);
|
|
||||||
+ UserStorage.fillDefaults(managed);
|
|
||||||
+ UserStorage.loadBarrier.resolve(managed);
|
|
||||||
+ return managed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- const $sync = await readSyncStorage(DEFAULT_SETTINGS);
|
@@ -126,18 +119,34 @@ export default class UserStorage {
|
||||||
+ const $sync = await readSyncStorage(managed);
|
|
||||||
if (!$sync) {
|
|
||||||
logWarn('Sync settings are missing');
|
|
||||||
local.syncSettings = false;
|
local.syncSettings = false;
|
||||||
UserStorage.set({syncSettings: false});
|
UserStorage.set({syncSettings: false});
|
||||||
UserStorage.saveSyncSetting(false);
|
UserStorage.saveSyncSetting(false);
|
||||||
- UserStorage.loadBarrier.resolve(local);
|
- UserStorage.loadBarrier.resolve(local);
|
||||||
- return local;
|
return local;
|
||||||
+ UserStorage.loadBarrier.resolve(managed);
|
|
||||||
+ return managed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- const {errors: syncCfgErrors} = validateSettings($sync);
|
const {errors: syncCfgErrors} = validateSettings($sync);
|
||||||
+ const {errors: syncCfgErrors} = validateSettings(managed);
|
|
||||||
syncCfgErrors.forEach((err) => logWarn(err));
|
syncCfgErrors.forEach((err) => logWarn(err));
|
||||||
|
+ return $sync;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ private static async loadSettingsFromStorage(): Promise<UserSettings> {
|
||||||
|
+ if (UserStorage.loadBarrier) {
|
||||||
|
+ return await UserStorage.loadBarrier.entry();
|
||||||
|
+ }
|
||||||
|
+ UserStorage.loadBarrier = new PromiseBarrier();
|
||||||
|
|
||||||
- UserStorage.migrateAutomationSettings($sync);
|
- UserStorage.migrateAutomationSettings($sync);
|
||||||
- UserStorage.fillDefaults($sync);
|
- UserStorage.fillDefaults($sync);
|
||||||
+ UserStorage.migrateAutomationSettings(managed);
|
+ let settings = await UserStorage.loadSettingsFromStorageWithoutManaged();
|
||||||
+ UserStorage.fillDefaults(managed);
|
|
||||||
|
|
||||||
- UserStorage.loadBarrier.resolve($sync);
|
- UserStorage.loadBarrier.resolve($sync);
|
||||||
- return $sync;
|
- return $sync;
|
||||||
+ UserStorage.loadBarrier.resolve(managed);
|
+ const managed = await readManagedStorage(settings);
|
||||||
+ return managed;
|
+ const {errors: managedCfgErrors} = validateSettings(managed);
|
||||||
|
+ if (managedCfgErrors.length === 0) {
|
||||||
|
+ settings = managed;
|
||||||
|
+ } else {
|
||||||
|
+ managedCfgErrors.forEach((err) => logWarn(err));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ UserStorage.migrateAutomationSettings(settings);
|
||||||
|
+ UserStorage.fillDefaults(settings);
|
||||||
|
+ UserStorage.loadBarrier.resolve(settings);
|
||||||
|
+ return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async saveSettings(): Promise<void> {
|
static async saveSettings(): Promise<void> {
|
||||||
@@ -227,4 +231,4 @@ export default class UserStorage {
|
|
||||||
|
|
||||||
UserStorage.settings = updatedSettings;
|
|
||||||
}
|
|
||||||
-}
|
|
||||||
+}
|
|
||||||
\ No newline at end of file
|
|
||||||
diff --git a/src/background/utils/extension-api.ts b/src/background/utils/extension-api.ts
|
diff --git a/src/background/utils/extension-api.ts b/src/background/utils/extension-api.ts
|
||||||
index ee54807..70a3cf2 100644
|
index 6d18fc0919df..6812ac2e4224 100644
|
||||||
--- a/src/background/utils/extension-api.ts
|
--- a/src/background/utils/extension-api.ts
|
||||||
+++ b/src/background/utils/extension-api.ts
|
+++ b/src/background/utils/extension-api.ts
|
||||||
@@ -97,6 +97,19 @@ export async function readLocalStorage<T extends {[key: string]: any}>(defaults:
|
@@ -97,6 +97,19 @@ export async function readLocalStorage<T extends {[key: string]: any}>(defaults:
|
||||||
|
@ -109,10 +103,10 @@ index ee54807..70a3cf2 100644
|
||||||
const value = values[key];
|
const value = values[key];
|
||||||
diff --git a/src/managed-storage.json b/src/managed-storage.json
|
diff --git a/src/managed-storage.json b/src/managed-storage.json
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..55065e4
|
index 000000000000..e394d0f1ff60
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/managed-storage.json
|
+++ b/src/managed-storage.json
|
||||||
@@ -0,0 +1,298 @@
|
@@ -0,0 +1,304 @@
|
||||||
+{
|
+{
|
||||||
+
|
+
|
||||||
+ "$schema": "http://json-schema.org/draft-07/schema#",
|
+ "$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
@ -180,6 +174,9 @@ index 0000000..55065e4
|
||||||
+ "previewNewDesign": {
|
+ "previewNewDesign": {
|
||||||
+ "type": "boolean"
|
+ "type": "boolean"
|
||||||
+ },
|
+ },
|
||||||
|
+ "previewNewestDesign": {
|
||||||
|
+ "type": "boolean"
|
||||||
|
+ },
|
||||||
+ "enableForPDF": {
|
+ "enableForPDF": {
|
||||||
+ "type": "boolean"
|
+ "type": "boolean"
|
||||||
+ },
|
+ },
|
||||||
|
@ -342,6 +339,9 @@ index 0000000..55065e4
|
||||||
+ },
|
+ },
|
||||||
+ "theme": {
|
+ "theme": {
|
||||||
+ "$ref": "Theme"
|
+ "$ref": "Theme"
|
||||||
|
+ },
|
||||||
|
+ "builtin": {
|
||||||
|
+ "type": "boolean"
|
||||||
+ }
|
+ }
|
||||||
+ },
|
+ },
|
||||||
+ "required": [
|
+ "required": [
|
||||||
|
@ -412,7 +412,7 @@ index 0000000..55065e4
|
||||||
+ }
|
+ }
|
||||||
+}
|
+}
|
||||||
diff --git a/tasks/bundle-manifest.js b/tasks/bundle-manifest.js
|
diff --git a/tasks/bundle-manifest.js b/tasks/bundle-manifest.js
|
||||||
index ae29531..f4058a1 100644
|
index ae29531e67b7..f4058a129f52 100644
|
||||||
--- a/tasks/bundle-manifest.js
|
--- a/tasks/bundle-manifest.js
|
||||||
+++ b/tasks/bundle-manifest.js
|
+++ b/tasks/bundle-manifest.js
|
||||||
@@ -4,6 +4,7 @@ import {PLATFORM} from './platform.js';
|
@@ -4,6 +4,7 @@ import {PLATFORM} from './platform.js';
|
||||||
|
|
Loading…
Reference in a new issue