Skip to content

Path cleanups #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/common/config-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function removeConfigItem(key: string): void {
function reloadDB(): void {
const settingsJsonPath = path.join(
app.getPath("userData"),
"/config/settings.json",
"config/settings.json",
);
try {
const file = fs.readFileSync(settingsJsonPath, "utf8");
Expand Down
16 changes: 6 additions & 10 deletions app/common/default-util.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import electron from "electron";
import fs from "fs";
import path from "path";

const {app} = process.type === "renderer" ? electron.remote : electron;

let setupCompleted = false;

const zulipDir = app.getPath("userData");
const logDir = `${zulipDir}/Logs/`;
const configDir = `${zulipDir}/config/`;
const configDir = path.join(zulipDir, "config");
export const initSetUp = (): void => {
// If it is the first time the app is running
// create zulip dir in userData folder to
Expand All @@ -17,18 +17,14 @@ export const initSetUp = (): void => {
fs.mkdirSync(zulipDir);
}

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

// 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`;
const domainJson = path.join(zulipDir, "domain.json");
const settingsJson = path.join(zulipDir, "settings.json");
const updatesJson = path.join(zulipDir, "updates.json");
const windowStateJson = path.join(zulipDir, "window-state.json");
const configData = [
{
path: domainJson,
Expand Down
5 changes: 3 additions & 2 deletions app/common/logger-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Console} from "console"; // eslint-disable-line node/prefer-global/conso
import electron from "electron";
import fs from "fs";
import os from "os";
import path from "path";

import {initSetUp} from "./default-util";
import {captureException, sentryInit} from "./sentry-util";
Expand Down Expand Up @@ -32,7 +33,7 @@ if (process.type === "renderer") {
);
}

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

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

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

file = `${logDir}/${file}`;
file = path.join(logDir, file);

// Trim log according to type of process
if (process.type === "renderer") {
Expand Down
8 changes: 4 additions & 4 deletions app/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ let badgeCount: number;

let isQuitting = false;

// Load this url in main window
const mainURL = "file://" + path.join(__dirname, "../renderer", "main.html");
// Load this file in main window
const mainFile = "app/renderer/main.html";

const permissionCallbacks = new Map<number, (grant: boolean) => void>();
let nextPermissionCallbackId = 0;
Expand All @@ -52,7 +52,7 @@ function createMainWindow(): Electron.BrowserWindow {
mainWindowState = windowStateKeeper({
defaultWidth: 1100,
defaultHeight: 720,
path: `${app.getPath("userData")}/config`,
path: path.join(app.getPath("userData"), "config"),
});

const win = new electron.BrowserWindow({
Expand Down Expand Up @@ -80,7 +80,7 @@ function createMainWindow(): Electron.BrowserWindow {
send(win.webContents, "focus");
});

(async () => win.loadURL(mainURL))();
(async () => win.loadFile(mainFile))();

// Keep the app running in background on close event
win.on("close", (event) => {
Expand Down
2 changes: 1 addition & 1 deletion app/main/linux-update-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function removeUpdateItem(key: string): void {
function reloadDB(): void {
const linuxUpdateJsonPath = path.join(
app.getPath("userData"),
"/config/updates.json",
"config/updates.json",
);
try {
const file = fs.readFileSync(linuxUpdateJsonPath, "utf8");
Expand Down
12 changes: 7 additions & 5 deletions app/main/menu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {BrowserWindow, Menu, app, shell} from "electron";
import * as path from "path";

import AdmZip from "adm-zip";

Expand Down Expand Up @@ -68,13 +69,14 @@ function getToolsSubmenu(): Electron.MenuItemConstructorOptions[] {
const dateString = date.toLocaleDateString().replace(/\//g, "-");

// Create a zip file of all the logs and config data
zip.addLocalFolder(`${app.getPath("appData")}/${appName}/Logs`);
zip.addLocalFolder(`${app.getPath("appData")}/${appName}/config`);
zip.addLocalFolder(app.getPath("logs"));
zip.addLocalFolder(path.join(app.getPath("userData"), "config"));

// Put the log file in downloads folder
const logFilePath = `${app.getPath(
"downloads",
)}/Zulip-logs-${dateString}.zip`;
const logFilePath = path.join(
app.getPath("downloads"),
`Zulip-logs-${dateString}.zip`,
);
zip.writeZip(logFilePath);

// Open and select the log file
Expand Down
4 changes: 2 additions & 2 deletions app/main/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const logger = new Logger({
});

const generateFilePath = (url: string): string => {
const dir = `${app.getPath("userData")}/server-icons`;
const dir = path.join(app.getPath("userData"), "server-icons");
const extension = path.extname(url).split("?")[0];

let hash = 5381;
Expand All @@ -51,7 +51,7 @@ const generateFilePath = (url: string): string => {
fs.mkdirSync(dir);
}

return `${dir}/${hash >>> 0}${extension}`;
return path.join(dir, `${hash >>> 0}${extension}`);
};

export const _getServerSettings = async (
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/js/components/handle-external-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function handleExternalLink(
const url = new URL(event.url);
const downloadPath = ConfigUtil.getConfigItem(
"downloadsPath",
`${app.getPath("downloads")}`,
app.getPath("downloads"),
);

if (LinkUtil.isUploadsUrl(this.props.url, url)) {
Expand Down
3 changes: 1 addition & 2 deletions app/renderer/js/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ sendFeedback.addEventListener("feedback-cancelled", () => {
feedbackHolder.classList.remove("show");
});

const dataDir = app.getPath("userData");
const logsDir = path.join(dataDir, "/Logs");
const logsDir = app.getPath("logs");
sendFeedback.logs.push(
...fs.readdirSync(logsDir).map((file) => path.join(logsDir, file)),
);
2 changes: 1 addition & 1 deletion app/renderer/js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class ServerManagerView {
showNotification: true,
silent: false,
},
downloadsPath: `${app.getPath("downloads")}`,
downloadsPath: app.getPath("downloads"),
quitOnClose: false,
promptDownload: false,
};
Expand Down
4 changes: 2 additions & 2 deletions scripts/notarize.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require("path");
const dotenv = require("dotenv");
const {notarize} = require("electron-notarize");

dotenv.config({path: path.join(__dirname, "/../.env")});
dotenv.config({path: path.join(__dirname, "../.env")});

exports.default = async function (context) {
const {electronPlatformName, appOutDir} = context;
Expand All @@ -16,7 +16,7 @@ exports.default = async function (context) {

return notarize({
appBundleId: "org.zulip.zulip-electron",
appPath: `${appOutDir}/${appName}.app`,
appPath: path.join(appOutDir, `${appName}.app`),
appleId: process.env.APPLE_ID,
appleIdPassword: process.env.APPLE_ID_PASS,
ascProvider: process.env.ASC_PROVIDER, // Team short name
Expand Down