mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 02:12:00 +03:00
chore: migrate updater console logs to Tauri logger
Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
parent
268ac9e81b
commit
43211b144b
7 changed files with 99 additions and 7 deletions
10
package-lock.json
generated
10
package-lock.json
generated
|
|
@ -19,6 +19,7 @@
|
|||
"@tauri-apps/plugin-autostart": "^2.3.0",
|
||||
"@tauri-apps/plugin-dialog": "^2.7.1",
|
||||
"@tauri-apps/plugin-global-shortcut": "^2.2.0",
|
||||
"@tauri-apps/plugin-log": "^2.9.0",
|
||||
"@tauri-apps/plugin-opener": "^2.2.0",
|
||||
"@tauri-apps/plugin-process": "^2.3.1",
|
||||
"@tauri-apps/plugin-updater": "^2.10.1",
|
||||
|
|
@ -1244,6 +1245,15 @@
|
|||
"@tauri-apps/api": "^2.11.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-log": {
|
||||
"version": "2.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-log/-/plugin-log-2.9.0.tgz",
|
||||
"integrity": "sha512-Ql8okrnsguk0eDq1GvRfttFV5KaeW/7vcao6bdbkXCRJ1+2sWE15ZJvJVEKVANrOKy1mRngqC3IFIAP+wP5qSw==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.11.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-opener": {
|
||||
"version": "2.5.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-opener/-/plugin-opener-2.5.4.tgz",
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
"@tauri-apps/plugin-autostart": "^2.3.0",
|
||||
"@tauri-apps/plugin-dialog": "^2.7.1",
|
||||
"@tauri-apps/plugin-global-shortcut": "^2.2.0",
|
||||
"@tauri-apps/plugin-log": "^2.9.0",
|
||||
"@tauri-apps/plugin-opener": "^2.2.0",
|
||||
"@tauri-apps/plugin-process": "^2.3.1",
|
||||
"@tauri-apps/plugin-updater": "^2.10.1",
|
||||
|
|
|
|||
69
src-tauri/Cargo.lock
generated
69
src-tauri/Cargo.lock
generated
|
|
@ -32,6 +32,23 @@ dependencies = [
|
|||
"alloc-no-stdlib",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android_log-sys"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84521a3cf562bc62942e294181d9eef17eb38ceb8c68677bc49f144e4c3d4f8d"
|
||||
|
||||
[[package]]
|
||||
name = "android_logger"
|
||||
version = "0.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dbb4e440d04be07da1f1bf44fb4495ebd58669372fe0cffa6e48595ac5bd88a3"
|
||||
dependencies = [
|
||||
"android_log-sys",
|
||||
"env_filter",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "android_system_properties"
|
||||
version = "0.1.5"
|
||||
|
|
@ -941,6 +958,16 @@ dependencies = [
|
|||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "env_filter"
|
||||
version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2"
|
||||
dependencies = [
|
||||
"log",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
|
|
@ -1004,6 +1031,15 @@ dependencies = [
|
|||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fern"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4316185f709b23713e41e3195f90edef7fb00c3ed4adc79769cf09cc762a3b29"
|
||||
dependencies = [
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "field-offset"
|
||||
version = "0.3.6"
|
||||
|
|
@ -2270,6 +2306,15 @@ dependencies = [
|
|||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_threads"
|
||||
version = "0.1.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc2"
|
||||
version = "0.6.4"
|
||||
|
|
@ -3736,6 +3781,7 @@ dependencies = [
|
|||
"tauri-plugin-autostart",
|
||||
"tauri-plugin-dialog",
|
||||
"tauri-plugin-global-shortcut",
|
||||
"tauri-plugin-log",
|
||||
"tauri-plugin-opener",
|
||||
"tauri-plugin-process",
|
||||
"tauri-plugin-single-instance",
|
||||
|
|
@ -4075,6 +4121,27 @@ dependencies = [
|
|||
"thiserror 2.0.18",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-log"
|
||||
version = "2.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6792296e6f389268016c77db21ebae1fc0568f2fccf88b1ec7e2ea71330afb4c"
|
||||
dependencies = [
|
||||
"android_logger",
|
||||
"fern",
|
||||
"log",
|
||||
"objc2",
|
||||
"objc2-foundation",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_repr",
|
||||
"swift-rs",
|
||||
"tauri",
|
||||
"tauri-plugin",
|
||||
"thiserror 2.0.18",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tauri-plugin-opener"
|
||||
version = "2.5.4"
|
||||
|
|
@ -4326,7 +4393,9 @@ checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c"
|
|||
dependencies = [
|
||||
"deranged",
|
||||
"itoa",
|
||||
"libc",
|
||||
"num-conv",
|
||||
"num_threads",
|
||||
"powerfmt",
|
||||
"serde_core",
|
||||
"time-core",
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ serde_json = "1"
|
|||
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
|
||||
chrono = "0.4"
|
||||
futures = "0.3.32"
|
||||
tauri-plugin-log = "2"
|
||||
|
||||
[profile.release]
|
||||
strip = true
|
||||
|
|
|
|||
|
|
@ -985,6 +985,7 @@ fn main() {
|
|||
.plugin(tauri_plugin_dialog::init())
|
||||
.plugin(tauri_plugin_updater::Builder::new().build())
|
||||
.plugin(tauri_plugin_process::init())
|
||||
.plugin(tauri_plugin_log::Builder::new().build())
|
||||
.manage(DroppedFiles::default())
|
||||
.manage(DataDirGate::default())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
|
|
|
|||
|
|
@ -19,11 +19,15 @@ vi.mock('@tauri-apps/plugin-process', () => ({
|
|||
relaunch: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('@tauri-apps/plugin-log', () => ({
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
info: vi.fn()
|
||||
}));
|
||||
|
||||
describe('checkForUpdate', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
vi.spyOn(console, 'info').mockImplementation(() => {});
|
||||
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
it('should return null if not in Tauri', async () => {
|
||||
|
|
@ -39,7 +43,8 @@ describe('checkForUpdate', () => {
|
|||
|
||||
const result = await checkForUpdate();
|
||||
expect(result).toBe('error');
|
||||
expect(console.warn).toHaveBeenCalledWith('update check failed', expect.any(Error));
|
||||
const { warn } = await import('@tauri-apps/plugin-log');
|
||||
expect(warn).toHaveBeenCalledWith('update check failed: Error: Network error');
|
||||
});
|
||||
|
||||
it('should return null if no update is available', async () => {
|
||||
|
|
@ -52,7 +57,8 @@ describe('checkForUpdate', () => {
|
|||
|
||||
const result = await checkForUpdate();
|
||||
expect(result).toBeNull();
|
||||
expect(console.info).toHaveBeenCalledWith("no update: running 1.0.0, that's the latest published release");
|
||||
const { info } = await import('@tauri-apps/plugin-log');
|
||||
expect(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 () => {
|
||||
|
|
@ -71,6 +77,9 @@ describe('checkForUpdate', () => {
|
|||
if (result !== 'error' && result !== null) {
|
||||
expect(result.version).toBe('1.1.0');
|
||||
|
||||
const { info } = await import('@tauri-apps/plugin-log');
|
||||
expect(info).toHaveBeenCalledWith('update available: 1.0.0 -> 1.1.0');
|
||||
|
||||
const { relaunch } = await import('@tauri-apps/plugin-process');
|
||||
await result.install();
|
||||
expect(mockUpdate.downloadAndInstall).toHaveBeenCalled();
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { info, warn } from "@tauri-apps/plugin-log";
|
||||
import { isTauri } from "./storage";
|
||||
|
||||
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
|
||||
// the latest published release" apart from "the check silently failed"
|
||||
const { getVersion } = await import("@tauri-apps/api/app");
|
||||
console.info(`no update: running ${await getVersion()}, that's the latest published release`);
|
||||
info(`no update: running ${await getVersion()}, that's the latest published release`);
|
||||
return null;
|
||||
}
|
||||
console.info(`update available: ${update.currentVersion} -> ${update.version}`);
|
||||
info(`update available: ${update.currentVersion} -> ${update.version}`);
|
||||
return {
|
||||
version: update.version,
|
||||
async install() {
|
||||
|
|
@ -32,7 +33,7 @@ export async function checkForUpdate(): Promise<AvailableUpdate | null | "error"
|
|||
},
|
||||
};
|
||||
} catch (e) {
|
||||
console.warn("update check failed", e);
|
||||
warn(`update check failed: ${e}`);
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue