diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2020-05-04 17:50:42 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-04 17:50:42 +0900 |
commit | 69b6894b1997a773678709a7cd591afddc15c8ce (patch) | |
tree | 07e4c665829236e733316ae6f2684fe03b0a6781 /src/shared/settings | |
parent | 49addd75b76f185c9dad5d74e44e39cbea360510 (diff) | |
parent | 44ff8e449dba0de32500da3c3f17fc1361449717 (diff) |
Merge pull request #751 from ueokande/dark-mode
Supports dark mode
Diffstat (limited to 'src/shared/settings')
-rw-r--r-- | src/shared/settings/Properties.ts | 23 | ||||
-rw-r--r-- | src/shared/settings/Settings.ts | 3 | ||||
-rw-r--r-- | src/shared/settings/schema.json | 4 | ||||
-rw-r--r-- | src/shared/settings/validate.js | 45 |
4 files changed, 69 insertions, 6 deletions
diff --git a/src/shared/settings/Properties.ts b/src/shared/settings/Properties.ts index cf10d61..7540c8a 100644 --- a/src/shared/settings/Properties.ts +++ b/src/shared/settings/Properties.ts @@ -1,20 +1,23 @@ +import ColorScheme from "../ColorScheme"; + export type PropertiesJSON = { hintchars?: string; smoothscroll?: boolean; complete?: string; + colorscheme?: ColorScheme; }; export type PropertyTypes = { hintchars: string; smoothscroll: string; complete: string; + colorscheme: string; }; -type PropertyName = "hintchars" | "smoothscroll" | "complete"; +type PropertyName = "hintchars" | "smoothscroll" | "complete" | "colorscheme"; type PropertyDef = { name: PropertyName; - description: string; defaultValue: string | number | boolean; type: "string" | "number" | "boolean"; }; @@ -22,28 +25,31 @@ type PropertyDef = { const defs: PropertyDef[] = [ { name: "hintchars", - description: "hint characters on follow mode", defaultValue: "abcdefghijklmnopqrstuvwxyz", type: "string", }, { name: "smoothscroll", - description: "smooth scroll", defaultValue: false, type: "boolean", }, { name: "complete", - description: "which are completed at the open page", defaultValue: "sbh", type: "string", }, + { + name: "colorscheme", + defaultValue: ColorScheme.System, + type: "string", + }, ]; const defaultValues = { hintchars: "abcdefghijklmnopqrstuvwxyz", smoothscroll: false, complete: "sbh", + colorscheme: ColorScheme.System, }; export default class Properties { @@ -53,18 +59,23 @@ export default class Properties { public complete: string; + public colorscheme: ColorScheme; + constructor({ hintchars, smoothscroll, complete, + colorscheme, }: { hintchars?: string; smoothscroll?: boolean; complete?: string; + colorscheme?: ColorScheme; } = {}) { this.hintchars = hintchars || defaultValues.hintchars; this.smoothscroll = smoothscroll || defaultValues.smoothscroll; this.complete = complete || defaultValues.complete; + this.colorscheme = colorscheme || defaultValues.colorscheme; } static fromJSON(json: PropertiesJSON): Properties { @@ -76,6 +87,7 @@ export default class Properties { hintchars: "string", smoothscroll: "boolean", complete: "string", + colorscheme: "string", }; } @@ -92,6 +104,7 @@ export default class Properties { hintchars: this.hintchars, smoothscroll: this.smoothscroll, complete: this.complete, + colorscheme: this.colorscheme, }; } } diff --git a/src/shared/settings/Settings.ts b/src/shared/settings/Settings.ts index 1bb9249..6f178ea 100644 --- a/src/shared/settings/Settings.ts +++ b/src/shared/settings/Settings.ts @@ -156,7 +156,8 @@ export const DefaultSettingJSONText = `{ "properties": { "hintchars": "abcdefghijklmnopqrstuvwxyz", "smoothscroll": false, - "complete": "sbh" + "complete": "sbh", + "colorscheme": "system" }, "blacklist": [ ] diff --git a/src/shared/settings/schema.json b/src/shared/settings/schema.json index 31d47f1..be0f2ec 100644 --- a/src/shared/settings/schema.json +++ b/src/shared/settings/schema.json @@ -48,6 +48,10 @@ }, "complete": { "type": "string" + }, + "colorscheme": { + "type": "string", + "enum": ["system", "light", "dark"] } } }, diff --git a/src/shared/settings/validate.js b/src/shared/settings/validate.js index 236488d..30f7888 100644 --- a/src/shared/settings/validate.js +++ b/src/shared/settings/validate.js @@ -1,4 +1,5 @@ 'use strict'; +var equal = require('ajv/lib/compile/equal'); var validate = (function() { var pattern0 = new RegExp('.*'); var refVal = []; @@ -273,6 +274,46 @@ var validate = (function() { } var valid2 = errors === errs_2; } + if (valid2) { + var data2 = data1.colorscheme; + if (data2 === undefined) { + valid2 = true; + } else { + var errs_2 = errors; + if (typeof data2 !== "string") { + validate.errors = [{ + keyword: 'type', + dataPath: (dataPath || '') + '.properties.colorscheme', + schemaPath: '#/properties/properties/properties/colorscheme/type', + params: { + type: 'string' + }, + message: 'should be string' + }]; + return false; + } + var schema2 = validate.schema.properties.properties.properties.colorscheme.enum; + var valid2; + valid2 = false; + for (var i2 = 0; i2 < schema2.length; i2++) + if (equal(data2, schema2[i2])) { + valid2 = true; + break; + } if (!valid2) { + validate.errors = [{ + keyword: 'enum', + dataPath: (dataPath || '') + '.properties.colorscheme', + schemaPath: '#/properties/properties/properties/colorscheme/enum', + params: { + allowedValues: schema2 + }, + message: 'should be equal to one of the allowed values' + }]; + return false; + } + var valid2 = errors === errs_2; + } + } } } } else { @@ -535,6 +576,10 @@ validate.schema = { }, "complete": { "type": "string" + }, + "colorscheme": { + "type": "string", + "enum": ["system", "light", "dark"] } } }, |