2017-07-19 04:48:28 +00:00
|
|
|
// @flow
|
2018-06-25 17:42:50 +00:00
|
|
|
import type { BaseModel } from './index';
|
2016-11-10 05:56:23 +00:00
|
|
|
import * as db from '../common/database';
|
2018-06-25 17:42:50 +00:00
|
|
|
import { UPDATE_CHANNEL_STABLE } from '../common/constants';
|
2019-03-12 16:38:30 +00:00
|
|
|
import * as hotkeys from '../common/hotkeys';
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2017-07-19 04:48:28 +00:00
|
|
|
type BaseSettings = {
|
|
|
|
showPasswords: boolean,
|
|
|
|
useBulkHeaderEditor: boolean,
|
|
|
|
followRedirects: boolean,
|
|
|
|
editorFontSize: number,
|
|
|
|
editorIndentSize: number,
|
|
|
|
editorLineWrapping: boolean,
|
|
|
|
editorKeyMap: string,
|
2018-09-26 23:08:32 +00:00
|
|
|
editorIndentWithTabs: boolean,
|
2017-07-19 04:48:28 +00:00
|
|
|
httpProxy: string,
|
|
|
|
httpsProxy: string,
|
|
|
|
noProxy: string,
|
|
|
|
proxyEnabled: boolean,
|
|
|
|
timeout: number,
|
|
|
|
validateSSL: boolean,
|
|
|
|
forceVerticalLayout: boolean,
|
|
|
|
autoHideMenuBar: boolean,
|
|
|
|
theme: string,
|
2017-08-16 17:08:29 +00:00
|
|
|
maxRedirects: number,
|
2019-04-18 04:29:42 +00:00
|
|
|
maxHistoryResponses: number,
|
2017-10-13 08:22:13 +00:00
|
|
|
pluginPath: string,
|
2017-11-18 22:47:54 +00:00
|
|
|
nunjucksPowerUserMode: boolean,
|
2017-11-21 17:49:33 +00:00
|
|
|
deviceId: string | null,
|
|
|
|
updateChannel: string,
|
2018-07-12 20:38:51 +00:00
|
|
|
updateAutomatically: boolean,
|
2018-11-06 00:41:42 +00:00
|
|
|
disableUpdateNotification: boolean,
|
2018-10-17 17:26:19 +00:00
|
|
|
environmentHighlightColorStyle: string,
|
2019-01-09 23:13:24 +00:00
|
|
|
autocompleteDelay: number,
|
2018-10-17 18:20:46 +00:00
|
|
|
fontMonospace: string | null,
|
|
|
|
fontInterface: string | null,
|
2018-10-17 17:26:19 +00:00
|
|
|
fontSize: number,
|
2018-12-12 17:36:11 +00:00
|
|
|
fontVariantLigatures: boolean,
|
2019-04-27 08:46:10 +00:00
|
|
|
maxTimelineDataSizeKB: number,
|
2019-04-18 00:50:03 +00:00
|
|
|
|
|
|
|
// Feature flags
|
|
|
|
enableSyncBeta: boolean,
|
2019-03-12 16:38:30 +00:00
|
|
|
hotKeyRegistry: hotkeys.HotKeyRegistry,
|
2017-07-19 04:48:28 +00:00
|
|
|
};
|
|
|
|
|
2017-11-18 22:47:54 +00:00
|
|
|
export type Settings = BaseModel & BaseSettings;
|
2017-07-19 04:48:28 +00:00
|
|
|
|
2016-11-22 19:42:10 +00:00
|
|
|
export const name = 'Settings';
|
2016-10-02 20:57:00 +00:00
|
|
|
export const type = 'Settings';
|
|
|
|
export const prefix = 'set';
|
2017-03-23 22:10:42 +00:00
|
|
|
export const canDuplicate = false;
|
2019-04-18 00:50:03 +00:00
|
|
|
export const canSync = false;
|
2016-11-22 19:42:10 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function init(): BaseSettings {
|
2016-11-10 01:15:27 +00:00
|
|
|
return {
|
2016-11-26 08:29:16 +00:00
|
|
|
showPasswords: false,
|
2016-10-02 20:57:00 +00:00
|
|
|
useBulkHeaderEditor: false,
|
2016-10-26 17:49:49 +00:00
|
|
|
followRedirects: true,
|
2017-04-21 04:30:52 +00:00
|
|
|
editorFontSize: 11,
|
|
|
|
editorIndentSize: 2,
|
2016-10-02 20:57:00 +00:00
|
|
|
editorLineWrapping: true,
|
2017-01-24 22:18:11 +00:00
|
|
|
editorKeyMap: 'default',
|
2018-09-26 23:08:32 +00:00
|
|
|
editorIndentWithTabs: true,
|
2016-10-02 20:57:00 +00:00
|
|
|
httpProxy: '',
|
|
|
|
httpsProxy: '',
|
2017-06-06 20:21:59 +00:00
|
|
|
noProxy: '',
|
2017-08-16 17:08:29 +00:00
|
|
|
maxRedirects: -1,
|
2019-04-18 04:29:42 +00:00
|
|
|
maxHistoryResponses: 20,
|
2017-03-28 22:45:23 +00:00
|
|
|
proxyEnabled: false,
|
2016-10-02 20:57:00 +00:00
|
|
|
timeout: 0,
|
2016-10-21 17:20:36 +00:00
|
|
|
validateSSL: true,
|
2016-10-26 20:19:18 +00:00
|
|
|
forceVerticalLayout: false,
|
2017-05-17 16:35:44 +00:00
|
|
|
autoHideMenuBar: false,
|
2017-06-01 13:35:29 +00:00
|
|
|
theme: 'default',
|
2017-10-13 08:22:13 +00:00
|
|
|
pluginPath: '',
|
2017-11-18 22:47:54 +00:00
|
|
|
nunjucksPowerUserMode: false,
|
2017-11-21 17:49:33 +00:00
|
|
|
deviceId: null,
|
|
|
|
updateChannel: UPDATE_CHANNEL_STABLE,
|
2018-07-12 20:38:51 +00:00
|
|
|
updateAutomatically: true,
|
2018-11-06 00:41:42 +00:00
|
|
|
disableUpdateNotification: false,
|
2018-10-17 17:26:19 +00:00
|
|
|
environmentHighlightColorStyle: 'sidebar-indicator',
|
2019-05-08 20:13:42 +00:00
|
|
|
autocompleteDelay: 1200,
|
2018-10-17 18:20:46 +00:00
|
|
|
fontMonospace: null,
|
|
|
|
fontInterface: null,
|
2018-10-17 17:26:19 +00:00
|
|
|
fontSize: 13,
|
2018-12-12 17:36:11 +00:00
|
|
|
fontVariantLigatures: false,
|
2019-04-27 08:46:10 +00:00
|
|
|
maxTimelineDataSizeKB: 10,
|
2019-04-18 00:50:03 +00:00
|
|
|
enableSyncBeta: false,
|
2019-03-12 16:38:30 +00:00
|
|
|
hotKeyRegistry: hotkeys.newDefaultRegistry(),
|
2016-11-10 01:15:27 +00:00
|
|
|
};
|
2016-10-02 20:57:00 +00:00
|
|
|
}
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export function migrate(doc: Settings): Settings {
|
2019-04-26 20:58:05 +00:00
|
|
|
doc = migrateEnsureHotKeys(doc);
|
2016-11-22 19:42:10 +00:00
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export async function all(patch: Object = {}): Promise<Array<Settings>> {
|
2016-11-16 17:18:39 +00:00
|
|
|
const settings = await db.all(type);
|
|
|
|
if (settings.length === 0) {
|
|
|
|
return [await getOrCreate()];
|
|
|
|
} else {
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export async function create(patch: Object = {}): Promise<Settings> {
|
2016-10-02 20:57:00 +00:00
|
|
|
return db.docCreate(type, patch);
|
|
|
|
}
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2018-10-17 16:42:33 +00:00
|
|
|
export async function update(settings: Settings, patch: Object): Promise<Settings> {
|
2016-09-21 20:32:45 +00:00
|
|
|
return db.docUpdate(settings, patch);
|
2016-10-02 20:57:00 +00:00
|
|
|
}
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
export async function getOrCreate(patch: Object = {}): Promise<Settings> {
|
2016-10-02 20:57:00 +00:00
|
|
|
const results = await db.all(type);
|
|
|
|
if (results.length === 0) {
|
2017-11-20 16:07:36 +00:00
|
|
|
return create(patch);
|
2016-10-02 20:57:00 +00:00
|
|
|
} else {
|
|
|
|
return results[0];
|
|
|
|
}
|
|
|
|
}
|
2019-04-26 20:58:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure map is updated when new hotkeys are added
|
|
|
|
*/
|
|
|
|
function migrateEnsureHotKeys(settings: Settings): Settings {
|
|
|
|
settings.hotKeyRegistry = {
|
|
|
|
...hotkeys.newDefaultRegistry(),
|
|
|
|
...settings.hotKeyRegistry,
|
|
|
|
};
|
|
|
|
return settings;
|
|
|
|
}
|