Skip to content

Commit

Permalink
Merge branch 'zulip:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jonassorgenfrei authored Dec 27, 2024
2 parents acde121 + 13f3818 commit 1b6c0fc
Show file tree
Hide file tree
Showing 104 changed files with 11,920 additions and 8,230 deletions.
51 changes: 41 additions & 10 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
---
<!-- Describe your pull request here.-->

<!--
Remove the fields that are not appropriate
Please include:
-->
Fixes: <!-- Issue link, or clear description.-->

**What's this PR do?**
<!-- If the PR makes UI changes, always include one or more still screenshots to demonstrate your changes. If it seems helpful, add a screen capture of the new functionality as well.
**Any background context you want to provide?**
Tooling tips: https://zulip.readthedocs.io/en/latest/tutorials/screenshot-and-gif-software.html
-->

**Screenshots?**
**Screenshots and screen captures:**

**You have tested this PR on:**
**Platforms this PR was tested on:**

- [ ] Windows
- [ ] Linux/Ubuntu
- [ ] macOS
- [ ] Linux (specify distro)

<details>
<summary>Self-review checklist</summary>

<!-- Prior to submitting a PR, follow our step-by-step guide to review your own code:
https://zulip.readthedocs.io/en/latest/contributing/code-reviewing.html#how-to-review-code -->

<!-- Once you create the PR, check off all the steps below that you have completed.
If any of these steps are not relevant or you have not completed, leave them unchecked.-->

