Skip to content

Commit fb5da05

Browse files
authored
feat: better debug (#486)
* fix: tauri os plugin not being fully loaded * feat: debug keybind Bound to `CTRL+SHIFT+D` (and `ALT+F12`) and copies the debug info to the clipboard * refactor: __root.tx Clean up a lot of code and move them into there own files * feat: os distro in debug * refactor: get_full_debug_info_parsed * feat: made by info in settings Also made it so that you can click on it to copy debug info * fix: warning in oneclient/desktop/lib.rs * refactor: copyDebugInfo Moved it to the backend to later be used * feat: log out debug info when oneclient launches * `inDev` -> `In Dev` * feat: toggle debug logging * fix rust compiler
1 parent 45db558 commit fb5da05

23 files changed

Lines changed: 438 additions & 284 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ tauri-plugin-deep-link = { version = "=2.2.1" }
5050
tauri-plugin-dialog = { version = "=2.2.1" }
5151
tauri-plugin-fs = { version = "=2.2.1", features = ["watch"] }
5252
tauri-plugin-os = { version = "=2.2.1" }
53+
tauri-plugin-global-shortcut = { version = "=2.2.1" }
5354
tauri-plugin-single-instance = { version = "=2.2.3" }
5455
tauri-plugin-updater = { version = "=2.7.1" }
5556
tauri-plugin-window-state = { version = "=2.2.2" }

apps/oneclient/desktop/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ tauri-plugin-clipboard-manager = { workspace = true }
3838
tauri-plugin-dialog = { workspace = true }
3939
tauri-plugin-fs = { workspace = true }
4040
tauri-plugin-os = { workspace = true }
41+
tauri-plugin-global-shortcut = { workspace = true }
4142
tauri-plugin-deep-link = { workspace = true }
4243

4344
# code gen

apps/oneclient/desktop/capabilities/default.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,19 @@
3737
"fs:allow-download-write",
3838
"fs:allow-data-read-recursive",
3939
"fs:allow-data-write-recursive",
40-
"fs:allow-watch",
40+
"fs:allow-watch",
41+
4142
"os:deny-hostname",
4243
"os:allow-locale",
4344
"os:allow-os-type",
4445
"os:allow-platform",
4546
"os:allow-version",
4647
"os:allow-arch",
4748
"os:deny-exe-extension",
48-
"os:allow-family"
49+
"os:allow-family",
50+
51+
"global-shortcut:allow-is-registered",
52+
"global-shortcut:allow-register",
53+
"global-shortcut:allow-unregister"
4954
]
5055
}

apps/oneclient/desktop/src/lib.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use onelauncher_core::api::proxy::ProxyTauri;
2-
use onelauncher_core::api::tauri::TauRPCLauncherExt;
2+
use onelauncher_core::api::tauri::{TauRPCLauncherExt, TauriLauncherDebugApi};
33
use onelauncher_core::error::LauncherResult;
44
use onelauncher_core::store::proxy::ProxyState;
55
use onelauncher_core::store::semaphore::SemaphoreStore;
@@ -48,6 +48,12 @@ async fn initialize_core() -> LauncherResult<()> {
4848
SemaphoreStore::get().await;
4949
tracing::info!("initialized core modules");
5050

51+
let debug_info = onelauncher_core::api::tauri::TauriLauncherDebugApiImpl
52+
.get_full_debug_info_parsed_string()
53+
.await;
54+
55+
tracing::info!("\n{}", debug_info);
56+
5157
Ok(())
5258
}
5359

@@ -75,11 +81,17 @@ async fn initialize_tauri(builder: tauri::Builder<tauri::Wry>) -> LauncherResult
7581
.plugin(tauri_plugin_dialog::init())
7682
.plugin(tauri_plugin_fs::init())
7783
.plugin(tauri_plugin_deep_link::init())
84+
.plugin(tauri_plugin_os::init())
7885
.menu(tauri::menu::Menu::default)
7986
.invoke_handler(router.into_handler())
8087
.setup(move |app| {
8188
app.manage(ext::updater::UpdaterState::default());
8289
setup_window(app.handle()).expect("failed to setup main window");
90+
91+
#[cfg(desktop)]
92+
app.handle()
93+
.plugin(tauri_plugin_global_shortcut::Builder::new().build())?;
94+
8395
Ok(())
8496
});
8597

apps/oneclient/frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@tauri-apps/plugin-clipboard-manager": "catalog:",
3030
"@tauri-apps/plugin-dialog": "catalog:",
3131
"@tauri-apps/plugin-fs": "catalog:",
32+
"@tauri-apps/plugin-global-shortcut": "catalog:",
3233
"@untitled-theme/icons-react": "catalog:",
3334
"fuse.js": "^7.1.0",
3435
"motion": "catalog:",

apps/oneclient/frontend/src/bindings.gen.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export type DaoError = { type: "NotFound"; data: string } | { type: "AlreadyExis
2929

3030
export type DbVec = T[]
3131

32+
export type DebugInfoData = { inDev: boolean; platform: string; arch: string; family: string; locale: string; osType: string; osVersion: string; osDistro: string; commitHash: string; buildTimestamp: string; buildVersion: string }
33+
34+
export type DebugInfoParsedLine = { title: string; value: string }
35+
3236
export type DirectoryError = { type: "BaseDir"; data: string }
3337

3438
export type DiscordError = { type: "MissingClientId"; data: string } | { type: "ConnectError"; data: string }
@@ -244,9 +248,9 @@ gallery: string[] }
244248

245249
export type SettingProfileModel = { name: string; java_id: number | null; res: Resolution | null; force_fullscreen: boolean | null; mem_max: number | null; launch_args: string | null; launch_env: string | null; hook_pre: string | null; hook_wrapper: string | null; hook_post: string | null; os_extra: SettingsOsExtra | null }
246250

247-
export type Settings = { global_game_settings: SettingProfileModel; allow_parallel_running_clusters: boolean; enable_gamemode: boolean; discord_enabled: boolean; seen_onboarding: boolean; mod_list_use_grid: boolean; max_concurrent_requests: number; settings_version: number; native_window_frame: boolean; show_tanstack_dev_tools: boolean }
251+
export type Settings = { global_game_settings: SettingProfileModel; allow_parallel_running_clusters: boolean; enable_gamemode: boolean; discord_enabled: boolean; seen_onboarding: boolean; mod_list_use_grid: boolean; max_concurrent_requests: number; settings_version: number; native_window_frame: boolean; log_debug_info: boolean; show_tanstack_dev_tools: boolean }
248252

249-
export type SettingsOsExtra = Record<string, never>
253+
export type SettingsOsExtra = { enable_gamemode: boolean | null }
250254

251255
export type SkinVariant = "classic" | "slim"
252256

@@ -313,18 +317,27 @@ export type VersionType =
313317
*/
314318
"old_beta"
315319

