mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
refactor(cli): remove deprecated verbose logging flags
This commit is contained in:
@@ -33,7 +33,7 @@ function makeArgs(overrides: Partial<CliArgs> = {}): CliArgs {
|
||||
autoStartOverlay: false,
|
||||
generateConfig: false,
|
||||
backupOverwrite: false,
|
||||
verbose: false,
|
||||
debug: false,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ export class MpvIpcClient implements MpvClient {
|
||||
this.transport = new MpvSocketTransport({
|
||||
socketPath,
|
||||
onConnect: () => {
|
||||
logger.info("Connected to MPV socket");
|
||||
logger.debug("Connected to MPV socket");
|
||||
this.connected = true;
|
||||
this.connecting = false;
|
||||
this.socket = this.transport.getSocket();
|
||||
@@ -192,7 +192,7 @@ export class MpvIpcClient implements MpvClient {
|
||||
this.deps.autoStartOverlay ||
|
||||
this.deps.getResolvedConfig().auto_start_overlay === true;
|
||||
if (this.firstConnection && shouldAutoStart) {
|
||||
logger.info("Auto-starting overlay, hiding mpv subtitles");
|
||||
logger.debug("Auto-starting overlay, hiding mpv subtitles");
|
||||
setTimeout(() => {
|
||||
this.deps.setOverlayVisible(true);
|
||||
}, 100);
|
||||
|
||||
@@ -35,7 +35,7 @@ function makeArgs(overrides: Partial<CliArgs> = {}): CliArgs {
|
||||
autoStartOverlay: false,
|
||||
generateConfig: false,
|
||||
backupOverwrite: false,
|
||||
verbose: false,
|
||||
debug: false,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
@@ -43,7 +43,7 @@ function makeArgs(overrides: Partial<CliArgs> = {}): CliArgs {
|
||||
test("runStartupBootstrapRuntimeService configures startup state and starts lifecycle", () => {
|
||||
const calls: string[] = [];
|
||||
const args = makeArgs({
|
||||
verbose: true,
|
||||
logLevel: "debug",
|
||||
socketPath: "/tmp/custom.sock",
|
||||
texthookerPort: 9001,
|
||||
backend: "x11",
|
||||
@@ -52,7 +52,7 @@ test("runStartupBootstrapRuntimeService configures startup state and starts life
|
||||
});
|
||||
|
||||
const result = runStartupBootstrapRuntimeService({
|
||||
argv: ["node", "main.ts", "--verbose"],
|
||||
argv: ["node", "main.ts", "--log-level", "debug"],
|
||||
parseArgs: () => args,
|
||||
setLogLevel: (level, source) => calls.push(`setLog:${level}:${source}`),
|
||||
forceX11Backend: () => calls.push("forceX11"),
|
||||
@@ -77,15 +77,14 @@ test("runStartupBootstrapRuntimeService configures startup state and starts life
|
||||
]);
|
||||
});
|
||||
|
||||
test("runStartupBootstrapRuntimeService prefers --log-level over --verbose", () => {
|
||||
test("runStartupBootstrapRuntimeService keeps log-level precedence for repeated calls", () => {
|
||||
const calls: string[] = [];
|
||||
const args = makeArgs({
|
||||
logLevel: "warn",
|
||||
verbose: true,
|
||||
});
|
||||
|
||||
runStartupBootstrapRuntimeService({
|
||||
argv: ["node", "main.ts", "--log-level", "warn", "--verbose"],
|
||||
argv: ["node", "main.ts", "--log-level", "warn"],
|
||||
parseArgs: () => args,
|
||||
setLogLevel: (level, source) => calls.push(`setLog:${level}:${source}`),
|
||||
forceX11Backend: () => calls.push("forceX11"),
|
||||
@@ -103,6 +102,27 @@ test("runStartupBootstrapRuntimeService prefers --log-level over --verbose", ()
|
||||
]);
|
||||
});
|
||||
|
||||
test("runStartupBootstrapRuntimeService keeps --debug separate from log verbosity", () => {
|
||||
const calls: string[] = [];
|
||||
const args = makeArgs({
|
||||
debug: true,
|
||||
});
|
||||
|
||||
runStartupBootstrapRuntimeService({
|
||||
argv: ["node", "main.ts", "--debug"],
|
||||
parseArgs: () => args,
|
||||
setLogLevel: (level, source) => calls.push(`setLog:${level}:${source}`),
|
||||
forceX11Backend: () => calls.push("forceX11"),
|
||||
enforceUnsupportedWaylandMode: () => calls.push("enforceWayland"),
|
||||
getDefaultSocketPath: () => "/tmp/default.sock",
|
||||
defaultTexthookerPort: 5174,
|
||||
runGenerateConfigFlow: () => false,
|
||||
startAppLifecycle: () => calls.push("startLifecycle"),
|
||||
});
|
||||
|
||||
assert.deepEqual(calls, ["forceX11", "enforceWayland", "startLifecycle"]);
|
||||
});
|
||||
|
||||
test("runStartupBootstrapRuntimeService skips lifecycle when generate-config flow handled", () => {
|
||||
const calls: string[] = [];
|
||||
const args = makeArgs({ generateConfig: true, logLevel: "warn" });
|
||||
|
||||
@@ -47,8 +47,6 @@ export function runStartupBootstrapRuntimeService(
|
||||
|
||||
if (initialArgs.logLevel) {
|
||||
deps.setLogLevel(initialArgs.logLevel, "cli");
|
||||
} else if (initialArgs.verbose) {
|
||||
deps.setLogLevel("debug", "cli");
|
||||
}
|
||||
|
||||
deps.forceX11Backend(initialArgs);
|
||||
|
||||
@@ -791,7 +791,7 @@ async function enrichYomitanPos1(
|
||||
mecabTokens = await deps.tokenizeWithMecab(text);
|
||||
} catch (err) {
|
||||
const error = err as Error;
|
||||
console.warn(
|
||||
logger.warn(
|
||||
"Failed to enrich Yomitan tokens with MeCab POS:",
|
||||
error.message,
|
||||
`tokenCount=${tokens.length}`,
|
||||
@@ -801,7 +801,7 @@ async function enrichYomitanPos1(
|
||||
}
|
||||
|
||||
if (!mecabTokens || mecabTokens.length === 0) {
|
||||
console.warn(
|
||||
logger.warn(
|
||||
"MeCab enrichment returned no tokens; preserving Yomitan token output.",
|
||||
`tokenCount=${tokens.length}`,
|
||||
`textLength=${text.length}`,
|
||||
@@ -886,7 +886,7 @@ async function ensureYomitanParserWindow(
|
||||
}
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error(
|
||||
logger.error(
|
||||
"Failed to initialize Yomitan parser window:",
|
||||
(err as Error).message,
|
||||
);
|
||||
@@ -977,8 +977,8 @@ async function parseWithYomitanInternalParser(
|
||||
}
|
||||
|
||||
return enrichYomitanPos1(yomitanTokens, deps, text);
|
||||
} catch (err) {
|
||||
console.error("Yomitan parser request failed:", (err as Error).message);
|
||||
} catch (err) {
|
||||
logger.error("Yomitan parser request failed:", (err as Error).message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1066,7 +1066,7 @@ export async function tokenizeSubtitleService(
|
||||
};
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Tokenization error:", (err as Error).message);
|
||||
logger.error("Tokenization error:", (err as Error).message);
|
||||
}
|
||||
|
||||
return { text: displayText, tokens: null };
|
||||
|
||||
@@ -2,6 +2,9 @@ import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import * as readline from "readline";
|
||||
import { CliArgs } from "../../cli/args";
|
||||
import { createLogger } from "../../logger";
|
||||
|
||||
const logger = createLogger("core:config-gen");
|
||||
|
||||
function formatBackupTimestamp(date = new Date()): string {
|
||||
const pad = (v: number): string => String(v).padStart(2, "0");
|
||||
@@ -40,13 +43,13 @@ export async function generateDefaultConfigFile(
|
||||
const backupPath = `${targetPath}.bak.${formatBackupTimestamp()}`;
|
||||
fs.copyFileSync(targetPath, backupPath);
|
||||
fs.writeFileSync(targetPath, template, "utf-8");
|
||||
console.log(`Backed up existing config to ${backupPath}`);
|
||||
console.log(`Generated config at ${targetPath}`);
|
||||
logger.info(`Backed up existing config to ${backupPath}`);
|
||||
logger.info(`Generated config at ${targetPath}`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
||||
console.error(
|
||||
logger.error(
|
||||
`Config exists at ${targetPath}. Re-run with --backup-overwrite to back up and overwrite.`,
|
||||
);
|
||||
return 1;
|
||||
@@ -56,15 +59,15 @@ export async function generateDefaultConfigFile(
|
||||
`Config exists at ${targetPath}. Back up and overwrite? [y/N] `,
|
||||
);
|
||||
if (!confirmed) {
|
||||
console.log("Config generation cancelled.");
|
||||
logger.info("Config generation cancelled.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
const backupPath = `${targetPath}.bak.${formatBackupTimestamp()}`;
|
||||
fs.copyFileSync(targetPath, backupPath);
|
||||
fs.writeFileSync(targetPath, template, "utf-8");
|
||||
console.log(`Backed up existing config to ${backupPath}`);
|
||||
console.log(`Generated config at ${targetPath}`);
|
||||
logger.info(`Backed up existing config to ${backupPath}`);
|
||||
logger.info(`Generated config at ${targetPath}`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -73,6 +76,6 @@ export async function generateDefaultConfigFile(
|
||||
fs.mkdirSync(parentDir, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(targetPath, template, "utf-8");
|
||||
console.log(`Generated config at ${targetPath}`);
|
||||
logger.info(`Generated config at ${targetPath}`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { CliArgs, shouldStartApp } from "../../cli/args";
|
||||
import { createLogger } from "../../logger";
|
||||
|
||||
const logger = createLogger("core:electron-backend");
|
||||
|
||||
function getElectronOzonePlatformHint(): string | null {
|
||||
const hint = process.env.ELECTRON_OZONE_PLATFORM_HINT?.trim().toLowerCase();
|
||||
@@ -34,6 +37,6 @@ export function enforceUnsupportedWaylandMode(args: CliArgs): void {
|
||||
|
||||
const message =
|
||||
"Unsupported Electron backend: Wayland. Set ELECTRON_OZONE_PLATFORM_HINT=x11 and restart SubMiner.";
|
||||
console.error(message);
|
||||
logger.error(message);
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { Notification, nativeImage } from "electron";
|
||||
import * as fs from "fs";
|
||||
import { createLogger } from "../../logger";
|
||||
|
||||
const logger = createLogger("core:notification");
|
||||
|
||||
export function showDesktopNotification(
|
||||
title: string,
|
||||
@@ -24,7 +27,7 @@ export function showDesktopNotification(
|
||||
if (fs.existsSync(options.icon)) {
|
||||
notificationOptions.icon = options.icon;
|
||||
} else {
|
||||
console.warn("Notification icon file not found:", options.icon);
|
||||
logger.warn("Notification icon file not found", options.icon);
|
||||
}
|
||||
} else if (
|
||||
typeof options.icon === "string" &&
|
||||
@@ -36,14 +39,14 @@ export function showDesktopNotification(
|
||||
Buffer.from(base64Data, "base64"),
|
||||
);
|
||||
if (image.isEmpty()) {
|
||||
console.warn(
|
||||
logger.warn(
|
||||
"Notification icon created from base64 is empty - image format may not be supported by Electron",
|
||||
);
|
||||
} else {
|
||||
notificationOptions.icon = image;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Failed to create notification icon from base64:", err);
|
||||
logger.error("Failed to create notification icon from base64", err);
|
||||
}
|
||||
} else {
|
||||
notificationOptions.icon = options.icon;
|
||||
|
||||
Reference in New Issue
Block a user