insomnia/packages/insomnia-app/app/models/settings.js
Gregory Schier 549ce23ce8
Merge All Repositories into Monorepo for easier maintenance (#629)
* All projects into monorepo

* Update CI

* More CI updates

* Extracted a bunch of things into packages

* Publish

 - insomnia-plugin-base64@1.0.1
 - insomnia-plugin-default-headers@1.0.2
 - insomnia-plugin-file@1.0.1
 - insomnia-plugin-hash@1.0.1
 - insomnia-plugin-now@1.0.1
 - insomnia-plugin-request@1.0.1
 - insomnia-plugin-response@1.0.1
 - insomnia-plugin-uuid@1.0.1
 - insomnia-cookies@0.0.2
 - insomnia-importers@1.5.2
 - insomnia-prettify@0.0.3
 - insomnia-url@0.0.2
 - insomnia-xpath@0.0.2

* A bunch of small fixes

* Improved build script

* Fixed

* Merge dangling files

* Usability refactor

* Handle duplicate plugin names
2017-11-26 20:45:40 +00:00

96 lines
2.3 KiB
JavaScript

// @flow
import type {BaseModel} from './index';
import * as db from '../common/database';
import {UPDATE_CHANNEL_STABLE} from '../common/constants';
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,
maxRedirects: number,
disableAnalyticsTracking: boolean,
pluginPath: string,
nunjucksPowerUserMode: boolean,
deviceId: string | null,
updateChannel: string,
updateAutomatically: boolean
};
export type Settings = BaseModel & BaseSettings;
export const name = 'Settings';
export const type = 'Settings';
export const prefix = 'set';
export const canDuplicate = false;
export function init (): BaseSettings {
return {
showPasswords: false,
useBulkHeaderEditor: false,
followRedirects: true,
editorFontSize: 11,
editorIndentSize: 2,
editorLineWrapping: true,
editorKeyMap: 'default',
httpProxy: '',
httpsProxy: '',
noProxy: '',
maxRedirects: -1,
proxyEnabled: false,
timeout: 0,
validateSSL: true,
forceVerticalLayout: false,
autoHideMenuBar: false,
theme: 'default',
disableAnalyticsTracking: false,
pluginPath: '',
nunjucksPowerUserMode: false,
deviceId: null,
updateChannel: UPDATE_CHANNEL_STABLE,
updateAutomatically: true
};
}
export function migrate (doc: Settings): Settings {
return doc;
}
export async function all (patch: Object = {}): Promise<Array<Settings>> {
const settings = await db.all(type);
if (settings.length === 0) {
return [await getOrCreate()];
} else {
return settings;
}
}
export async function create (patch: Object = {}): Promise<Settings> {
return db.docCreate(type, patch);
}
export async function update (settings: Settings, patch: Object): Promise<Settings> {
return db.docUpdate(settings, patch);
}
export async function getOrCreate (patch: Object = {}): Promise<Settings> {
const results = await db.all(type);
if (results.length === 0) {
return create(patch);
} else {
return results[0];
}
}