From fce9a527d7a542bcf15c158df4068e7ffcb10cb6 Mon Sep 17 00:00:00 2001 From: Michael Macnair Date: Sun, 17 Dec 2017 22:39:39 +0000 Subject: [PATCH] Make the editor opening on startup configurable - fixes #112 --- src/main-process/config.ts | 11 ++++++++++- src/main-process/prompts.ts | 3 ++- src/preferences.tsx | 25 +++++++++++++++++-------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/main-process/config.ts b/src/main-process/config.ts index 1f2cb1f..0a84c50 100644 --- a/src/main-process/config.ts +++ b/src/main-process/config.ts @@ -13,7 +13,8 @@ export enum ConfigName { pingFileStart = "pingFileStart", period = "period", seed = "seed", - cancelTags = "cancelTags" + cancelTags = "cancelTags", + editorOnStartup = "editorOnStartup" } export interface ConfigDict { [index: string]: any; @@ -25,6 +26,7 @@ export interface ConfigDict { period: number; seed: number; cancelTags: Set; + editorOnStartup: boolean; } export interface ConfigPref { @@ -189,6 +191,13 @@ export class Config { label: "The tags to use when not supplied by the user for any reason", configurable: true, default: ["afk", "RETRO"] + }, + { + name: ConfigName.editorOnStartup, + type: "checkbox", + label: "Open the tag editor on startup if pings have been missed since last run", + configurable: true, + default: false } ]; } diff --git a/src/main-process/prompts.ts b/src/main-process/prompts.ts index 25a761e..6333dd8 100644 --- a/src/main-process/prompts.ts +++ b/src/main-process/prompts.ts @@ -5,6 +5,7 @@ import windowStateKeeper = require("electron-window-state"); import * as helper from "./helper"; import * as edit from "./edit"; import { Ping } from "../ping"; +import { ConfigName } from "./config"; // Global reference to prevent garbage collection let promptWindow: Electron.BrowserWindow | null; @@ -166,7 +167,7 @@ export function catchUp(till: number): boolean { * Show an editor if the time is after the next ping in the pingfile */ export function editorIfMissed() { - if (global.pingFile.pings.length === 0) { + if (!global.config.user.get(ConfigName.editorOnStartup) || global.pingFile.pings.length === 0) { return; } diff --git a/src/preferences.tsx b/src/preferences.tsx index f96ddfe..b3286dc 100644 --- a/src/preferences.tsx +++ b/src/preferences.tsx @@ -22,15 +22,24 @@ export const PrefGroup = (props: PrefGroupProps) => { if (isFormControl) { inProps["className"] = "form-control"; } - let type = props.pref.type; - if (props.pref.type === "file") { - type = "input"; - inProps["className"] = - ("className" in inProps ? inProps["className"] + " " : "") + "file-input"; - } - if (props.pref.type === "tags") { - type = "input"; + + let type; + switch (props.pref.type) { + case "file": { + type = "input"; + inProps["className"] = + ("className" in inProps ? inProps["className"] + " " : "") + "file-input"; + break; + } + case "tags": { + type = "input"; + break; + } + default: { + type = props.pref.type; + } } + return (