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';
|
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,
|
|
|
|
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,
|
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,
|
|
|
|
updateAutomatically: boolean
|
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;
|
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',
|
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,
|
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,
|
|
|
|
updateAutomatically: true
|
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 {
|
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-06-25 17:42:50 +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];
|
|
|
|
}
|
|
|
|
}
|