316-
const ARGS_MAP = { 'oneclient':'{"getBundlesFor":["cluster_id"],"extractBundleOverrides":["bundle_path","cluster_id"],"getVersions":[],"isBundleSyncing":[],"cacheArt":["path"],"checkForUpdate":[],"updateBundlePackages":["cluster_id"],"refreshArt":["path"],"getClustersGroupedByMajor":[],"downloadPackageFromBundle":["package","cluster_id","bundle_name","skip_compatibility"],"installUpdate":[]}', 'core':'{"getLogs":["id"],"getProfileOrDefault":["name"],"getClusters":[],"installModpack":["modpack","cluster_id"],"downloadExternalPackage":["package","cluster_id","force","skip_compatibility"],"refreshAccounts":[],"updateClusterById":["id","request"],"launchCluster":["id","uuid","search_for_java"],"getGlobalProfile":[],"createCluster":["options"],"searchPackages":["provider","query"],"removeUser":["uuid"],"getPackageVersions":["provider","slug","mc_version","loader","offset","limit"],"getDefaultUser":["fallback"],"removeCape":["access_token"],"removePackage":["cluster_id","package_hash"],"removeCluster":["id"],"getMultiplePackages":["provider","slugs"],"syncCluster":["cluster_id"],"getLinkedPackages":["cluster_id"],"fetchMinecraftProfile":["uuid"],"refreshAccount":["uuid"],"getRunningProcessesByClusterId":["cluster_id"],"downloadPackage":["provider","package_id","version_id","cluster_id","skip_compatibility"],"isClusterRunning":["cluster_id"],"setClusterStage":["id","stage"],"killProcess":["pid"],"getLogByName":["id","name"],"getUsersFromAuthor":["provider","author"],"togglePackage":["cluster_id","package_hash"],"getScreenshots":["id"],"writeSettings":["setting"],"fetchLoggedInProfile":["access_token"],"changeSkin":["access_token","skin_url","skin_variant"],"openMsaLogin":[],"convertUsernameUUID":["username_uuid"],"getClusterById":["id"],"getRunningProcesses":[],"getLoadersForVersion":["mc_version"],"getUsers":[],"createSettingsProfile":["name"],"getUser":["uuid"],"readSettings":[],"setDefaultUser":["uuid"],"getPackageBody":["provider","body"],"updateClusterProfile":["name","profile"],"uploadSkinBytes":["access_token","skin_data","image_format","skin_variant"],"getWorlds":["id"],"getProcessLogTail":["id","max_lines"],"changeCape":["access_token","cape_uuid"],"getGameVersions":[],"setDiscordRPCMessage":["message"],"open":["input"],"getPackage":["provider","slug"]}', 'events':'{"process":["event"],"ingress":["event"],"message":["event"]}', 'debug':'{"getGitCommitHash":[],"getPackageVersion":[],"getFamily":[],"getOsVersion":[],"openDevTools":[],"getArch":[],"getBuildTimestamp":[],"getType":[],"isInDev":[],"getLocale":[],"getPlatform":[]}', 'folders':'{"fromCluster":["folder_name"],"openCluster":["folder_name"]}' }
317-
export type Router = { 'debug': { openDevTools: () => Promise<void>,
320+
const ARGS_MAP = { 'debug':'{"getFullDebugInfoParsedString":[],"getBuildTimestamp":[],"getPackageVersion":[],"openDevTools":[],"getFamily":[],"getArch":[],"isInDev":[],"getFullDebugInfo":[],"getType":[],"getLocale":[],"getPlatform":[],"getOsDistro":[],"getGitCommitHash":[],"getOsVersion":[],"getFullDebugInfoParsed":[]}', 'oneclient':'{"updateBundlePackages":["cluster_id"],"installUpdate":[],"checkForUpdate":[],"cacheArt":["path"],"extractBundleOverrides":["bundle_path","cluster_id"],"isBundleSyncing":[],"getBundlesFor":["cluster_id"],"downloadPackageFromBundle":["package","cluster_id","bundle_name","skip_compatibility"],"getVersions":[],"getClustersGroupedByMajor":[],"refreshArt":["path"]}', 'events':'{"ingress":["event"],"message":["event"],"process":["event"]}', 'folders':'{"fromCluster":["folder_name"],"openCluster":["folder_name"]}', 'core':'{"removeCape":["access_token"],"changeSkin":["access_token","skin_url","skin_variant"],"getLinkedPackages":["cluster_id"],"fetchMinecraftProfile":["uuid"],"downloadPackage":["provider","package_id","version_id","cluster_id","skip_compatibility"],"updateClusterById":["id","request"],"getLogs":["id"],"openMsaLogin":[],"getGameVersions":[],"setDefaultUser":["uuid"],"syncCluster":["cluster_id"],"refreshAccount":["uuid"],"removeCluster":["id"],"removePackage":["cluster_id","package_hash"],"convertUsernameUUID":["username_uuid"],"getClusterById":["id"],"fetchLoggedInProfile":["access_token"],"removeUser":["uuid"],"getLogByName":["id","name"],"launchCluster":["id","uuid","search_for_java"],"readSettings":[],"createCluster":["options"],"getGlobalProfile":[],"isClusterRunning":["cluster_id"],"searchPackages":["provider","query"],"getRunningProcessesByClusterId":["cluster_id"],"refreshAccounts":[],"getDefaultUser":["fallback"],"getUsers":[],"getPackage":["provider","slug"],"getPackageBody":["provider","body"],"getClusters":[],"getPackageVersions":["provider","slug","mc_version","loader","offset","limit"],"downloadExternalPackage":["package","cluster_id","force","skip_compatibility"],"setDiscordRPCMessage":["message"],"updateClusterProfile":["name","profile"],"setClusterStage":["id","stage"],"getUser":["uuid"],"killProcess":["pid"],"getWorlds":["id"],"installModpack":["modpack","cluster_id"],"open":["input"],"createSettingsProfile":["name"],"getProcessLogTail":["id","max_lines"],"getMultiplePackages":["provider","slugs"],"getRunningProcesses":[],"getLoadersForVersion":["mc_version"],"getProfileOrDefault":["name"],"writeSettings":["setting"],"getScreenshots":["id"],"getUsersFromAuthor":["provider","author"],"togglePackage":["cluster_id","package_hash"],"changeCape":["access_token","cape_uuid"],"uploadSkinBytes":["access_token","skin_data","image_format","skin_variant"]}' }
321+
export type Router = { 'events': { ingress: (event: IngressPayload) => Promise<void>,
322+
message: (event: MessagePayload) => Promise<void>,
323+
process: (event: ProcessPayload) => Promise<void> },
324+
'folders': { fromCluster: (folderName: string) => Promise<string>,
325+
openCluster: (folderName: string) => Promise<null> },
326+
'debug': { openDevTools: () => Promise<void>,
318327
isInDev: () => Promise<boolean>,
319328
getArch: () => Promise<string>,
320329
getFamily: () => Promise<string>,
321-
getLocale: () => Promise<string | null>,
330+
getLocale: () => Promise<string>,
322331
getType: () => Promise<string>,
323332
getPlatform: () => Promise<string>,
324333
getOsVersion: () => Promise<string>,
334+
getOsDistro: () => Promise<string>,
325335
getGitCommitHash: () => Promise<string>,
326336
getBuildTimestamp: () => Promise<string>,
327-
getPackageVersion: () => Promise<string> },
337+
getPackageVersion: () => Promise<string>,
338+
getFullDebugInfo: () => Promise<DebugInfoData>,
339+
getFullDebugInfoParsed: () => Promise<DebugInfoParsedLine[]>,
340+
getFullDebugInfoParsedString: () => Promise<string> },
328341
'core': { getClusters: () => Promise<ClusterModel[]>,
329342
getClusterById: (id: number) => Promise<ClusterModel | null>,
330343
removeCluster: (id: number) => Promise<null>,
@@ -389,12 +402,7 @@ downloadPackageFromBundle: (package: ModpackFileKind, clusterId: number, bundleN
389402
updateBundlePackages: (clusterId: number) => Promise<ApplyBundleUpdatesResult>,
390403
isBundleSyncing: () => Promise<boolean>,
391404
cacheArt: (path: string) => Promise<string>,
392-
refreshArt: (path: string) => Promise<null> },
393-
'events': { ingress: (event: IngressPayload) => Promise<void>,
394-
message: (event: MessagePayload) => Promise<void>,
395-
process: (event: ProcessPayload) => Promise<void> },
396-
'folders': { fromCluster: (folderName: string) => Promise<string>,
397-
openCluster: (folderName: string) => Promise<null> } };
405+
refreshArt: (path: string) => Promise<null> } };
398406

