Skip to content

Commit

Permalink
Merge pull request #875 from pano9000/refactor_isMac_isWin
Browse files Browse the repository at this point in the history
refactor(utils): add isMac and isWindows util functions
  • Loading branch information
eliandoran authored Jan 2, 2025
2 parents 6a9c8ff + ac77d20 commit 6825fe2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/services/keyboard_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import optionService from "./options.js";
import log from "./log.js";
import { isElectron as getIsElectron } from "./utils.js";
import { isElectron as getIsElectron, isMac as getIsMac } from "./utils.js";
import { KeyboardShortcut } from './keyboard_actions_interface.js';
import { t } from "i18next";

const isMac = process.platform === "darwin";
const isMac = getIsMac();
const isElectron = getIsElectron();

function getDefaultKeyboardActions() {
Expand Down
3 changes: 2 additions & 1 deletion src/services/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Request, Response } from "express";
import fs from "fs";
import dataDir from "./data_dir.js";
import cls from "./cls.js";
import { isWindows } from "./utils.js";

if (!fs.existsSync(dataDir.LOG_DIR)) {
fs.mkdirSync(dataDir.LOG_DIR, 0o700);
Expand All @@ -16,7 +17,7 @@ const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;

const NEW_LINE = process.platform === "win32" ? '\r\n' : '\n';
const NEW_LINE = isWindows() ? '\r\n' : '\n';

let todaysMidnight!: Date;

Expand Down
4 changes: 2 additions & 2 deletions src/services/options_init.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import optionService from "./options.js";
import type { OptionMap } from "./options.js";
import appInfo from "./app_info.js";
import { randomSecureToken } from "./utils.js";
import { randomSecureToken, isWindows } from "./utils.js";
import log from "./log.js";
import dateUtils from "./date_utils.js";
import keyboardActions from "./keyboard_actions.js";
Expand Down Expand Up @@ -72,7 +72,7 @@ const defaultOptions: DefaultOption[] = [
{ name: 'revisionSnapshotTimeInterval', value: '600', isSynced: true },
{ name: 'revisionSnapshotNumberLimit', value: '-1', isSynced: true },
{ name: 'protectedSessionTimeout', value: '600', isSynced: true },
{ name: 'zoomFactor', value: process.platform === "win32" ? '0.9' : '1.0', isSynced: false },
{ name: 'zoomFactor', value: isWindows() ? '0.9' : '1.0', isSynced: false },
{ name: 'overrideThemeFonts', value: 'false', isSynced: false },
{ name: 'mainFontFamily', value: 'theme', isSynced: false },
{ name: 'mainFontSize', value: '100', isSynced: false },
Expand Down
12 changes: 11 additions & 1 deletion src/services/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,14 @@ export function getResourceDir() {
}
}

export function isMac() {
return process.platform === "darwin";
}

export function isWindows() {
return process.platform === "win32";
}

export default {
randomSecureToken,
randomString,
Expand Down Expand Up @@ -365,5 +373,7 @@ export default {
hashedBlobId,
toMap,
isString,
getResourceDir
getResourceDir,
isMac,
isWindows
};
10 changes: 4 additions & 6 deletions src/services/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import cls from "./cls.js";
import keyboardActionsService from "./keyboard_actions.js";
import remoteMain from "@electron/remote/main/index.js";
import { App, BrowserWindow, BrowserWindowConstructorOptions, WebContents, ipcMain } from 'electron';
import { isMac, isWindows } from "./utils.js";

import { fileURLToPath } from "url";
import { dirname } from "path";
Expand Down Expand Up @@ -115,14 +116,11 @@ async function createMainWindow(app: App) {
function getWindowExtraOpts() {
const extraOpts: Partial<BrowserWindowConstructorOptions> = {};

const isMac = (process.platform === "darwin");
const isWindows = (process.platform === "win32");

if (!optionService.getOptionBool('nativeTitleBarVisible')) {
if (isMac) {
if (isMac()) {
extraOpts.titleBarStyle = "hiddenInset";
extraOpts.titleBarOverlay = true;
} else if (isWindows) {
} else if (isWindows()) {
extraOpts.titleBarStyle = "hidden";
extraOpts.titleBarOverlay = true;
} else {
Expand All @@ -132,7 +130,7 @@ function getWindowExtraOpts() {
}

// Window effects (Mica)
if (optionService.getOptionBool('backgroundEffects') && isWindows) {
if (optionService.getOptionBool('backgroundEffects') && isWindows()) {
extraOpts.backgroundMaterial = "auto";
}

Expand Down

0 comments on commit 6825fe2

Please sign in to comment.