- [ ] [Self-reviewed](https://zulip.readthedocs.io/en/latest/contributing/code-reviewing.html#how-to-review-code) the changes for clarity and maintainability
(variable names, code reuse, readability, etc.).

Communicate decisions, questions, and potential concerns.

- [ ] Explains differences from previous plans (e.g., issue description).
- [ ] Highlights technical choices and bugs encountered.
- [ ] Calls out remaining decisions and concerns.
- [ ] Automated tests verify logic where appropriate.

Individual commits are ready for review (see [commit discipline](https://zulip.readthedocs.io/en/latest/contributing/commit-discipline.html)).

- [ ] Each commit is a coherent idea.
- [ ] Commit message(s) explain reasoning and motivation for changes.

Completed manual review and testing of the following:

- [ ] Visual appearance of the changes.
- [ ] Responsiveness and internationalization.
- [ ] Strings and tooltips.
- [ ] End-to-end functionality of buttons, interactions and flows.
- [ ] Corner cases, error conditions, and easily imagined bugs.
</details>
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- run: npm ci
- run: npm test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Zulip Desktop Client

[![Build Status](https://travis-ci.com/zulip/zulip-desktop.svg?branch=main)](https://travis-ci.com/github/zulip/zulip-desktop)
[![Build Status](https://github.com/zulip/zulip-desktop/actions/workflows/node.js.yml/badge.svg)](https://github.com/zulip/zulip-desktop/actions/workflows/node.js.yml?query=branch%3Amain)
[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/zulip/zulip-desktop?branch=main&svg=true)](https://ci.appveyor.com/project/zulip/zulip-desktop/branch/main)
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)
[![project chat](https://img.shields.io/badge/zulip-join_chat-brightgreen.svg)](https://chat.zulip.org)
Expand Down
26 changes: 13 additions & 13 deletions app/common/config-util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "node:fs";
import path from "node:path";

import * as Sentry from "@sentry/electron";
import * as Sentry from "@sentry/core";
import {JsonDB} from "node-json-db";
import {DataError} from "node-json-db/dist/lib/Errors";
import type {z} from "zod";
Expand All @@ -19,23 +19,23 @@ const logger = new Logger({
file: "config-util.log",
});

let db: JsonDB;
let database: JsonDB;

reloadDb();
reloadDatabase();

export function getConfigItem<Key extends keyof Config>(
key: Key,
defaultValue: Config[Key],
): z.output<(typeof configSchemata)[Key]> {
try {
db.reload();
database.reload();
} catch (error: unknown) {
logger.error("Error while reloading settings.json: ");
logger.error(error);
}

try {
return configSchemata[key].parse(db.getObject<unknown>(`/${key}`));
return configSchemata[key].parse(database.getObject<unknown>(`/${key}`));
} catch (error: unknown) {
if (!(error instanceof DataError)) throw error;
setConfigItem(key, defaultValue);
Expand All @@ -46,13 +46,13 @@ export function getConfigItem<Key extends keyof Config>(
// This function returns whether a key exists in the configuration file (settings.json)
export function isConfigItemExists(key: string): boolean {
try {
db.reload();
database.reload();
} catch (error: unknown) {
logger.error("Error while reloading settings.json: ");
logger.error(error);
}

return db.exists(`/${key}`);
return database.exists(`/${key}`);
}

export function setConfigItem<Key extends keyof Config>(
Expand All @@ -66,16 +66,16 @@ export function setConfigItem<Key extends keyof Config>(
}

configSchemata[key].parse(value);
db.push(`/${key}`, value, true);
db.save();
database.push(`/${key}`, value, true);
database.save();
}

export function removeConfigItem(key: string): void {
db.delete(`/${key}`);
db.save();
database.delete(`/${key}`);
database.save();
}

function reloadDb(): void {
function reloadDatabase(): void {
const settingsJsonPath = path.join(
app.getPath("userData"),
"/config/settings.json",
Expand All @@ -96,5 +96,5 @@ function reloadDb(): void {
}
}

db = new JsonDB(settingsJsonPath, true, true);
database = new JsonDB(settingsJsonPath, true, true);
}
28 changes: 14 additions & 14 deletions app/common/default-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ import {app} from "zulip:remote";

let setupCompleted = false;

const zulipDir = app.getPath("userData");
const logDir = `${zulipDir}/Logs/`;
const configDir = `${zulipDir}/config/`;
const zulipDirectory = app.getPath("userData");
const logDirectory = `${zulipDirectory}/Logs/`;
const configDirectory = `${zulipDirectory}/config/`;
export const initSetUp = (): void => {
// If it is the first time the app is running
// create zulip dir in userData folder to
// avoid errors
if (!setupCompleted) {
if (!fs.existsSync(zulipDir)) {
fs.mkdirSync(zulipDir);
if (!fs.existsSync(zulipDirectory)) {
fs.mkdirSync(zulipDirectory);
}

if (!fs.existsSync(logDir)) {
fs.mkdirSync(logDir);
if (!fs.existsSync(logDirectory)) {
fs.mkdirSync(logDirectory);
}

// Migrate config files from app data folder to config folder inside app
// data folder. This will be done once when a user updates to the new version.
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir);
const domainJson = `${zulipDir}/domain.json`;
const settingsJson = `${zulipDir}/settings.json`;
const updatesJson = `${zulipDir}/updates.json`;
const windowStateJson = `${zulipDir}/window-state.json`;
if (!fs.existsSync(configDirectory)) {
fs.mkdirSync(configDirectory);
const domainJson = `${zulipDirectory}/domain.json`;
const settingsJson = `${zulipDirectory}/settings.json`;
const updatesJson = `${zulipDirectory}/updates.json`;
const windowStateJson = `${zulipDirectory}/window-state.json`;
const configData = [
{
path: domainJson,
Expand All @@ -44,7 +44,7 @@ export const initSetUp = (): void => {
];
for (const data of configData) {
if (fs.existsSync(data.path)) {
fs.copyFileSync(data.path, configDir + data.fileName);
fs.copyFileSync(data.path, configDirectory + data.fileName);
fs.unlinkSync(data.path);
}
}
Expand Down
8 changes: 4 additions & 4 deletions app/common/enterprise-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const logger = new Logger({
let enterpriseSettings: Partial<EnterpriseConfig>;
let configFile: boolean;

reloadDb();
reloadDatabase();

function reloadDb(): void {
function reloadDatabase(): void {
let enterpriseFile = "/etc/zulip-desktop-config/global_config.json";
if (process.platform === "win32") {
enterpriseFile =
Expand Down Expand Up @@ -56,7 +56,7 @@ export function getConfigItem<Key extends keyof EnterpriseConfig>(
key: Key,
defaultValue: EnterpriseConfig[Key],
): EnterpriseConfig[Key] {
reloadDb();
reloadDatabase();
if (!configFile) {
return defaultValue;
}
Expand All @@ -66,7 +66,7 @@ export function getConfigItem<Key extends keyof EnterpriseConfig>(
}

export function configItemExists(key: keyof EnterpriseConfig): boolean {
reloadDb();
reloadDatabase();
if (!configFile) {
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions app/common/link-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export async function openBrowser(url: URL): Promise<void> {
} else {
// For security, indirect links to non-whitelisted protocols
// through a real web browser via a local HTML file.
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "zulip-redirect-"));
const file = path.join(dir, "redirect.html");
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "zulip-redirect-"));
const file = path.join(directory, "redirect.html");
fs.writeFileSync(
file,
html`
<!DOCTYPE html>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
Expand All @@ -45,7 +45,7 @@ export async function openBrowser(url: URL): Promise<void> {
await shell.openPath(file);
setTimeout(() => {
fs.unlinkSync(file);
fs.rmdirSync(dir);
fs.rmdirSync(directory);
}, 15_000);
}
}
34 changes: 17 additions & 17 deletions app/common/logger-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type LoggerOptions = {

initSetUp();

const logDir = `${app.getPath("userData")}/Logs`;
const logDirectory = `${app.getPath("userData")}/Logs`;

type Level = "log" | "debug" | "info" | "warn" | "error";

Expand All @@ -23,7 +23,7 @@ export default class Logger {
constructor(options: LoggerOptions = {}) {
let {file = "console.log"} = options;

file = `${logDir}/${file}`;
file = `${logDirectory}/${file}`;

// Trim log according to type of process
if (process.type === "renderer") {
Expand All @@ -38,31 +38,31 @@ export default class Logger {
this.nodeConsole = nodeConsole;
}

_log(type: Level, ...args: unknown[]): void {
args.unshift(this.getTimestamp() + " |\t");
args.unshift(type.toUpperCase() + " |");
this.nodeConsole[type](...args);
console[type](...args);
_log(type: Level, ...arguments_: unknown[]): void {
arguments_.unshift(this.getTimestamp() + " |\t");
arguments_.unshift(type.toUpperCase() + " |");
this.nodeConsole[type](...arguments_);
console[type](...arguments_);
}

log(...args: unknown[]): void {
this._log("log", ...args);
log(...arguments_: unknown[]): void {
this._log("log", ...arguments_);
}

debug(...args: unknown[]): void {
this._log("debug", ...args);
debug(...arguments_: unknown[]): void {
this._log("debug", ...arguments_);
}

info(...args: unknown[]): void {
this._log("info", ...args);
info(...arguments_: unknown[]): void {
this._log("info", ...arguments_);
}

warn(...args: unknown[]): void {
this._log("warn", ...args);
warn(...arguments_: unknown[]): void {
this._log("warn", ...arguments_);
}

error(...args: unknown[]): void {
this._log("error", ...args);
error(...arguments_: unknown[]): void {
this._log("error", ...arguments_);
}

getTimestamp(): string {
Expand Down
8 changes: 4 additions & 4 deletions app/common/typed-ipc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {DndSettings} from "./dnd-util.js";
import type {MenuProps, ServerConf} from "./types.js";
import type {MenuProperties, ServerConfig} from "./types.js";

export type MainMessage = {
"clear-app-settings": () => void;
Expand All @@ -21,12 +21,12 @@ export type MainMessage = {
toggleAutoLauncher: (AutoLaunchValue: boolean) => void;
"unread-count": (unreadCount: number) => void;
"update-badge": (messageCount: number) => void;
"update-menu": (props: MenuProps) => void;
"update-menu": (properties: MenuProperties) => void;
"update-taskbar-icon": (data: string, text: string) => void;
};

export type MainCall = {
"get-server-settings": (domain: string) => ServerConf;
"get-server-settings": (domain: string) => ServerConfig;
"is-online": (url: string) => boolean;
"poll-clipboard": (key: Uint8Array, sig: Uint8Array) => string | undefined;
"save-server-icon": (iconURL: string) => string | null;
Expand Down Expand Up @@ -74,7 +74,7 @@ export type RendererMessage = {
"toggle-silent": (state: boolean) => void;
"toggle-tray": (state: boolean) => void;
toggletray: () => void;
tray: (arg: number) => void;
tray: (argument: number) => void;
"update-realm-icon": (serverURL: string, iconURL: string) => void;
"update-realm-name": (serverURL: string, realmName: string) => void;
"webview-reload": () => void;
Expand Down
10 changes: 6 additions & 4 deletions app/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export type MenuProps = {
export type MenuProperties = {
tabs: TabData[];
activeTabIndex?: number;
enableMenu?: boolean;
};

export type NavItem =
export type NavigationItem =
| "General"
| "Network"
| "AddServer"
| "Organizations"
| "Shortcuts";

export type ServerConf = {
export type ServerConfig = {
url: string;
alias: string;
icon: string;
Expand All @@ -20,9 +20,11 @@ export type ServerConf = {
};

export type TabRole = "server" | "function";
export type TabPage = "Settings" | "About";

export type TabData = {
role: TabRole;
name: string;
page?: TabPage;
label: string;
index: number;
};
Loading

0 comments on commit 1b6c0fc

Please sign in to comment.