mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 01:02:01 +03:00
Refactor console logs to use centralized logger
This commit is contained in:
parent
d263976248
commit
1592a3567f
9 changed files with 55 additions and 40 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { logger } from "../logger";
|
||||||
// Public facade: evaluates whole documents line by line and exposes the
|
// Public facade: evaluates whole documents line by line and exposes the
|
||||||
// extension API (numi.addUnit / addFunction / setVariable).
|
// extension API (numi.addUnit / addFunction / setVariable).
|
||||||
import { DateOrder, Decimal, EngineSettings, EvalError, Quantity, Unit, Value, XRefError, defaultSettings, qty } from "./types";
|
import { DateOrder, Decimal, EngineSettings, EvalError, Quantity, Unit, Value, XRefError, defaultSettings, qty } from "./types";
|
||||||
|
|
@ -147,7 +148,7 @@ export class SumEngine {
|
||||||
} else {
|
} else {
|
||||||
// Capture unexpected execution anomalies like BigInt or Range errors
|
// Capture unexpected execution anomalies like BigInt or Range errors
|
||||||
lineError = e instanceof Error ? e.message : String(e);
|
lineError = e instanceof Error ? e.message : String(e);
|
||||||
console.warn("evaluate failed:", e);
|
logger.warn("evaluate failed:", e);
|
||||||
}
|
}
|
||||||
// a line without a result beats a dead sheet.
|
// a line without a result beats a dead sheet.
|
||||||
value = null;
|
value = null;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { logger } from "./logger";
|
||||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||||
import { makeApi, runExtensions } from "./extensions";
|
import { makeApi, runExtensions } from "./extensions";
|
||||||
import { SumEngine } from "./engine";
|
import { SumEngine } from "./engine";
|
||||||
|
|
@ -41,8 +42,8 @@ describe("extensions", () => {
|
||||||
let consoleWarnSpy: any;
|
let consoleWarnSpy: any;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
consoleErrorSpy = vi.spyOn(logger, "error").mockImplementation(() => {});
|
||||||
consoleWarnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
|
consoleWarnSpy = vi.spyOn(logger, "warn").mockImplementation(() => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|
@ -185,6 +186,8 @@ describe("extensions", () => {
|
||||||
newQuickJSWASMModuleFromVariant: () => Promise.reject(new Error("no WebAssembly")),
|
newQuickJSWASMModuleFromVariant: () => Promise.reject(new Error("no WebAssembly")),
|
||||||
}));
|
}));
|
||||||
const { runExtensions: run } = await import("./extensions");
|
const { runExtensions: run } = await import("./extensions");
|
||||||
|
const { logger } = await import("./logger");
|
||||||
|
consoleWarnSpy = vi.spyOn(logger, "warn").mockImplementation(() => {});
|
||||||
|
|
||||||
await run(mockEngine as SumEngine, [{ name: "s", code: "numi.setVariable('x', 1);" }]);
|
await run(mockEngine as SumEngine, [{ name: "s", code: "numi.setVariable('x', 1);" }]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { logger } from "./logger";
|
||||||
// JS extensions runtime: numi.setVariable, numi.addUnit, numi.addFunction.
|
// JS extensions runtime: numi.setVariable, numi.addUnit, numi.addFunction.
|
||||||
// Scripts run inside a QuickJS WASM sandbox — no DOM, no Tauri IPC, no host globals.
|
// Scripts run inside a QuickJS WASM sandbox — no DOM, no Tauri IPC, no host globals.
|
||||||
import {
|
import {
|
||||||
|
|
@ -75,7 +76,7 @@ export async function runExtensions(
|
||||||
try {
|
try {
|
||||||
await load(engine, scripts);
|
await load(engine, scripts);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("extensions disabled: QuickJS sandbox unavailable:", e);
|
logger.warn("extensions disabled: QuickJS sandbox unavailable:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,7 +201,7 @@ function evaluateScripts(
|
||||||
}
|
}
|
||||||
res.value.dispose();
|
res.value.dispose();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`extension ${s.name} failed:`, e);
|
logger.error(`extension ${s.name} failed:`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
src/logger.ts
Normal file
5
src/logger.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
export const logger = {
|
||||||
|
info: (...args: any[]) => console.info(...args),
|
||||||
|
warn: (...args: any[]) => console.warn(...args),
|
||||||
|
error: (...args: any[]) => console.error(...args),
|
||||||
|
};
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { logger } from "./logger";
|
||||||
/** App bootstrap: engine + editor + documents + settings + Tauri glue. */
|
/** App bootstrap: engine + editor + documents + settings + Tauri glue. */
|
||||||
import "./ui/app.css";
|
import "./ui/app.css";
|
||||||
import { SumEngine } from "./engine";
|
import { SumEngine } from "./engine";
|
||||||
|
|
@ -436,7 +437,7 @@ function bindDataDirSettings(): void {
|
||||||
await flushAppData();
|
await flushAppData();
|
||||||
await migrateDataDir(settings.dataDir, picked, strategy);
|
await migrateDataDir(settings.dataDir, picked, strategy);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("migrate failed", e);
|
logger.warn("migrate failed", e);
|
||||||
toast(t("folderError"));
|
toast(t("folderError"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -537,7 +538,7 @@ async function registerHotkey(old: string | null, combo: string): Promise<boolea
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("hotkey registration failed", e);
|
logger.warn("hotkey registration failed", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -549,14 +550,14 @@ async function applyAutostart(enabled: boolean): Promise<void> {
|
||||||
if (enabled) await auto.enable();
|
if (enabled) await auto.enable();
|
||||||
else await auto.disable();
|
else await auto.disable();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("autostart failed", e);
|
logger.warn("autostart failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function applyAlwaysOnTop(enabled: boolean): Promise<void> {
|
async function applyAlwaysOnTop(enabled: boolean): Promise<void> {
|
||||||
if (!isTauri()) return;
|
if (!isTauri()) return;
|
||||||
const { getCurrentWindow } = await import("@tauri-apps/api/window");
|
const { getCurrentWindow } = await import("@tauri-apps/api/window");
|
||||||
await getCurrentWindow().setAlwaysOnTop(enabled).catch((e) => console.warn("always-on-top failed", e));
|
await getCurrentWindow().setAlwaysOnTop(enabled).catch((e) => logger.warn("always-on-top failed", e));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refreshRates(force = false): Promise<void> {
|
async function refreshRates(force = false): Promise<void> {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { logger } from "./logger";
|
||||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
||||||
import { isTauri, loadSettings, saveSettings, defaultSettingsData, loadAppData, saveAppData, flushAppData, setDataDir, runBackups, backupDeletedSheet, openBackupsFolder, chooseFolder, dataDirHasDocuments, migrateDataDir, fetchRates, fetchHistoricalRates } from './storage';
|
import { isTauri, loadSettings, saveSettings, defaultSettingsData, loadAppData, saveAppData, flushAppData, setDataDir, runBackups, backupDeletedSheet, openBackupsFolder, chooseFolder, dataDirHasDocuments, migrateDataDir, fetchRates, fetchHistoricalRates } from './storage';
|
||||||
import { invoke } from '@tauri-apps/api/core';
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
|
|
@ -14,7 +15,7 @@ describe('storage', () => {
|
||||||
getItem: vi.fn(),
|
getItem: vi.fn(),
|
||||||
setItem: vi.fn(),
|
setItem: vi.fn(),
|
||||||
});
|
});
|
||||||
vi.stubGlobal('console', { warn: vi.fn() });
|
vi.spyOn(logger, 'warn').mockImplementation(() => {});
|
||||||
vi.stubGlobal('fetch', vi.fn());
|
vi.stubGlobal('fetch', vi.fn());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -54,7 +55,7 @@ describe('storage', () => {
|
||||||
it('falls back to defaultSettingsData if localStorage throws', async () => {
|
it('falls back to defaultSettingsData if localStorage throws', async () => {
|
||||||
vi.mocked(localStorage.getItem).mockImplementation(() => { throw new Error('localStorage error'); });
|
vi.mocked(localStorage.getItem).mockImplementation(() => { throw new Error('localStorage error'); });
|
||||||
const settings = await loadSettings();
|
const settings = await loadSettings();
|
||||||
expect(console.warn).toHaveBeenCalledWith('loadSettings failed', expect.any(Error));
|
expect(logger.warn).toHaveBeenCalledWith('loadSettings failed', expect.any(Error));
|
||||||
expect(settings).toEqual(defaultSettingsData);
|
expect(settings).toEqual(defaultSettingsData);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -62,7 +63,7 @@ describe('storage', () => {
|
||||||
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
||||||
vi.mocked(invoke).mockRejectedValue(new Error('invoke error'));
|
vi.mocked(invoke).mockRejectedValue(new Error('invoke error'));
|
||||||
const settings = await loadSettings();
|
const settings = await loadSettings();
|
||||||
expect(console.warn).toHaveBeenCalledWith('loadSettings failed', expect.any(Error));
|
expect(logger.warn).toHaveBeenCalledWith('loadSettings failed', expect.any(Error));
|
||||||
expect(settings).toEqual(defaultSettingsData);
|
expect(settings).toEqual(defaultSettingsData);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -75,7 +76,7 @@ describe('storage', () => {
|
||||||
it('falls back to defaultSettingsData if JSON is invalid', async () => {
|
it('falls back to defaultSettingsData if JSON is invalid', async () => {
|
||||||
vi.mocked(localStorage.getItem).mockReturnValue("invalid json");
|
vi.mocked(localStorage.getItem).mockReturnValue("invalid json");
|
||||||
const settings = await loadSettings();
|
const settings = await loadSettings();
|
||||||
expect(console.warn).toHaveBeenCalledWith('loadSettings failed', expect.any(Error));
|
expect(logger.warn).toHaveBeenCalledWith('loadSettings failed', expect.any(Error));
|
||||||
expect(settings).toEqual(defaultSettingsData);
|
expect(settings).toEqual(defaultSettingsData);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -124,7 +125,7 @@ describe('storage', () => {
|
||||||
it('returns null if localStorage throws', async () => {
|
it('returns null if localStorage throws', async () => {
|
||||||
vi.mocked(localStorage.getItem).mockImplementation(() => { throw new Error('localStorage error'); });
|
vi.mocked(localStorage.getItem).mockImplementation(() => { throw new Error('localStorage error'); });
|
||||||
const data = await loadAppData('');
|
const data = await loadAppData('');
|
||||||
expect(console.warn).toHaveBeenCalledWith('loadAppData failed', expect.any(Error));
|
expect(logger.warn).toHaveBeenCalledWith('loadAppData failed', expect.any(Error));
|
||||||
expect(data).toBeNull();
|
expect(data).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -132,7 +133,7 @@ describe('storage', () => {
|
||||||
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
||||||
vi.mocked(invoke).mockRejectedValue(new Error('invoke error'));
|
vi.mocked(invoke).mockRejectedValue(new Error('invoke error'));
|
||||||
const data = await loadAppData('');
|
const data = await loadAppData('');
|
||||||
expect(console.warn).toHaveBeenCalledWith('loadAppData failed', expect.any(Error));
|
expect(logger.warn).toHaveBeenCalledWith('loadAppData failed', expect.any(Error));
|
||||||
expect(data).toBeNull();
|
expect(data).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -145,7 +146,7 @@ describe('storage', () => {
|
||||||
it('returns null if JSON is invalid', async () => {
|
it('returns null if JSON is invalid', async () => {
|
||||||
vi.mocked(localStorage.getItem).mockReturnValue("invalid json");
|
vi.mocked(localStorage.getItem).mockReturnValue("invalid json");
|
||||||
const data = await loadAppData('');
|
const data = await loadAppData('');
|
||||||
expect(console.warn).toHaveBeenCalledWith('loadAppData failed', expect.any(Error));
|
expect(logger.warn).toHaveBeenCalledWith('loadAppData failed', expect.any(Error));
|
||||||
expect(data).toBeNull();
|
expect(data).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -223,7 +224,7 @@ describe('storage', () => {
|
||||||
|
|
||||||
await flushAppData();
|
await flushAppData();
|
||||||
|
|
||||||
expect(console.warn).toHaveBeenCalledWith('saveAppData failed', expect.any(Error));
|
expect(logger.warn).toHaveBeenCalledWith('saveAppData failed', expect.any(Error));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles invoke throw gracefully in flushAppData', async () => {
|
it('handles invoke throw gracefully in flushAppData', async () => {
|
||||||
|
|
@ -234,7 +235,7 @@ describe('storage', () => {
|
||||||
|
|
||||||
await flushAppData();
|
await flushAppData();
|
||||||
|
|
||||||
expect(console.warn).toHaveBeenCalledWith('saveAppData failed', expect.any(Error));
|
expect(logger.warn).toHaveBeenCalledWith('saveAppData failed', expect.any(Error));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -255,7 +256,7 @@ describe('storage', () => {
|
||||||
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
||||||
vi.mocked(invoke).mockRejectedValue(new Error('invoke error'));
|
vi.mocked(invoke).mockRejectedValue(new Error('invoke error'));
|
||||||
await runBackups('dir', 10);
|
await runBackups('dir', 10);
|
||||||
expect(console.warn).toHaveBeenCalledWith('runBackups failed', expect.any(Error));
|
expect(logger.warn).toHaveBeenCalledWith('runBackups failed', expect.any(Error));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -281,7 +282,7 @@ describe('storage', () => {
|
||||||
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
vi.stubGlobal('window', { __TAURI_INTERNALS__: {} });
|
||||||
vi.mocked(invoke).mockRejectedValue(new Error('invoke error'));
|
vi.mocked(invoke).mockRejectedValue(new Error('invoke error'));
|
||||||
await backupDeletedSheet('dir', 'title', 'contents');
|
await backupDeletedSheet('dir', 'title', 'contents');
|
||||||
expect(console.warn).toHaveBeenCalledWith('backupDeletedSheet failed', expect.any(Error));
|
expect(logger.warn).toHaveBeenCalledWith('backupDeletedSheet failed', expect.any(Error));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -369,7 +370,7 @@ describe('storage', () => {
|
||||||
it('returns null if fetch fails', async () => {
|
it('returns null if fetch fails', async () => {
|
||||||
vi.mocked(fetch).mockRejectedValue(new Error('Network error'));
|
vi.mocked(fetch).mockRejectedValue(new Error('Network error'));
|
||||||
const result = await fetchRates();
|
const result = await fetchRates();
|
||||||
expect(console.warn).toHaveBeenCalledWith('fetchRates failed', expect.any(Error));
|
expect(logger.warn).toHaveBeenCalledWith('fetchRates failed', expect.any(Error));
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -404,7 +405,7 @@ describe('storage', () => {
|
||||||
it('returns null if fetch fails', async () => {
|
it('returns null if fetch fails', async () => {
|
||||||
vi.mocked(fetch).mockRejectedValue(new Error('Network error'));
|
vi.mocked(fetch).mockRejectedValue(new Error('Network error'));
|
||||||
const result = await fetchHistoricalRates('2024-01-01');
|
const result = await fetchHistoricalRates('2024-01-01');
|
||||||
expect(console.warn).toHaveBeenCalledWith('fetchHistoricalRates failed', '2024-01-01', expect.any(Error));
|
expect(logger.warn).toHaveBeenCalledWith('fetchHistoricalRates failed', '2024-01-01', expect.any(Error));
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { logger } from "./logger";
|
||||||
// Storage: Tauri commands in the app, localStorage fallback for `vite dev`.
|
// Storage: Tauri commands in the app, localStorage fallback for `vite dev`.
|
||||||
|
|
||||||
export interface DocMeta {
|
export interface DocMeta {
|
||||||
|
|
@ -79,7 +80,7 @@ export async function loadSettings(): Promise<SettingsData> {
|
||||||
: localStorage.getItem("summarum.settings");
|
: localStorage.getItem("summarum.settings");
|
||||||
if (raw) return { ...defaultSettingsData, ...JSON.parse(raw) };
|
if (raw) return { ...defaultSettingsData, ...JSON.parse(raw) };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("loadSettings failed", e);
|
logger.warn("loadSettings failed", e);
|
||||||
}
|
}
|
||||||
return { ...defaultSettingsData };
|
return { ...defaultSettingsData };
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +100,7 @@ export async function loadAppData(dataDir: string): Promise<AppData | null> {
|
||||||
: localStorage.getItem("summarum.documents");
|
: localStorage.getItem("summarum.documents");
|
||||||
if (raw) return JSON.parse(raw);
|
if (raw) return JSON.parse(raw);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("loadAppData failed", e);
|
logger.warn("loadAppData failed", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +133,7 @@ export async function flushAppData(): Promise<void> {
|
||||||
if (isTauri()) await invoke("save_documents", { dir: dirArg(currentDataDir), contents: raw });
|
if (isTauri()) await invoke("save_documents", { dir: dirArg(currentDataDir), contents: raw });
|
||||||
else localStorage.setItem("summarum.documents", raw);
|
else localStorage.setItem("summarum.documents", raw);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("saveAppData failed", e);
|
logger.warn("saveAppData failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -150,7 +151,7 @@ export async function runBackups(dataDir: string, retentionDays: number): Promis
|
||||||
try {
|
try {
|
||||||
await invoke("run_backups", { dir: dirArg(dataDir), retentionDays });
|
await invoke("run_backups", { dir: dirArg(dataDir), retentionDays });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("runBackups failed", e);
|
logger.warn("runBackups failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,7 +160,7 @@ export async function backupDeletedSheet(dataDir: string, title: string, content
|
||||||
try {
|
try {
|
||||||
await invoke("backup_deleted_sheet", { dir: dirArg(dataDir), title, contents });
|
await invoke("backup_deleted_sheet", { dir: dirArg(dataDir), title, contents });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("backupDeletedSheet failed", e);
|
logger.warn("backupDeletedSheet failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,7 +206,7 @@ export async function fetchRates(force = false): Promise<RatesPayload | null> {
|
||||||
return { date: json.time_last_update_utc, rates: json.rates, fetchedAt: Math.floor(Date.now() / 1000) };
|
return { date: json.time_last_update_utc, rates: json.rates, fetchedAt: Math.floor(Date.now() / 1000) };
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("fetchRates failed", e);
|
logger.warn("fetchRates failed", e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -227,7 +228,7 @@ export async function fetchHistoricalRatesBatch(dates: string[]): Promise<Record
|
||||||
);
|
);
|
||||||
return results;
|
return results;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("fetchHistoricalRatesBatch failed", e);
|
logger.warn("fetchHistoricalRatesBatch failed", e);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -246,7 +247,7 @@ export async function fetchHistoricalRates(date: string): Promise<Record<string,
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("fetchHistoricalRates failed", date, e);
|
logger.warn("fetchHistoricalRates failed", date, e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -265,7 +266,7 @@ export async function fetchMarketData(symbols: string[]): Promise<Record<string,
|
||||||
try {
|
try {
|
||||||
return await invoke<Record<string, number>>("fetch_market_data", { symbols });
|
return await invoke<Record<string, number>>("fetch_market_data", { symbols });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("fetchMarketData failed", e);
|
logger.warn("fetchMarketData failed", e);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -277,7 +278,7 @@ export async function loadExtensionScripts(): Promise<{ name: string; code: stri
|
||||||
try {
|
try {
|
||||||
return await invoke<{ name: string; code: string }[]>("load_extensions");
|
return await invoke<{ name: string; code: string }[]>("load_extensions");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("loadExtensions failed", e);
|
logger.warn("loadExtensions failed", e);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -314,7 +315,7 @@ export async function onFileDrop(cb: (content: string) => void): Promise<void> {
|
||||||
const content = await invoke<string>("read_text_file", { path });
|
const content = await invoke<string>("read_text_file", { path });
|
||||||
cb(content);
|
cb(content);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("file drop rejected", path, e);
|
logger.warn("file drop rejected", path, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { logger } from "./logger";
|
||||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
import { checkForUpdate } from './updater';
|
import { checkForUpdate } from './updater';
|
||||||
import * as storage from './storage';
|
import * as storage from './storage';
|
||||||
|
|
@ -22,8 +23,8 @@ vi.mock('@tauri-apps/plugin-process', () => ({
|
||||||
describe('checkForUpdate', () => {
|
describe('checkForUpdate', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
vi.spyOn(console, 'info').mockImplementation(() => {});
|
vi.spyOn(logger, 'info').mockImplementation(() => {});
|
||||||
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
vi.spyOn(logger, 'warn').mockImplementation(() => {});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null if not in Tauri', async () => {
|
it('should return null if not in Tauri', async () => {
|
||||||
|
|
@ -39,7 +40,7 @@ describe('checkForUpdate', () => {
|
||||||
|
|
||||||
const result = await checkForUpdate();
|
const result = await checkForUpdate();
|
||||||
expect(result).toBe('error');
|
expect(result).toBe('error');
|
||||||
expect(console.warn).toHaveBeenCalledWith('update check failed', expect.any(Error));
|
expect(logger.warn).toHaveBeenCalledWith('update check failed', expect.any(Error));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null if no update is available', async () => {
|
it('should return null if no update is available', async () => {
|
||||||
|
|
@ -52,7 +53,7 @@ describe('checkForUpdate', () => {
|
||||||
|
|
||||||
const result = await checkForUpdate();
|
const result = await checkForUpdate();
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
expect(console.info).toHaveBeenCalledWith("no update: running 1.0.0, that's the latest published release");
|
expect(logger.info).toHaveBeenCalledWith("no update: running 1.0.0, that's the latest published release");
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return an update object if an update is available', async () => {
|
it('should return an update object if an update is available', async () => {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { logger } from "./logger";
|
||||||
import { isTauri } from "./storage";
|
import { isTauri } from "./storage";
|
||||||
|
|
||||||
interface AvailableUpdate {
|
interface AvailableUpdate {
|
||||||
|
|
@ -19,10 +20,10 @@ export async function checkForUpdate(): Promise<AvailableUpdate | null | "error"
|
||||||
// visible in devtools console — the fastest way to tell "already on
|
// visible in devtools console — the fastest way to tell "already on
|
||||||
// the latest published release" apart from "the check silently failed"
|
// the latest published release" apart from "the check silently failed"
|
||||||
const { getVersion } = await import("@tauri-apps/api/app");
|
const { getVersion } = await import("@tauri-apps/api/app");
|
||||||
console.info(`no update: running ${await getVersion()}, that's the latest published release`);
|
logger.info(`no update: running ${await getVersion()}, that's the latest published release`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
console.info(`update available: ${update.currentVersion} -> ${update.version}`);
|
logger.info(`update available: ${update.currentVersion} -> ${update.version}`);
|
||||||
return {
|
return {
|
||||||
version: update.version,
|
version: update.version,
|
||||||
async install() {
|
async install() {
|
||||||
|
|
@ -32,7 +33,7 @@ export async function checkForUpdate(): Promise<AvailableUpdate | null | "error"
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("update check failed", e);
|
logger.warn("update check failed", e);
|
||||||
return "error";
|
return "error";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue