Skip to content

Commit d3bb110

Browse files
committed
Add logs
1 parent 6de13d4 commit d3bb110

File tree

12 files changed

+642
-45
lines changed

12 files changed

+642
-45
lines changed

bun.lock

Lines changed: 377 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"bump-major": "bunx tauri-version --no-git --no-lock major"
1414
},
1515
"dependencies": {
16+
"@fltsci/tauri-plugin-tracing": "^0.3.2",
1617
"@tauri-apps/api": "^2.10.1",
1718
"@tauri-apps/plugin-dialog": "~2.6.0",
1819
"@tauri-apps/plugin-opener": "^2.5.3",

src-tauri/Cargo.lock

Lines changed: 129 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tauri-plugin-dialog = "2"
3232
reqwest = "0.13.2"
3333
tokio = "1.49.0"
3434
tauri-plugin-process = "2"
35+
tauri-plugin-tracing = "0.3"
3536

3637
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
3738
tauri-plugin-updater = "2"

src-tauri/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::{
1818
sideload::{install_sidestore_operation, sideload_operation, SideloaderMutex},
1919
};
2020
use tauri::Manager;
21+
use tauri_plugin_tracing::LevelFilter;
2122

2223
#[cfg_attr(mobile, tauri::mobile_entry_point)]
2324
pub fn run() {
@@ -27,6 +28,12 @@ pub fn run() {
2728
.plugin(tauri_plugin_opener::init())
2829
.plugin(tauri_plugin_dialog::init())
2930
.plugin(tauri_plugin_store::Builder::new().build())
31+
.plugin(
32+
tauri_plugin_tracing::Builder::new()
33+
.with_max_level(LevelFilter::INFO)
34+
.with_default_subscriber()
35+
.build(),
36+
)
3037
.setup(|app| {
3138
app.manage(DeviceInfoMutex::new(None));
3239
app.manage(SideloaderMutex::new(None));

src/LogContext.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React, {
2+
createContext,
3+
useContext,
4+
useState,
5+
useEffect,
6+
useRef,
7+
} from "react";
8+
9+
import { attachLogger, RecordPayload } from '@fltsci/tauri-plugin-tracing';
10+
11+
export const LogContext = createContext<RecordPayload[]>([]);
12+
13+
export const LogProvider: React.FC<{ children: React.ReactNode }> = ({
14+
children,
15+
}) => {
16+
const [logs, setLogs] = useState<RecordPayload[]>([]);
17+
const listenerAdded = useRef<boolean>(false);
18+
let unlistenRef = useRef<(() => void) | null>(null);
19+
20+
useEffect(() => {
21+
if (!listenerAdded.current) {
22+
const setupLogger = async () => {
23+
listenerAdded.current = true;
24+
unlistenRef.current = await attachLogger((record) => {
25+
console.log(record)
26+
setLogs((prevLogs) => [...prevLogs, record]);
27+
});
28+
};
29+
30+
setupLogger();
31+
}
32+
33+
return () => {
34+
if (unlistenRef.current) {
35+
unlistenRef.current();
36+
}
37+
};
38+
}, []);
39+
40+
return (
41+
<LogContext.Provider value={logs}>
42+
{children}
43+
</LogContext.Provider>
44+
);
45+
};
46+
47+
export const useLogs = () => {
48+
return useContext(LogContext);
49+
};

src/SideStore.tsx

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/components/OperationView.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
margin: 0.5rem 0 0;
4646
font-family: "SF Mono", "Menlo", monospace;
4747
font-size: 0.85rem;
48+
user-select: text;
4849
}
4950

5051
.operation-step-internal {
@@ -84,6 +85,7 @@
8485
from {
8586
transform: rotate(0deg);
8687
}
88+
8789
to {
8890
transform: rotate(360deg);
8991
}
@@ -113,4 +115,4 @@
113115
.operation-success-message {
114116
font-weight: 600;
115117
color: rgb(241, 212, 115);
116-
}
118+
}

src/components/OperationView.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default ({
1919
const done =
2020
(opFailed &&
2121
operationState.started.length ==
22-
operationState.completed.length + operationState.failed.length) ||
22+
operationState.completed.length + operationState.failed.length) ||
2323
operationState.completed.length == operation.steps.length;
2424

2525
return (
@@ -74,7 +74,6 @@ export default ({
7474
<p>{step.title}</p>
7575
{failed && (
7676
<pre className="operation-extra-details">
77-
{/* trim newlines BUT NOT SPACES before */}
7877
{failed.extraDetails.replace(/^\n+/, "")}
7978
</pre>
8079
)}

0 commit comments

Comments
 (0)