2017-07-19 04:48:28 +00:00
|
|
|
// @flow
|
|
|
|
import type {BaseModel} from './index';
|
2016-11-10 05:56:23 +00:00
|
|
|
import * as db from '../common/database';
|
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-07-20 01:55:40 +00:00
|
|
|
disableAnalyticsTracking: boolean,
|
|
|
|
pluginPath: string
|
2017-07-19 04:48:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type Settings = BaseModel & Settings;
|
|
|
|
|
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
|
|
|
|
2017-07-19 04:48:28 +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-07-20 01:55:40 +00:00
|
|
|
disableAnalyticsTracking: false,
|
|
|
|
pluginPath: ''
|
2016-11-10 01:15:27 +00:00
|
|
|
};
|
2016-10-02 20:57:00 +00:00
|
|
|
}
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2017-07-19 04:48:28 +00:00
|
|
|
export function migrate <T> (doc: T): T {
|
2016-11-22 19:42:10 +00:00
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2017-07-19 04:48:28 +00:00
|
|
|
export async function all (): 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-19 04:48:28 +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
|
|
|
|
2017-07-19 04:48:28 +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
|
|
|
|
2017-07-19 04:48:28 +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-06-01 13:50:15 +00:00
|
|
|
return await create(patch);
|
2016-10-02 20:57:00 +00:00
|
|
|
} else {
|
|
|
|
return results[0];
|
|
|
|
}
|
|
|
|
}
|