Changes in response to review comments and lint
This commit is contained in:
parent
72e5dde0f3
commit
1b9337ef67
11 changed files with 53 additions and 39 deletions
|
@ -48,7 +48,6 @@
|
||||||
"eslint-plugin-prettier": "^5.0.1",
|
"eslint-plugin-prettier": "^5.0.1",
|
||||||
"eslint-plugin-simple-import-sort": "^10.0.0",
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
||||||
"eslint-plugin-unused-imports": "^3.0.0",
|
"eslint-plugin-unused-imports": "^3.0.0",
|
||||||
"fast-glob": "3.3",
|
|
||||||
"prettier": "^3.1.0",
|
"prettier": "^3.1.0",
|
||||||
"sharp": "^0.33.0",
|
"sharp": "^0.33.0",
|
||||||
"sharp-ico": "^0.1.5",
|
"sharp-ico": "^0.1.5",
|
||||||
|
|
|
@ -69,9 +69,6 @@ devDependencies:
|
||||||
eslint-plugin-unused-imports:
|
eslint-plugin-unused-imports:
|
||||||
specifier: ^3.0.0
|
specifier: ^3.0.0
|
||||||
version: 3.0.0(@typescript-eslint/eslint-plugin@6.13.1)(eslint@8.54.0)
|
version: 3.0.0(@typescript-eslint/eslint-plugin@6.13.1)(eslint@8.54.0)
|
||||||
fast-glob:
|
|
||||||
specifier: '3.3'
|
|
||||||
version: 3.3.1
|
|
||||||
prettier:
|
prettier:
|
||||||
specifier: ^3.1.0
|
specifier: ^3.1.0
|
||||||
version: 3.1.0
|
version: 3.1.0
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
import { BuildContext, BuildOptions, context } from "esbuild";
|
import { BuildContext, BuildOptions, context } from "esbuild";
|
||||||
import { copyFile } from "fs/promises";
|
import { copyFile } from "fs/promises";
|
||||||
|
|
||||||
import vencordDep from "./vencordDep.mjs";
|
|
||||||
import { composeTrayIcons } from "./composeTrayIcons.mts";
|
import { composeTrayIcons } from "./composeTrayIcons.mts";
|
||||||
|
import vencordDep from "./vencordDep.mjs";
|
||||||
|
|
||||||
const isDev = process.argv.includes("--dev");
|
const isDev = process.argv.includes("--dev");
|
||||||
|
|
||||||
|
@ -50,14 +50,20 @@ async function copyVenmic() {
|
||||||
]).catch(() => console.warn("Failed to copy venmic. Building without venmic support"));
|
]).catch(() => console.warn("Failed to copy venmic. Building without venmic support"));
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all([
|
async function composeTrayIconsIfSupported() {
|
||||||
copyVenmic(),
|
if (process.platform === "darwin") return;
|
||||||
composeTrayIcons({
|
|
||||||
|
await composeTrayIcons({
|
||||||
icon: "./static/icon.png",
|
icon: "./static/icon.png",
|
||||||
badges: "./static/badges/*",
|
badgeDir: "./static/badges/",
|
||||||
outDir: "./static/dist/tray_icons",
|
outDir: "./static/dist/tray_icons",
|
||||||
createEmpty: true
|
createEmpty: true
|
||||||
}),
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
copyVenmic(),
|
||||||
|
composeTrayIconsIfSupported(),
|
||||||
createContext({
|
createContext({
|
||||||
...NodeCommonOpts,
|
...NodeCommonOpts,
|
||||||
entryPoints: ["src/main/index.ts"],
|
entryPoints: ["src/main/index.ts"],
|
||||||
|
|
|
@ -1,7 +1,14 @@
|
||||||
import sharp, { OutputInfo } from "sharp";
|
/*
|
||||||
import fastGlob from "fast-glob";
|
* SPDX-License-Identifier: GPL-3.0
|
||||||
import type { ImageData } from "sharp-ico";
|
* Vesktop, a desktop app aiming to give you a snappier Discord Experience
|
||||||
import { parse as pathParse, format as pathFormat } from "node:path";
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { readdir, stat } from "node:fs/promises";
|
||||||
|
import { format as pathFormat, join, parse as pathParse } from "node:path";
|
||||||
|
|
||||||
|
import sharp from "sharp";
|
||||||
|
import { type ImageData, sharpsFromIco } from "sharp-ico";
|
||||||
|
|
||||||
interface BadgePosition {
|
interface BadgePosition {
|
||||||
left?: number;
|
left?: number;
|
||||||
|
@ -30,7 +37,7 @@ const DEFAULT_BADGE_OPTIONS: Required<BadgeOptions> = {
|
||||||
|
|
||||||
export async function composeTrayIcons({
|
export async function composeTrayIcons({
|
||||||
icon: iconPath,
|
icon: iconPath,
|
||||||
badges: badgeGlob,
|
badgeDir,
|
||||||
outDir,
|
outDir,
|
||||||
outExt = ".png",
|
outExt = ".png",
|
||||||
createEmpty = false,
|
createEmpty = false,
|
||||||
|
@ -38,16 +45,19 @@ export async function composeTrayIcons({
|
||||||
badgeOptions = undefined
|
badgeOptions = undefined
|
||||||
}: {
|
}: {
|
||||||
icon: string | Buffer | sharp.Sharp;
|
icon: string | Buffer | sharp.Sharp;
|
||||||
badges: string;
|
badgeDir: string;
|
||||||
outDir: string;
|
outDir: string;
|
||||||
outExt?: string;
|
outExt?: string;
|
||||||
createEmpty?: boolean;
|
createEmpty?: boolean;
|
||||||
iconOptions?: ImageDim;
|
iconOptions?: ImageDim;
|
||||||
badgeOptions?: BadgeOptions;
|
badgeOptions?: BadgeOptions;
|
||||||
}) {
|
}) {
|
||||||
const badges = await fastGlob.glob(badgeGlob);
|
const badges: string[] = [];
|
||||||
if (!badges.length) {
|
for (const filename of await readdir(badgeDir)) {
|
||||||
throw new Error(`No badges matching glob '${badgeGlob}' found!`);
|
const path = join(badgeDir, filename);
|
||||||
|
if (!(await stat(path)).isDirectory()) {
|
||||||
|
badges.push(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const badgeOptionsFilled = { ...DEFAULT_BADGE_OPTIONS, ...badgeOptions };
|
const badgeOptionsFilled = { ...DEFAULT_BADGE_OPTIONS, ...badgeOptions };
|
||||||
|
@ -73,7 +83,7 @@ export async function composeTrayIcons({
|
||||||
ext: outExt,
|
ext: outExt,
|
||||||
base: undefined
|
base: undefined
|
||||||
});
|
});
|
||||||
let out = composeTrayIcon(iconData, iconInfo, badgeData, badgeInfo, badgeOptionsFilled);
|
const out = composeTrayIcon(iconData, iconInfo, badgeData, badgeInfo, badgeOptionsFilled);
|
||||||
const outputInfo = await out.toFile(savePath);
|
const outputInfo = await out.toFile(savePath);
|
||||||
return {
|
return {
|
||||||
iconInfo,
|
iconInfo,
|
||||||
|
@ -115,7 +125,7 @@ async function loadFromImageOrIco(
|
||||||
sizeOptions?: ImageDim & { resizeICO?: boolean }
|
sizeOptions?: ImageDim & { resizeICO?: boolean }
|
||||||
): Promise<sharp.Sharp> {
|
): Promise<sharp.Sharp> {
|
||||||
if (typeof path === "string" && path.endsWith(".ico")) {
|
if (typeof path === "string" && path.endsWith(".ico")) {
|
||||||
const icos = (await import("sharp-ico")).sharpsFromIco(path, undefined, true) as unknown as ImageData[];
|
const icos = sharpsFromIco(path, undefined, true) as unknown as ImageData[];
|
||||||
let icoInfo;
|
let icoInfo;
|
||||||
if (sizeOptions == null) {
|
if (sizeOptions == null) {
|
||||||
icoInfo = icos[icos.length - 1];
|
icoInfo = icos[icos.length - 1];
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
import { app, NativeImage, nativeImage } from "electron";
|
import { app, NativeImage, nativeImage } from "electron";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { BADGE_DIR, TRAY_ICON_DIR, TRAY_ICON_PATH } from "shared/paths";
|
import { BADGE_DIR, TRAY_ICON_DIR, TRAY_ICON_PATH } from "shared/paths";
|
||||||
|
|
||||||
import { globals } from "./mainWindow";
|
import { globals } from "./mainWindow";
|
||||||
|
import { Settings } from "./settings";
|
||||||
|
|
||||||
const imgCache = new Map<string, NativeImage>();
|
const imgCache = new Map<string, NativeImage>();
|
||||||
|
|
||||||
|
@ -31,14 +33,14 @@ function loadTrayIcon(index: number) {
|
||||||
|
|
||||||
let lastIndex: null | number = -1;
|
let lastIndex: null | number = -1;
|
||||||
|
|
||||||
export function setBadgeCount(count: number, native: boolean = true, tray: boolean = false) {
|
export function setBadgeCount(count: number) {
|
||||||
const [index, description] = getBadgeIndexAndDescription(count);
|
const [index, description] = getBadgeIndexAndDescription(count);
|
||||||
|
|
||||||
if (tray) {
|
if (Settings.store.trayBadge) {
|
||||||
globals.tray?.setImage(loadTrayIcon(index ?? 0));
|
globals.tray?.setImage(loadTrayIcon(index ?? 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!native) return;
|
if (!Settings.store.appBadge) return;
|
||||||
|
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case "linux":
|
case "linux":
|
||||||
|
|
|
@ -9,12 +9,12 @@ import "./ipc";
|
||||||
import { app, BrowserWindow } from "electron";
|
import { app, BrowserWindow } from "electron";
|
||||||
import { checkUpdates } from "updater/main";
|
import { checkUpdates } from "updater/main";
|
||||||
|
|
||||||
import { Settings } from "./settings";
|
|
||||||
import { DATA_DIR } from "./constants";
|
import { DATA_DIR } from "./constants";
|
||||||
import { createFirstLaunchTour } from "./firstLaunch";
|
import { createFirstLaunchTour } from "./firstLaunch";
|
||||||
import { createWindows, globals } from "./mainWindow";
|
import { createWindows, globals } from "./mainWindow";
|
||||||
import { registerMediaPermissionsHandler } from "./mediaPermissions";
|
import { registerMediaPermissionsHandler } from "./mediaPermissions";
|
||||||
import { registerScreenShareHandler } from "./screenShare";
|
import { registerScreenShareHandler } from "./screenShare";
|
||||||
|
import { Settings } from "./settings";
|
||||||
|
|
||||||
if (IS_DEV) {
|
if (IS_DEV) {
|
||||||
require("source-map-support").install();
|
require("source-map-support").install();
|
||||||
|
@ -43,9 +43,9 @@ function init() {
|
||||||
);
|
);
|
||||||
|
|
||||||
app.on("second-instance", (_event, _cmdLine, _cwd, data: any) => {
|
app.on("second-instance", (_event, _cmdLine, _cwd, data: any) => {
|
||||||
let mainWin;
|
const { mainWin } = globals;
|
||||||
if (data.IS_DEV) app.quit();
|
if (data.IS_DEV) app.quit();
|
||||||
else if ((mainWin = globals.mainWin)) {
|
else if (mainWin) {
|
||||||
if (mainWin.isMinimized()) mainWin.restore();
|
if (mainWin.isMinimized()) mainWin.restore();
|
||||||
if (!mainWin.isVisible()) mainWin.show();
|
if (!mainWin.isVisible()) mainWin.show();
|
||||||
mainWin.focus();
|
mainWin.focus();
|
||||||
|
|
|
@ -15,11 +15,11 @@ import { join } from "path";
|
||||||
import { debounce } from "shared/utils/debounce";
|
import { debounce } from "shared/utils/debounce";
|
||||||
|
|
||||||
import { IpcEvents } from "../shared/IpcEvents";
|
import { IpcEvents } from "../shared/IpcEvents";
|
||||||
|
// !!IMPORTANT!! ./appBadge import must occur after ./mainWindow
|
||||||
|
import { setBadgeCount } from "./appBadge";
|
||||||
import { autoStart } from "./autoStart";
|
import { autoStart } from "./autoStart";
|
||||||
import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants";
|
import { VENCORD_FILES_DIR, VENCORD_QUICKCSS_FILE, VENCORD_THEMES_DIR } from "./constants";
|
||||||
import { globals } from "./mainWindow";
|
import { globals } from "./mainWindow";
|
||||||
// !!IMPORTANT!! ./appBadge import must occur after ./mainWindow
|
|
||||||
import { setBadgeCount } from "./appBadge";
|
|
||||||
import { Settings } from "./settings";
|
import { Settings } from "./settings";
|
||||||
import { handle, handleSync } from "./utils/ipcWrappers";
|
import { handle, handleSync } from "./utils/ipcWrappers";
|
||||||
import { isDeckGameMode, showGamePage } from "./utils/steamOS";
|
import { isDeckGameMode, showGamePage } from "./utils/steamOS";
|
||||||
|
@ -122,9 +122,9 @@ handle(IpcEvents.SELECT_VENCORD_DIR, async () => {
|
||||||
return dir;
|
return dir;
|
||||||
});
|
});
|
||||||
|
|
||||||
handle(IpcEvents.SET_BADGE_COUNT, (_, count: number, native: boolean, tray: boolean) =>
|
handle(IpcEvents.SET_BADGE_COUNT, (_, count: number) => {
|
||||||
setBadgeCount(count, native, tray)
|
setBadgeCount(count);
|
||||||
);
|
});
|
||||||
|
|
||||||
function readCss() {
|
function readCss() {
|
||||||
return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => "");
|
return readFile(VENCORD_QUICKCSS_FILE, "utf-8").catch(() => "");
|
||||||
|
|
|
@ -24,7 +24,6 @@ import type { SettingsStore } from "shared/utils/SettingsStore";
|
||||||
import { ICON_PATH, TRAY_ICON_PATH } from "../shared/paths";
|
import { ICON_PATH, TRAY_ICON_PATH } from "../shared/paths";
|
||||||
import { createAboutWindow } from "./about";
|
import { createAboutWindow } from "./about";
|
||||||
import { initArRPC } from "./arrpc";
|
import { initArRPC } from "./arrpc";
|
||||||
import { Settings, VencordSettings } from "./settings";
|
|
||||||
import {
|
import {
|
||||||
DATA_DIR,
|
DATA_DIR,
|
||||||
DEFAULT_HEIGHT,
|
DEFAULT_HEIGHT,
|
||||||
|
@ -35,6 +34,7 @@ import {
|
||||||
UserAgent,
|
UserAgent,
|
||||||
VENCORD_FILES_DIR
|
VENCORD_FILES_DIR
|
||||||
} from "./constants";
|
} from "./constants";
|
||||||
|
import { Settings, VencordSettings } from "./settings";
|
||||||
import { createSplashWindow } from "./splash";
|
import { createSplashWindow } from "./splash";
|
||||||
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
|
import { makeLinksOpenExternally } from "./utils/makeLinksOpenExternally";
|
||||||
import { applyDeckKeyboardFix, askToApplySteamLayout, isDeckGameMode } from "./utils/steamOS";
|
import { applyDeckKeyboardFix, askToApplySteamLayout, isDeckGameMode } from "./utils/steamOS";
|
||||||
|
|
|
@ -23,8 +23,7 @@ export const VesktopNative = {
|
||||||
app: {
|
app: {
|
||||||
relaunch: () => invoke<void>(IpcEvents.RELAUNCH),
|
relaunch: () => invoke<void>(IpcEvents.RELAUNCH),
|
||||||
getVersion: () => sendSync<void>(IpcEvents.GET_VERSION),
|
getVersion: () => sendSync<void>(IpcEvents.GET_VERSION),
|
||||||
setBadgeCount: (count: number, native: boolean = true, tray: boolean = false) =>
|
setBadgeCount: (count: number) => invoke<void>(IpcEvents.SET_BADGE_COUNT, count),
|
||||||
invoke<void>(IpcEvents.SET_BADGE_COUNT, count, native, tray),
|
|
||||||
supportsWindowsTransparency: () => sendSync<boolean>(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY)
|
supportsWindowsTransparency: () => sendSync<boolean>(IpcEvents.SUPPORTS_WINDOWS_TRANSPARENCY)
|
||||||
},
|
},
|
||||||
autostart: {
|
autostart: {
|
||||||
|
|
|
@ -22,8 +22,9 @@ export function setBadge() {
|
||||||
let totalCount = mentionCount + pendingRequests;
|
let totalCount = mentionCount + pendingRequests;
|
||||||
if (!totalCount && hasUnread && !disableUnreadBadge) totalCount = -1;
|
if (!totalCount && hasUnread && !disableUnreadBadge) totalCount = -1;
|
||||||
|
|
||||||
if (Settings.store.appBadge || Settings.store.trayBadge)
|
if (Settings.store.appBadge || Settings.store.trayBadge) {
|
||||||
VesktopNative.app.setBadgeCount(totalCount, Settings.store.appBadge, Settings.store.trayBadge);
|
VesktopNative.app.setBadgeCount(totalCount);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ export default function SettingsUi() {
|
||||||
onChange={v => {
|
onChange={v => {
|
||||||
Settings.appBadge = v;
|
Settings.appBadge = v;
|
||||||
if (v) setBadge();
|
if (v) setBadge();
|
||||||
else VesktopNative.app.setBadgeCount(0, true, false);
|
else VesktopNative.app.setBadgeCount(0);
|
||||||
}}
|
}}
|
||||||
note="Show mention badge on the app (taskbar/panel) icon"
|
note="Show mention badge on the app (taskbar/panel) icon"
|
||||||
>
|
>
|
||||||
|
@ -121,7 +121,7 @@ export default function SettingsUi() {
|
||||||
onChange={v => {
|
onChange={v => {
|
||||||
Settings.trayBadge = v;
|
Settings.trayBadge = v;
|
||||||
if (v) setBadge();
|
if (v) setBadge();
|
||||||
else VesktopNative.app.setBadgeCount(0, false, true);
|
else VesktopNative.app.setBadgeCount(0);
|
||||||
}}
|
}}
|
||||||
disabled={!(Settings.tray ?? true)}
|
disabled={!(Settings.tray ?? true)}
|
||||||
note="Show mention badge on the tray icon"
|
note="Show mention badge on the tray icon"
|
||||||
|
|
Loading…
Reference in a new issue