399407

400408
export type { InferCommandOutput }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { bindings } from '@/main';
2+
import { copyDebugInfo } from '@/utils/debugInfo';
3+
import { useCommand } from '@onelauncher/common';
4+
import { Button } from '@onelauncher/common/components';
5+
6+
export function MadeBy() {
7+
const { data: version } = useCommand(['getPackageVersion'], () => bindings.debug.getPackageVersion());
8+
const { data: isInDev } = useCommand(['isInDev'], () => bindings.debug.isInDev());
9+
10+
return (
11+
<Button
12+
className="flex flex-col items-start p-4 text-xs text-fg-secondary"
13+
color="ghost"
14+
onClick={copyDebugInfo}
15+
>
16+
<p>OneClient by Polyfrost</p>
17+
<p>Version {version}</p>
18+
<p>{isInDev ? 'Development' : 'Release'} Build</p>
19+
</Button>
20+
);
21+
}

apps/oneclient/frontend/src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export * from './GameBackground';
88
export * from './LaunchButton';
99
export * from './Loader';
1010
export * from './LogViewer';
11+
export * from './MadeBy';
1112
export * from './ManageSkinButton';
1213
export * from './Markdown';
1314
export * from './Navbar';
Lines changed: 3 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,7 @@
1+
import type { DebugInfoArray } from '@/utils/debugInfo';
12
import { Overlay } from '@/components';
2-
import { bindings } from '@/main';
3+
import { copyDebugInfo, useDebugInfo } from '@/utils/debugInfo';
34
import { Button } from '@onelauncher/common/components';
4-
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
5-
import { useEffect, useState } from 'react';
6-
7-
export type DebugInfoArray = Array<{ title: string; value: string }>;
8-
export interface DebugInfoData {
9-
inDev: boolean;
10-
platform: string;
11-
arch: string;
12-
family: string;
13-
locale: string;
14-
type: string;
15-
osVersion: string;
16-
commitHash: string;
17-
buildTimestamp: string;
18-
buildVersion: string;
19-
}
20-
21-
export function useDebugInfo(): DebugInfoArray {
22-
const [devInfo, setDevInfo] = useState<DebugInfoData>({
23-
inDev: false,
24-
platform: 'UNKNOWN',
25-
arch: 'UNKNOWN',
26-
family: 'UNKNOWN',
27-
locale: 'UNKNOWN',
28-
type: 'UNKNOWN',
29-
osVersion: 'UNKNOWN',
30-
commitHash: 'UNKNOWN',
31-
buildTimestamp: 'UNKNOWN',
32-
buildVersion: 'UNKNOWN',
33-
});
34-
35-
useEffect(() => {
36-
const fetchDevInfo = async () => {
37-
const [
38-
inDev,
39-
platform,
40-
arch,
41-
family,
42-
locale,
43-
type,
44-
osVersion,
45-
commitHash,
46-
buildTimestamp,
47-
buildVersion,
48-
] = await Promise.all([
49-
bindings.debug.isInDev(),
50-
bindings.debug.getPlatform(),
51-
bindings.debug.getArch(),
52-
bindings.debug.getFamily(),
53-
bindings.debug.getLocale(),
54-
bindings.debug.getType(),
55-
bindings.debug.getOsVersion(),
56-
bindings.debug.getGitCommitHash(),
57-
bindings.debug.getBuildTimestamp(),
58-
bindings.debug.getPackageVersion(),
59-
]);
60-
61-
setDevInfo({
62-
inDev,
63-
platform,
64-
arch,
65-
family,
66-
locale: locale ?? 'UNKNOWN',
67-
type,
68-
osVersion,
69-
commitHash,
70-
buildTimestamp,
71-
buildVersion,
72-
});
73-
};
74-
75-
void fetchDevInfo();
76-
}, []);
77-
78-
return [
79-
{ title: 'inDev', value: devInfo.inDev ? 'yes' : 'no' },
80-
{ title: 'Platform', value: devInfo.platform },
81-
{ title: 'Arch', value: devInfo.arch },
82-
{ title: 'Family', value: devInfo.family },
83-
{ title: 'Locale', value: devInfo.locale },
84-
{ title: 'Type', value: devInfo.type },
85-
{ title: 'Os Version', value: devInfo.osVersion },
86-
{ title: 'Commit Hash', value: devInfo.commitHash },
87-
{ title: 'Build Timestamp', value: devInfo.buildTimestamp },
88-
{ title: 'Version', value: devInfo.buildVersion },
89-
];
90-
}
91-
92-
export function copyDebugInfo(debugInfo: DebugInfoArray) {
93-
const timestamp = Math.floor(new Date().getTime() / 1000);
94-
const lines = [
95-
`**Data exported at:** <t:${timestamp}> (\`${timestamp}\`)`,
96-
...debugInfo.map((lineData) => {
97-
if (lineData.title === 'Build Timestamp')
98-
return `**${lineData.title}:** <t:${lineData.value}> (\`${lineData.value}\`)`;
99-
return `**${lineData.title}:** \`${lineData.value}\``;
100-
}),
101-
];
102-
writeText(lines.join('\n'));
103-
}
1045

1056
export function DebugInfo() {
1067
const debugInfo = useDebugInfo();
@@ -113,7 +14,6 @@ export function DebugInfo() {
11314
}
11415

11516
export function RawDebugInfo({ debugInfo }: { debugInfo: DebugInfoArray }) {
116-
const copy = () => copyDebugInfo(debugInfo);
11717
return (
11818
<>
11919
<div>
@@ -126,7 +26,7 @@ export function RawDebugInfo({ debugInfo }: { debugInfo: DebugInfoArray }) {
12626
return <p key={lineData.title}>{line}</p>;
12727
})}
12828
</div>
129-
<Button onPress={copy}>Copy Data</Button>
29+
<Button onPress={copyDebugInfo}>Copy Data</Button>
13030
</>
13131
);
13232
}

0 commit comments

Comments
 (0)