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