Use Partial types for DNDSettings, SettingsOptions.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-04-27 16:16:16 -07:00
parent a49cb77840
commit 6a3f50d606
4 changed files with 14 additions and 14 deletions

View File

@@ -3,14 +3,14 @@ import * as ConfigUtil from "./config-util";
type SettingName = "showNotification" | "silent" | "flashTaskbarOnMessage";
export interface DNDSettings {
showNotification?: boolean;
silent?: boolean;
flashTaskbarOnMessage?: boolean;
showNotification: boolean;
silent: boolean;
flashTaskbarOnMessage: boolean;
}
interface Toggle {
dnd: boolean;
newSettings: DNDSettings;
newSettings: Partial<DNDSettings>;
}
export function toggle(): Toggle {
@@ -20,9 +20,9 @@ export function toggle(): Toggle {
dndSettingList.push("flashTaskbarOnMessage");
}
let newSettings: DNDSettings;
let newSettings: Partial<DNDSettings>;
if (dnd) {
const oldSettings: DNDSettings = {};
const oldSettings: Partial<DNDSettings> = {};
newSettings = {};
// Iterate through the dndSettingList.

View File

@@ -73,7 +73,7 @@ export interface RendererMessage {
autoHideMenubar: boolean,
updateMenu: boolean,
) => void;
"toggle-dnd": (state: boolean, newSettings: DNDSettings) => void;
"toggle-dnd": (state: boolean, newSettings: Partial<DNDSettings>) => void;
"toggle-menubar-setting": (state: boolean) => void;
"toggle-sidebar": (show: boolean) => void;
"toggle-sidebar-setting": (state: boolean) => void;

View File

@@ -46,12 +46,12 @@ interface SettingsOptions extends DNDSettings {
customCSS: boolean;
lastActiveTab: number;
dnd: boolean;
dndPreviousSettings: DNDSettings;
dndPreviousSettings: Partial<DNDSettings>;
downloadsPath: string;
quitOnClose: boolean;
promptDownload: boolean;
dockBouncing?: boolean;
spellcheckerLanguages?: string[];
dockBouncing: boolean;
spellcheckerLanguages: string[];
}
type WebviewListener =
@@ -194,7 +194,7 @@ class ServerManagerView {
// This will make sure the default settings are correctly set to either true or false
initDefaultSettings(): void {
// Default settings which should be respected
const settingOptions: SettingsOptions = {
const settingOptions: Partial<SettingsOptions> = {
autoHideMenubar: false,
trayIcon: true,
useManualProxy: false,
@@ -226,7 +226,7 @@ class ServerManagerView {
if (process.platform === "win32") {
// Only available on Windows
settingOptions.flashTaskbarOnMessage = true;
settingOptions.dndPreviousSettings.flashTaskbarOnMessage = true;
settingOptions.dndPreviousSettings!.flashTaskbarOnMessage = true;
}
if (process.platform === "darwin") {
@@ -1074,7 +1074,7 @@ class ServerManagerView {
ipcRenderer.on(
"toggle-dnd",
(event: Event, state: boolean, newSettings: DNDSettings) => {
(event: Event, state: boolean, newSettings: Partial<DNDSettings>) => {
this.toggleDNDButton(state);
ipcRenderer.send(
"forward-message",

View File

@@ -92,7 +92,7 @@ export function initPreferenceView(): void {
ipcRenderer.on(
"toggle-dnd",
(_event: Event, _state: boolean, newSettings: DNDSettings) => {
(_event: Event, _state: boolean, newSettings: Partial<DNDSettings>) => {
handleToggle("show-notification-option", newSettings.showNotification);
handleToggle("silent-option", newSettings.silent);