-
-
Notifications
You must be signed in to change notification settings - Fork 141
fix(developer): consolidate user options in TypeScript code #16134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mcdurdin
wants to merge
1
commit into
master
Choose a base branch
from
fix/developer/13458-consolidate-server-options
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
developer/src/common/web/utils/src/keyman-developer-options.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,128 @@ | ||||||
| /* | ||||||
| * Keyman is copyright (C) SIL Global. MIT License. | ||||||
| * | ||||||
| * User options for Keyman Developer. These are stored in options.json in the | ||||||
| * user profile; the location varies by operating system or may be stored in | ||||||
| * browser storage on web sites. | ||||||
| * | ||||||
| * The node-based loader is implemented in both kmc and Keyman Developer Server, | ||||||
| * in order to keep node dependencies out of the developer-utils module. | ||||||
| */ | ||||||
|
|
||||||
| /** | ||||||
| * The standard path under the user profile where options.json is stored; use | ||||||
| * `path.join(os.homedir(), ...KeymanDeveloperOptionsPath)` or similar | ||||||
| */ | ||||||
| export const KeymanDeveloperOptionsPath = [/* '~', */ '.keymandeveloper', 'options.json']; | ||||||
|
|
||||||
| /** | ||||||
| * The set of standard user options for Keyman Developer. Corresponds to | ||||||
| * TKeymanDeveloperOptions in the Keyman Developer TIKE source. | ||||||
| */ | ||||||
| export interface KeymanDeveloperOptions { | ||||||
| "use tab char": boolean; | ||||||
| "link font sizes": boolean; | ||||||
| "indent size": number; | ||||||
| "use old debugger": boolean; | ||||||
| "editor theme": string; | ||||||
| "debugger break when exiting line": boolean; | ||||||
| "debugger single step after break": boolean; | ||||||
| "debugger show store offset": boolean; | ||||||
| "debugger recompile with debug info": boolean; | ||||||
| "debugger auto reset before compilng": boolean; | ||||||
| "auto save before compiling": boolean; | ||||||
| "osk auto save before importing": boolean; | ||||||
| "web host port": number; | ||||||
| "server keep alive": boolean; | ||||||
| "server use local addresses": boolean; | ||||||
| "server ngrok token": string; | ||||||
| "server ngrok region": string; | ||||||
| "server use ngrok": boolean; | ||||||
| "server show console window": boolean; | ||||||
| "char map disable database lookups": boolean; | ||||||
| "char map auto lookup": boolean; | ||||||
| "open keyboard files in source view": boolean; | ||||||
| "display theme": string; | ||||||
| "external editor path": string; | ||||||
| "smtp server": string; | ||||||
| "test email addresses": string; | ||||||
| "web ladder length": number; | ||||||
| "default project path": string; | ||||||
| "automatically report errors": boolean; | ||||||
| "automatically report usage": boolean; | ||||||
| "toolbar visible": boolean; | ||||||
| "active project": string; | ||||||
| "prompt to upgrade projects": boolean; | ||||||
| }; | ||||||
|
|
||||||
| /** | ||||||
| * A single Keyman Developer user option. | ||||||
| */ | ||||||
| export type KeymanDeveloperOption = keyof KeymanDeveloperOptions; | ||||||
|
|
||||||
| const DEFAULT_OPTIONS: KeymanDeveloperOptions = { | ||||||
| // Corresponds to KeymanDeveloperOptions.pas, TKeymanDeveloperOptions.Read | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit clearer might be:
Suggested change
|
||||||
| "use tab char": false, | ||||||
| "link font sizes": true, | ||||||
| "indent size": 4, | ||||||
| "use old debugger": false, | ||||||
| "editor theme": '', | ||||||
| "debugger break when exiting line": true, | ||||||
| "debugger single step after break": false, | ||||||
| "debugger show store offset": false, | ||||||
| "debugger recompile with debug info": false, | ||||||
| "debugger auto reset before compilng": false, | ||||||
| "auto save before compiling": false, | ||||||
| "osk auto save before importing": false, | ||||||
| "web host port": 8008, | ||||||
| "server keep alive": false, | ||||||
| "server use local addresses": true, | ||||||
| "server ngrok token": '', | ||||||
| "server ngrok region": '', | ||||||
| "server use ngrok": false, | ||||||
| "server show console window": false, | ||||||
| "char map disable database lookups": false, | ||||||
| "char map auto lookup": true, | ||||||
| "open keyboard files in source view": false, | ||||||
| "display theme": 'Windows10', | ||||||
| "external editor path": '', | ||||||
| "smtp server": '', | ||||||
| "test email addresses": '', | ||||||
| "web ladder length": 100, | ||||||
| "default project path": '', // Note: this diverges from Delphi code, which uses CSIDL_PERSONAL on Windows, but it is not used in Server | ||||||
| "automatically report errors": true, | ||||||
| "automatically report usage": true, | ||||||
| "toolbar visible": true, | ||||||
| "active project": '', | ||||||
| "prompt to upgrade projects": true, | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| class KeymanDeveloperOptionsManager { | ||||||
| private options: KeymanDeveloperOptions = {...DEFAULT_OPTIONS}; | ||||||
| constructor() {} | ||||||
|
|
||||||
| public load(blob: Uint8Array | null) { | ||||||
| this.options = {...DEFAULT_OPTIONS}; | ||||||
| if(blob !== null && blob !== undefined) { | ||||||
| const data = JSON.parse(new TextDecoder('utf-8').decode(blob)); | ||||||
| if(typeof data == 'object') { | ||||||
| // TODO: verify fields in options | ||||||
| this.options = {...DEFAULT_OPTIONS, ...data}; | ||||||
| return true; | ||||||
| } | ||||||
| } | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| public get<T extends KeymanDeveloperOption>(valueName: T): KeymanDeveloperOptions[T] { | ||||||
| return this.options[valueName]; | ||||||
| } | ||||||
|
|
||||||
| public clear() { | ||||||
| this.options = {...DEFAULT_OPTIONS}; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| export const optionsManager = new KeymanDeveloperOptionsManager(); | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if it would be better to state the filename?