Skip to content

Commit 9c153d3

Browse files
committed
Add platform detection functionality and cache implementation
1 parent 8c7424c commit 9c153d3

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

frontend/src/common/DesktopApp.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export interface DesktopPlatformVersion {
2+
appVersion: string; // 1.0.0
3+
arch: string; // x64
4+
platform: string; // linux
5+
version: string; // 6.15.7-1-MANJARO
6+
}
7+
8+
export async function getPlatform(): Promise<DesktopPlatformVersion | null> {
9+
if ((window as any).electronAPI) {
10+
return await (window as any).electronAPI.getPlatform();
11+
}
12+
return null;
13+
}
14+
15+
export const platformCache: {
16+
platform: DesktopPlatformVersion | null;
17+
} = {
18+
platform: null
19+
};

frontend/src/index.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ThemeProvider } from "@emotion/react";
66
import { CssBaseline, createTheme } from "@mui/material";
77
import { BrowserRouter } from "react-router-dom";
88
import { makeid, uuidv4 } from "./plex/QuickFunctions";
9+
import { getPlatform, platformCache } from "./common/DesktopApp";
910

1011
import "@fontsource-variable/quicksand";
1112
import "@fontsource-variable/rubik";
@@ -37,6 +38,19 @@ const root = ReactDOM.createRoot(
3738
document.getElementById("root") as HTMLElement
3839
);
3940

41+
getPlatform().then((platformData) => {
42+
if(!platformData) return;
43+
44+
// make platformData.platform lowercase but capitalize the first letter
45+
platformData.platform = platformData.platform.charAt(0).toUpperCase() + platformData.platform.slice(1).toLowerCase();
46+
47+
platformCache.platform = platformData;
48+
49+
if (platformCache.platform)
50+
console.log("Platform detected:", platformCache.platform);
51+
else console.warn("Platform detection failed.");
52+
});
53+
4054
root.render(
4155
<ThemeProvider
4256
theme={createTheme({
@@ -99,7 +113,7 @@ root.render(
99113
styleOverrides: {
100114
root: {
101115
height: "100vh",
102-
zIndex: 200
116+
zIndex: 200,
103117
},
104118
},
105119
},
@@ -111,4 +125,4 @@ root.render(
111125
<App />
112126
</BrowserRouter>
113127
</ThemeProvider>
114-
);
128+
);

frontend/src/plex/QuickFunctions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ProxiedRequest } from "../backendURL";
2+
import { platformCache } from "../common/DesktopApp";
23
import { useSessionStore } from "../states/SessionState";
34

45
export async function authedGet(url: string) {
@@ -52,8 +53,8 @@ export function getXPlexProps() {
5253
"X-Plex-Product": "NEVU",
5354
"X-Plex-Version": "0.1.0",
5455
"X-Plex-Client-Identifier": localStorage.getItem("clientID"),
55-
"X-Plex-Platform": getBrowserName(),
56-
"X-Plex-Platform-Version": getBrowserVersion(),
56+
"X-Plex-Platform": platformCache.platform?.platform ?? getBrowserName(),
57+
"X-Plex-Platform-Version": platformCache.platform?.version ?? getBrowserVersion(),
5758
"X-Plex-Features": "external-media,indirect-media,hub-style-list",
5859
"X-Plex-Model": "bundled",
5960
"X-Plex-Device": getBrowserName(),

0 commit comments

Comments
 (0)