xo: Fix @typescript-eslint/naming-convention.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2022-03-08 20:08:28 -08:00
parent b43a7b6809
commit bc59714192
28 changed files with 159 additions and 159 deletions

View File

@@ -21,7 +21,7 @@ const logger = new Logger({
let db: JsonDB;
reloadDB();
reloadDb();
export function getConfigItem<Key extends keyof Config>(
key: Key,
@@ -75,7 +75,7 @@ export function removeConfigItem(key: string): void {
db.save();
}
function reloadDB(): void {
function reloadDb(): void {
const settingsJsonPath = path.join(
app.getPath("userData"),
"/config/settings.json",

View File

@@ -3,17 +3,17 @@ import type * as z from "zod";
import type {dndSettingsSchemata} from "./config-schemata.js";
import * as ConfigUtil from "./config-util.js";
export type DNDSettings = {
export type DndSettings = {
[Key in keyof typeof dndSettingsSchemata]: z.output<
typeof dndSettingsSchemata[Key]
>;
};
type SettingName = keyof DNDSettings;
type SettingName = keyof DndSettings;
interface Toggle {
dnd: boolean;
newSettings: Partial<DNDSettings>;
newSettings: Partial<DndSettings>;
}
export function toggle(): Toggle {
@@ -23,9 +23,9 @@ export function toggle(): Toggle {
dndSettingList.push("flashTaskbarOnMessage");
}
let newSettings: Partial<DNDSettings>;
let newSettings: Partial<DndSettings>;
if (dnd) {
const oldSettings: Partial<DNDSettings> = {};
const oldSettings: Partial<DndSettings> = {};
newSettings = {};
// Iterate through the dndSettingList.

View File

@@ -19,9 +19,9 @@ const logger = new Logger({
let enterpriseSettings: Partial<EnterpriseConfig>;
let configFile: boolean;
reloadDB();
reloadDb();
function reloadDB(): void {
function reloadDb(): void {
let enterpriseFile = "/etc/zulip-desktop-config/global_config.json";
if (process.platform === "win32") {
enterpriseFile =
@@ -55,7 +55,7 @@ export function getConfigItem<Key extends keyof EnterpriseConfig>(
key: Key,
defaultValue: EnterpriseConfig[Key],
): EnterpriseConfig[Key] {
reloadDB();
reloadDb();
if (!configFile) {
return defaultValue;
}
@@ -65,7 +65,7 @@ export function getConfigItem<Key extends keyof EnterpriseConfig>(
}
export function configItemExists(key: keyof EnterpriseConfig): boolean {
reloadDB();
reloadDb();
if (!configFile) {
return false;
}

View File

@@ -1,26 +1,26 @@
import {htmlEscape} from "escape-goat";
export class HTML {
export class Html {
html: string;
constructor({html}: {html: string}) {
this.html = html;
}
join(htmls: readonly HTML[]): HTML {
return new HTML({html: htmls.map((html) => html.html).join(this.html)});
join(htmls: readonly Html[]): Html {
return new Html({html: htmls.map((html) => html.html).join(this.html)});
}
}
export function html(
template: TemplateStringsArray,
...values: unknown[]
): HTML {
): Html {
let html = template[0];
for (const [index, value] of values.entries()) {
html += value instanceof HTML ? value.html : htmlEscape(String(value));
html += value instanceof Html ? value.html : htmlEscape(String(value));
html += template[index + 1];
}
return new HTML({html});
return new Html({html});
}

View File

@@ -74,13 +74,13 @@ export default class Logger {
async trimLog(file: string): Promise<void> {
const data = await fs.promises.readFile(file, "utf8");
const MAX_LOG_FILE_LINES = 500;
const maxLogFileLines = 500;
const logs = data.split(os.EOL);
const logLength = logs.length - 1;
// Keep bottom MAX_LOG_FILE_LINES of each log instance
if (logLength > MAX_LOG_FILE_LINES) {
const trimmedLogs = logs.slice(logLength - MAX_LOG_FILE_LINES);
// Keep bottom maxLogFileLines of each log instance
if (logLength > maxLogFileLines) {
const trimmedLogs = logs.slice(logLength - maxLogFileLines);
const toWrite = trimmedLogs.join(os.EOL);
await fs.promises.writeFile(file, toWrite);
}

View File

@@ -1,4 +1,4 @@
import type {DNDSettings} from "./dnd-util.js";
import type {DndSettings} from "./dnd-util.js";
import type {MenuProps, ServerConf} from "./types.js";
export interface MainMessage {
@@ -69,7 +69,7 @@ export interface RendererMessage {
autoHideMenubar: boolean,
updateMenu: boolean,
) => void;
"toggle-dnd": (state: boolean, newSettings: Partial<DNDSettings>) => void;
"toggle-dnd": (state: boolean, newSettings: Partial<DndSettings>) => void;
"toggle-sidebar": (show: boolean) => void;
"toggle-silent": (state: boolean) => void;
"toggle-tray": (state: boolean) => void;

View File

@@ -31,15 +31,15 @@ let badgeCount: number;
let isQuitting = false;
// Load this url in main window
const mainURL = "file://" + path.join(__dirname, "../renderer", "main.html");
const mainUrl = "file://" + path.join(__dirname, "../renderer", "main.html");
const permissionCallbacks = new Map<number, (grant: boolean) => void>();
let nextPermissionCallbackId = 0;
const APP_ICON = path.join(__dirname, "../resources", "Icon");
const appIcon = path.join(__dirname, "../resources", "Icon");
const iconPath = (): string =>
APP_ICON + (process.platform === "win32" ? ".ico" : ".png");
appIcon + (process.platform === "win32" ? ".ico" : ".png");
// Toggle the app window
const toggleApp = (): void => {
@@ -80,7 +80,7 @@ function createMainWindow(): Electron.BrowserWindow {
send(win.webContents, "focus");
});
(async () => win.loadURL(mainURL))();
(async () => win.loadURL(mainUrl))();
// Keep the app running in background on close event
win.on("close", (event) => {

View File

@@ -13,13 +13,13 @@ const logger = new Logger({
let db: JsonDB;
reloadDB();
reloadDb();
export function getUpdateItem(
key: string,
defaultValue: true | null = null,
): true | null {
reloadDB();
reloadDb();
let value: unknown;
try {
value = db.getObject<unknown>(`/${key}`);
@@ -37,15 +37,15 @@ export function getUpdateItem(
export function setUpdateItem(key: string, value: true | null): void {
db.push(`/${key}`, value, true);
reloadDB();
reloadDb();
}
export function removeUpdateItem(key: string): void {
db.delete(`/${key}`);
reloadDB();
reloadDb();
}
function reloadDB(): void {
function reloadDb(): void {
const linuxUpdateJsonPath = path.join(
app.getPath("userData"),
"/config/updates.json",

View File

@@ -303,7 +303,7 @@ function getWindowSubmenu(
];
if (tabs.length > 0) {
const ShortcutKey = process.platform === "darwin" ? "Cmd" : "Ctrl";
const shortcutKey = process.platform === "darwin" ? "Cmd" : "Ctrl";
initialSubmenu.push({
type: "separator",
});
@@ -320,7 +320,7 @@ function getWindowSubmenu(
initialSubmenu.push({
label: tab.name,
accelerator:
tab.role === "function" ? "" : `${ShortcutKey} + ${tab.index + 1}`,
tab.role === "function" ? "" : `${shortcutKey} + ${tab.index + 1}`,
checked: tab.index === activeTabIndex,
click(_item, focusedWindow) {
if (focusedWindow) {

View File

@@ -19,13 +19,13 @@ export const setAutoLaunch = async (
// `setLoginItemSettings` doesn't support linux
if (process.platform === "linux") {
const ZulipAutoLauncher = new AutoLaunch({
const zulipAutoLauncher = new AutoLaunch({
name: "Zulip",
isHidden: false,
});
await (autoLaunchOption
? ZulipAutoLauncher.enable()
: ZulipAutoLauncher.disable());
? zulipAutoLauncher.enable()
: zulipAutoLauncher.disable());
} else {
app.setLoginItemSettings({
openAtLogin: autoLaunchOption,

View File

@@ -1,6 +1,6 @@
import type {HTML} from "../../../common/html.js";
import type {Html} from "../../../common/html.js";
export function generateNodeFromHTML(html: HTML): Element {
export function generateNodeFromHtml(html: Html): Element {
const wrapper = document.createElement("div");
wrapper.innerHTML = html.html;

View File

@@ -11,7 +11,7 @@ export const contextMenu = (
) => {
const isText = props.selectionText !== "";
const isLink = props.linkURL !== "";
const linkURL = isLink ? new URL(props.linkURL) : undefined;
const linkUrl = isLink ? new URL(props.linkURL) : undefined;
const makeSuggestion = (suggestion: string) => ({
label: suggestion,
@@ -76,7 +76,7 @@ export const contextMenu = (
},
{
label:
linkURL?.protocol === "mailto:"
linkUrl?.protocol === "mailto:"
? t.__("Copy Email Address")
: t.__("Copy Link"),
visible: isLink,
@@ -84,7 +84,7 @@ export const contextMenu = (
clipboard.write({
bookmark: props.linkText,
text:
linkURL?.protocol === "mailto:" ? linkURL.pathname : props.linkURL,
linkUrl?.protocol === "mailto:" ? linkUrl.pathname : props.linkURL,
});
},
},

View File

@@ -1,7 +1,7 @@
import type {HTML} from "../../../common/html.js";
import type {Html} from "../../../common/html.js";
import {html} from "../../../common/html.js";
import {generateNodeFromHTML} from "./base.js";
import {generateNodeFromHtml} from "./base.js";
import type {TabProps} from "./tab.js";
import Tab from "./tab.js";
@@ -18,7 +18,7 @@ export default class FunctionalTab extends Tab {
super(props);
this.$view = $view;
this.$el = generateNodeFromHTML(this.templateHTML());
this.$el = generateNodeFromHtml(this.templateHtml());
if (this.props.name !== "Settings") {
this.props.$root.append(this.$el);
this.$closeButton = this.$el.querySelector(".server-tab-badge")!;
@@ -41,7 +41,7 @@ export default class FunctionalTab extends Tab {
this.$view.remove();
}
templateHTML(): HTML {
templateHtml(): Html {
return html`
<div class="tab functional-tab" data-tab-id="${this.props.tabIndex}">
<div class="server-tab-badge close-button">

View File

@@ -1,8 +1,8 @@
import type {HTML} from "../../../common/html.js";
import type {Html} from "../../../common/html.js";
import {html} from "../../../common/html.js";
import {ipcRenderer} from "../typed-ipc-renderer.js";
import {generateNodeFromHTML} from "./base.js";
import {generateNodeFromHtml} from "./base.js";
import type {TabProps} from "./tab.js";
import Tab from "./tab.js";
import type WebView from "./webview.js";
@@ -20,7 +20,7 @@ export default class ServerTab extends Tab {
super(props);
this.webview = webview;
this.$el = generateNodeFromHTML(this.templateHTML());
this.$el = generateNodeFromHtml(this.templateHtml());
this.props.$root.append(this.$el);
this.registerListeners();
this.$badge = this.$el.querySelector(".server-tab-badge")!;
@@ -41,7 +41,7 @@ export default class ServerTab extends Tab {
(await this.webview).$el.remove();
}
templateHTML(): HTML {
templateHtml(): Html {
return html`
<div class="tab" data-tab-id="${this.props.tabIndex}">
<div class="server-tooltip" style="display:none">

View File

@@ -5,14 +5,14 @@ import * as remote from "@electron/remote";
import {app, dialog} from "@electron/remote";
import * as ConfigUtil from "../../../common/config-util.js";
import type {HTML} from "../../../common/html.js";
import type {Html} from "../../../common/html.js";
import {html} from "../../../common/html.js";
import type {RendererMessage} from "../../../common/typed-ipc.js";
import type {TabRole} from "../../../common/types.js";
import {ipcRenderer} from "../typed-ipc-renderer.js";
import * as SystemUtil from "../utils/system-util.js";
import {generateNodeFromHTML} from "./base.js";
import {generateNodeFromHtml} from "./base.js";
import {contextMenu} from "./context-menu.js";
import handleExternalLink from "./handle-external-link.js";
@@ -38,7 +38,7 @@ export default class WebView {
zoomFactor: number;
badgeCount: number;
loading: boolean;
customCSS: string | false | null;
customCss: string | false | null;
$webviewsContainer: DOMTokenList;
$el: HTMLElement;
webContentsId: number;
@@ -52,7 +52,7 @@ export default class WebView {
this.zoomFactor = 1;
this.loading = true;
this.badgeCount = 0;
this.customCSS = ConfigUtil.getConfigItem("customCSS", null);
this.customCss = ConfigUtil.getConfigItem("customCSS", null);
this.$webviewsContainer = document.querySelector(
"#webviews-container",
)!.classList;
@@ -62,7 +62,7 @@ export default class WebView {
this.registerListeners();
}
static templateHTML(props: WebViewProps): HTML {
static templateHtml(props: WebViewProps): Html {
return html`
<webview
data-tab-id="${props.tabIndex}"
@@ -77,8 +77,8 @@ export default class WebView {
}
static async create(props: WebViewProps): Promise<WebView> {
const $element = generateNodeFromHTML(
WebView.templateHTML(props),
const $element = generateNodeFromHtml(
WebView.templateHtml(props),
) as HTMLElement;
props.$root.append($element);
@@ -175,7 +175,7 @@ export default class WebView {
webContents.on("did-fail-load", (_event, _errorCode, errorDescription) => {
const hasConnectivityError =
SystemUtil.connectivityERR.includes(errorDescription);
SystemUtil.connectivityError.includes(errorDescription);
if (hasConnectivityError) {
console.error("error", errorDescription);
if (!this.props.url.includes("network.html")) {
@@ -225,11 +225,11 @@ export default class WebView {
))();
// Get customCSS again from config util to avoid warning user again
const customCSS = ConfigUtil.getConfigItem("customCSS", null);
this.customCSS = customCSS;
if (customCSS) {
if (!fs.existsSync(customCSS)) {
this.customCSS = null;
const customCss = ConfigUtil.getConfigItem("customCSS", null);
this.customCss = customCss;
if (customCss) {
if (!fs.existsSync(customCss)) {
this.customCss = null;
ConfigUtil.setConfigItem("customCSS", null);
const errorMessage = "The custom css previously set is deleted!";
@@ -239,7 +239,7 @@ export default class WebView {
(async () =>
this.getWebContents().insertCSS(
fs.readFileSync(path.resolve(__dirname, customCSS), "utf8"),
fs.readFileSync(path.resolve(__dirname, customCss), "utf8"),
))();
}
}

View File

@@ -73,20 +73,20 @@ bridgeEvents.on("realm_name", (realmName: unknown) => {
throw new TypeError("Expected string for realmName");
}
const serverURL = location.origin;
ipcRenderer.send("realm-name-changed", serverURL, realmName);
const serverUrl = location.origin;
ipcRenderer.send("realm-name-changed", serverUrl, realmName);
});
bridgeEvents.on("realm_icon_url", (iconURL: unknown) => {
if (typeof iconURL !== "string") {
throw new TypeError("Expected string for iconURL");
bridgeEvents.on("realm_icon_url", (iconUrl: unknown) => {
if (typeof iconUrl !== "string") {
throw new TypeError("Expected string for iconUrl");
}
const serverURL = location.origin;
const serverUrl = location.origin;
ipcRenderer.send(
"realm-icon-changed",
serverURL,
iconURL.includes("http") ? iconURL : `${serverURL}${iconURL}`,
serverUrl,
iconUrl.includes("http") ? iconUrl : `${serverUrl}${iconUrl}`,
);
});

View File

@@ -8,7 +8,7 @@ import * as Sentry from "@sentry/electron";
import type {Config} from "../../common/config-util.js";
import * as ConfigUtil from "../../common/config-util.js";
import * as DNDUtil from "../../common/dnd-util.js";
import type {DNDSettings} from "../../common/dnd-util.js";
import type {DndSettings} from "../../common/dnd-util.js";
import * as EnterpriseUtil from "../../common/enterprise-util.js";
import Logger from "../../common/logger-util.js";
import * as Messages from "../../common/messages.js";
@@ -123,7 +123,7 @@ export class ServerManagerView {
await this.loadProxy();
this.initDefaultSettings();
this.initSidebar();
this.removeUAfromDisk();
this.removeUaFromDisk();
if (EnterpriseUtil.hasConfigFile()) {
await this.initPresetOrgs();
}
@@ -231,7 +231,7 @@ export class ServerManagerView {
// Remove the stale UA string from the disk if the app is not freshly
// installed. This should be removed in a further release.
removeUAfromDisk(): void {
removeUaFromDisk(): void {
ConfigUtil.removeConfigItem("userAgent");
}
@@ -401,7 +401,7 @@ export class ServerManagerView {
}
initActions(): void {
this.initDNDButton();
this.initDndButton();
this.initServerActions();
this.initLeftSidebarEvents();
}
@@ -454,9 +454,9 @@ export class ServerManagerView {
this.sidebarHoverEvent(this.$dndButton, this.$dndTooltip);
}
initDNDButton(): void {
initDndButton(): void {
const dnd = ConfigUtil.getConfigItem("dnd", false);
this.toggleDNDButton(dnd);
this.toggleDndButton(dnd);
}
getTabIndex(): number {
@@ -776,7 +776,7 @@ export class ServerManagerView {
}
// Toggles the dnd button icon.
toggleDNDButton(alert: boolean): void {
toggleDndButton(alert: boolean): void {
this.$dndTooltip.textContent =
(alert ? "Disable" : "Enable") + " Do Not Disturb";
this.$dndButton.querySelector("i")!.textContent = alert
@@ -1029,9 +1029,9 @@ export class ServerManagerView {
async (
event: Event,
state: boolean,
newSettings: Partial<DNDSettings>,
newSettings: Partial<DndSettings>,
) => {
this.toggleDNDButton(state);
this.toggleDndButton(state);
ipcRenderer.send(
"forward-message",
"toggle-silent",

View File

@@ -1,6 +1,6 @@
import type {HTML} from "../../../../common/html.js";
import type {Html} from "../../../../common/html.js";
import {html} from "../../../../common/html.js";
import {generateNodeFromHTML} from "../../components/base.js";
import {generateNodeFromHtml} from "../../components/base.js";
import {ipcRenderer} from "../../typed-ipc-renderer.js";
interface BaseSectionProps {
@@ -15,8 +15,8 @@ export function generateSettingOption(props: BaseSectionProps): void {
$element.textContent = "";
const $optionControl = generateNodeFromHTML(
generateOptionHTML(value, disabled),
const $optionControl = generateNodeFromHtml(
generateOptionHtml(value, disabled),
);
$element.append($optionControl);
@@ -25,11 +25,11 @@ export function generateSettingOption(props: BaseSectionProps): void {
}
}
export function generateOptionHTML(
export function generateOptionHtml(
settingOption: boolean,
disabled?: boolean,
): HTML {
const labelHTML = disabled
): Html {
const labelHtml = disabled
? html`<label
class="disallowed"
title="Setting locked by system administrator."
@@ -40,7 +40,7 @@ export function generateOptionHTML(
<div class="action">
<div class="switch">
<input class="toggle toggle-round" type="checkbox" checked disabled />
${labelHTML}
${labelHtml}
</div>
</div>
`;
@@ -50,7 +50,7 @@ export function generateOptionHTML(
<div class="action">
<div class="switch">
<input class="toggle toggle-round" type="checkbox" />
${labelHTML}
${labelHtml}
</div>
</div>
`;
@@ -59,12 +59,12 @@ export function generateOptionHTML(
/* A method that in future can be used to create dropdown menus using <select> <option> tags.
it needs an object which has ``key: value`` pairs and will return a string that can be appended to HTML
*/
export function generateSelectHTML(
export function generateSelectHtml(
options: Record<string, string>,
className?: string,
idName?: string,
): HTML {
const optionsHTML = html``.join(
): Html {
const optionsHtml = html``.join(
Object.keys(options).map(
(key) => html`
<option name="${key}" value="${key}">${options[key]}</option>
@@ -73,7 +73,7 @@ export function generateSelectHTML(
);
return html`
<select class="${className}" id="${idName}">
${optionsHTML}
${optionsHtml}
</select>
`;
}

View File

@@ -1,6 +1,6 @@
import {html} from "../../../../common/html.js";
import * as t from "../../../../common/translation-util.js";
import {generateNodeFromHTML} from "../../components/base.js";
import {generateNodeFromHtml} from "../../components/base.js";
import * as LinkUtil from "../../utils/link-util.js";
interface FindAccountsProps {
@@ -20,7 +20,7 @@ async function findAccounts(url: string): Promise<void> {
}
export function initFindAccounts(props: FindAccountsProps): void {
const $findAccounts = generateNodeFromHTML(html`
const $findAccounts = generateNodeFromHtml(html`
<div class="settings-card certificate-card">
<div class="certificate-input">
<div>${t.__("Organization URL")}</div>

View File

@@ -15,7 +15,7 @@ import * as t from "../../../../common/translation-util.js";
import supportedLocales from "../../../../translations/supported-locales.json";
import {ipcRenderer} from "../../typed-ipc-renderer.js";
import {generateSelectHTML, generateSettingOption} from "./base-section.js";
import {generateSelectHtml, generateSettingOption} from "./base-section.js";
const currentBrowserWindow = remote.getCurrentWindow();
@@ -222,9 +222,9 @@ export function initGeneralSection({$root}: GeneralSectionProps): void {
showDesktopNotification();
enableSpellchecker();
minimizeOnStart();
addCustomCSS();
showCustomCSSPath();
removeCustomCSS();
addCustomCss();
showCustomCssPath();
removeCustomCss();
downloadFolder();
updateQuitOnCloseOption();
updatePromptDownloadOption();
@@ -470,8 +470,8 @@ export function initGeneralSection({$root}: GeneralSectionProps): void {
function setLocale(): void {
const langDiv: HTMLSelectElement = $root.querySelector(".lang-div")!;
const langListHTML = generateSelectHTML(supportedLocales, "lang-menu");
langDiv.innerHTML += langListHTML.html;
const langListHtml = generateSelectHtml(supportedLocales, "lang-menu");
langDiv.innerHTML += langListHtml.html;
// `langMenu` is the select-option dropdown menu formed after executing the previous command
const langMenu: HTMLSelectElement = $root.querySelector(".lang-menu")!;
@@ -498,25 +498,25 @@ export function initGeneralSection({$root}: GeneralSectionProps): void {
});
}
function addCustomCSS(): void {
const customCSSButton = $root.querySelector(
function addCustomCss(): void {
const customCssButton = $root.querySelector(
"#add-custom-css .custom-css-button",
)!;
customCSSButton.addEventListener("click", async () => {
customCssButton.addEventListener("click", async () => {
await customCssDialog();
});
}
function showCustomCSSPath(): void {
function showCustomCssPath(): void {
if (!ConfigUtil.getConfigItem("customCSS", null)) {
const cssPATH: HTMLElement = $root.querySelector("#remove-custom-css")!;
cssPATH.style.display = "none";
const cssPath: HTMLElement = $root.querySelector("#remove-custom-css")!;
cssPath.style.display = "none";
}
}
function removeCustomCSS(): void {
const removeCSSButton = $root.querySelector("#css-delete-action")!;
removeCSSButton.addEventListener("click", () => {
function removeCustomCss(): void {
const removeCssButton = $root.querySelector("#css-delete-action")!;
removeCssButton.addEventListener("click", () => {
ConfigUtil.setConfigItem("customCSS", "");
ipcRenderer.send("forward-message", "hard-reload");
});

View File

@@ -1,8 +1,8 @@
import type {HTML} from "../../../../common/html.js";
import type {Html} from "../../../../common/html.js";
import {html} from "../../../../common/html.js";
import * as t from "../../../../common/translation-util.js";
import type {NavItem} from "../../../../common/types.js";
import {generateNodeFromHTML} from "../../components/base.js";
import {generateNodeFromHtml} from "../../components/base.js";
interface PreferenceNavProps {
$root: Element;
@@ -23,13 +23,13 @@ export default class PreferenceNav {
"Shortcuts",
];
this.$el = generateNodeFromHTML(this.templateHTML());
this.$el = generateNodeFromHtml(this.templateHtml());
this.props.$root.append(this.$el);
this.registerListeners();
}
templateHTML(): HTML {
const navItemsHTML = html``.join(
templateHtml(): Html {
const navItemsHtml = html``.join(
this.navItems.map(
(navItem) => html`
<div class="nav" id="nav-${navItem}">${t.__(navItem)}</div>
@@ -40,7 +40,7 @@ export default class PreferenceNav {
return html`
<div>
<div id="settings-header">${t.__("Settings")}</div>
<div id="nav-container">${navItemsHTML}</div>
<div id="nav-container">${navItemsHtml}</div>
</div>
`;
}

View File

@@ -55,7 +55,7 @@ export function initNetworkSection({$root}: NetworkSectionProps): void {
</div>
`.html;
const $proxyPAC: HTMLInputElement = $root.querySelector(
const $proxyPac: HTMLInputElement = $root.querySelector(
"#proxy-pac-option .setting-input-value",
)!;
const $proxyRules: HTMLInputElement = $root.querySelector(
@@ -70,12 +70,12 @@ export function initNetworkSection({$root}: NetworkSectionProps): void {
toggleManualProxySettings(ConfigUtil.getConfigItem("useManualProxy", false));
updateProxyOption();
$proxyPAC.value = ConfigUtil.getConfigItem("proxyPAC", "");
$proxyPac.value = ConfigUtil.getConfigItem("proxyPAC", "");
$proxyRules.value = ConfigUtil.getConfigItem("proxyRules", "");
$proxyBypass.value = ConfigUtil.getConfigItem("proxyBypass", "");
$proxySaveAction.addEventListener("click", () => {
ConfigUtil.setConfigItem("proxyPAC", $proxyPAC.value);
ConfigUtil.setConfigItem("proxyPAC", $proxyPac.value);
ConfigUtil.setConfigItem("proxyRules", $proxyRules.value);
ConfigUtil.setConfigItem("proxyBypass", $proxyBypass.value);

View File

@@ -2,7 +2,7 @@ import {dialog} from "@electron/remote";
import {html} from "../../../../common/html.js";
import * as t from "../../../../common/translation-util.js";
import {generateNodeFromHTML} from "../../components/base.js";
import {generateNodeFromHtml} from "../../components/base.js";
import {ipcRenderer} from "../../typed-ipc-renderer.js";
import * as DomainUtil from "../../utils/domain-util.js";
import * as LinkUtil from "../../utils/link-util.js";
@@ -13,7 +13,7 @@ interface NewServerFormProps {
}
export function initNewServerForm({$root, onChange}: NewServerFormProps): void {
const $newServerForm = generateNodeFromHTML(html`
const $newServerForm = generateNodeFromHtml(html`
<div class="server-input-container">
<div class="title">${t.__("Organization URL")}</div>
<div class="add-server-info-row">

View File

@@ -1,4 +1,4 @@
import type {DNDSettings} from "../../../../common/dnd-util.js";
import type {DndSettings} from "../../../../common/dnd-util.js";
import {html} from "../../../../common/html.js";
import type {NavItem} from "../../../../common/types.js";
import {ipcRenderer} from "../../typed-ipc-renderer.js";
@@ -129,7 +129,7 @@ export class PreferenceView {
private readonly handleToggleDnd = (
_event: Event,
_state: boolean,
newSettings: Partial<DNDSettings>,
newSettings: Partial<DndSettings>,
) => {
this.handleToggle("show-notification-option", newSettings.showNotification);
this.handleToggle("silent-option", newSettings.silent);

View File

@@ -4,7 +4,7 @@ import {html} from "../../../../common/html.js";
import * as Messages from "../../../../common/messages.js";
import * as t from "../../../../common/translation-util.js";
import type {ServerConf} from "../../../../common/types.js";
import {generateNodeFromHTML} from "../../components/base.js";
import {generateNodeFromHtml} from "../../components/base.js";
import {ipcRenderer} from "../../typed-ipc-renderer.js";
import * as DomainUtil from "../../utils/domain-util.js";
@@ -16,7 +16,7 @@ interface ServerInfoFormProps {
}
export function initServerInfoForm(props: ServerInfoFormProps): void {
const $serverInfoForm = generateNodeFromHTML(html`
const $serverInfoForm = generateNodeFromHtml(html`
<div class="settings-card">
<div class="server-info-left">
<img class="server-info-icon" src="${props.server.icon}" />

View File

@@ -11,23 +11,23 @@ import {ipcRenderer} from "./typed-ipc-renderer.js";
let tray: Electron.Tray | null = null;
const ICON_DIR = "../../resources/tray";
const iconDir = "../../resources/tray";
const TRAY_SUFFIX = "tray";
const traySuffix = "tray";
const APP_ICON = path.join(__dirname, ICON_DIR, TRAY_SUFFIX);
const appIcon = path.join(__dirname, iconDir, traySuffix);
const iconPath = (): string => {
if (process.platform === "linux") {
return APP_ICON + "linux.png";
return appIcon + "linux.png";
}
return (
APP_ICON + (process.platform === "win32" ? "win.ico" : "macOSTemplate.png")
appIcon + (process.platform === "win32" ? "win.ico" : "macOSTemplate.png")
);
};
const winUnreadTrayIconPath = (): string => APP_ICON + "unread.ico";
const winUnreadTrayIconPath = (): string => appIcon + "unread.ico";
let unread = 0;
@@ -60,42 +60,42 @@ const config = {
const renderCanvas = function (arg: number): HTMLCanvasElement {
config.unreadCount = arg;
const SIZE = config.size * config.pixelRatio;
const PADDING = SIZE * 0.05;
const CENTER = SIZE / 2;
const HAS_COUNT = config.showUnreadCount && config.unreadCount;
const size = config.size * config.pixelRatio;
const padding = size * 0.05;
const center = size / 2;
const hasCount = config.showUnreadCount && config.unreadCount;
const color = config.unreadCount ? config.unreadColor : config.readColor;
const backgroundColor = config.unreadCount
? config.unreadBackgroundColor
: config.readBackgroundColor;
const canvas = document.createElement("canvas");
canvas.width = SIZE;
canvas.height = SIZE;
canvas.width = size;
canvas.height = size;
const ctx = canvas.getContext("2d")!;
// Circle
// If (!config.thick || config.thick && HAS_COUNT) {
// If (!config.thick || config.thick && hasCount) {
ctx.beginPath();
ctx.arc(CENTER, CENTER, SIZE / 2 - PADDING, 0, 2 * Math.PI, false);
ctx.arc(center, center, size / 2 - padding, 0, 2 * Math.PI, false);
ctx.fillStyle = backgroundColor;
ctx.fill();
ctx.lineWidth = SIZE / (config.thick ? 10 : 20);
ctx.lineWidth = size / (config.thick ? 10 : 20);
ctx.strokeStyle = backgroundColor;
ctx.stroke();
// Count or Icon
if (HAS_COUNT) {
if (hasCount) {
ctx.fillStyle = color;
ctx.textAlign = "center";
if (config.unreadCount > 99) {
ctx.font = `${config.thick ? "bold " : ""}${SIZE * 0.4}px Helvetica`;
ctx.fillText("99+", CENTER, CENTER + SIZE * 0.15);
ctx.font = `${config.thick ? "bold " : ""}${size * 0.4}px Helvetica`;
ctx.fillText("99+", center, center + size * 0.15);
} else if (config.unreadCount < 10) {
ctx.font = `${config.thick ? "bold " : ""}${SIZE * 0.5}px Helvetica`;
ctx.fillText(String(config.unreadCount), CENTER, CENTER + SIZE * 0.2);
ctx.font = `${config.thick ? "bold " : ""}${size * 0.5}px Helvetica`;
ctx.fillText(String(config.unreadCount), center, center + size * 0.2);
} else {
ctx.font = `${config.thick ? "bold " : ""}${SIZE * 0.5}px Helvetica`;
ctx.fillText(String(config.unreadCount), CENTER, CENTER + SIZE * 0.15);
ctx.font = `${config.thick ? "bold " : ""}${size * 0.5}px Helvetica`;
ctx.fillText(String(config.unreadCount), center, center + size * 0.15);
}
}

View File

@@ -27,7 +27,7 @@ const serverConfSchema = z.object({
let db!: JsonDB;
reloadDB();
reloadDb();
// Migrate from old schema
try {
@@ -46,7 +46,7 @@ try {
}
export function getDomains(): ServerConf[] {
reloadDB();
reloadDb();
try {
return serverConfSchema.array().parse(db.getObject<unknown>("/domains"));
} catch (error: unknown) {
@@ -56,12 +56,12 @@ export function getDomains(): ServerConf[] {
}
export function getDomain(index: number): ServerConf {
reloadDB();
reloadDb();
return serverConfSchema.parse(db.getObject<unknown>(`/domains[${index}]`));
}
export function updateDomain(index: number, server: ServerConf): void {
reloadDB();
reloadDb();
serverConfSchema.parse(server);
db.push(`/domains[${index}]`, server, true);
}
@@ -76,18 +76,18 @@ export async function addDomain(server: {
server.icon = localIconUrl;
serverConfSchema.parse(server);
db.push("/domains[]", server, true);
reloadDB();
reloadDb();
} else {
server.icon = defaultIconUrl;
serverConfSchema.parse(server);
db.push("/domains[]", server, true);
reloadDB();
reloadDb();
}
}
export function removeDomains(): void {
db.delete("/domains");
reloadDB();
reloadDb();
}
export function removeDomain(index: number): boolean {
@@ -96,7 +96,7 @@ export function removeDomain(index: number): boolean {
}
db.delete(`/domains[${index}]`);
reloadDB();
reloadDb();
return true;
}
@@ -144,7 +144,7 @@ export async function updateSavedServer(
if (!oldIcon || localIconUrl !== "../renderer/img/icon.png") {
newServerConf.icon = localIconUrl;
updateDomain(index, newServerConf);
reloadDB();
reloadDb();
}
} catch (error: unknown) {
logger.log("Could not update server icon.");
@@ -153,7 +153,7 @@ export async function updateSavedServer(
}
}
function reloadDB(): void {
function reloadDb(): void {
const domainJsonPath = path.join(
app.getPath("userData"),
"config/domain.json",

View File

@@ -1,6 +1,6 @@
import {ipcRenderer} from "../typed-ipc-renderer.js";
export const connectivityERR: string[] = [
export const connectivityError: string[] = [
"ERR_INTERNET_DISCONNECTED",
"ERR_PROXY_CONNECTION_FAILED",
"ERR_CONNECTION_RESET",