Fix Add Server menu does not recognize servers not using HTTPS or using the :8096 port. #74
This commit is contained in:
5 files changed
+74
-112
No files matched your search
@@ -17,8 +17,10 @@ tauri-build = { version = "1.2.1", features = [] }
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
tauri = { version = "1.2.2", features = ["process-exit", "process-relaunch", "shell-all", "window-set-fullscreen"] }
|
tauri = { version = "1.2.2", features = ["api-all", "devtools"] }
|
||||||
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
|
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "dev" }
|
||||||
|
tauri-plugin-localhost = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
|
||||||
|
portpicker = "0.1" # used in the example to pick a random free port
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# by default Tauri runs in production mode
|
# by default Tauri runs in production mode
|
||||||
|
|||||||
+34
-2
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
use tauri::Manager;
|
use tauri::Manager;
|
||||||
|
|
||||||
|
use tauri::{utils::config::AppUrl, WindowUrl};
|
||||||
|
|
||||||
// Create the command:
|
// Create the command:
|
||||||
// This command must be async so that it doesn't run on the main thread.
|
// This command must be async so that it doesn't run on the main thread.
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -14,10 +16,40 @@ async fn close_splashscreen(window: tauri::Window) {
|
|||||||
window.get_window("main").unwrap().show().unwrap();
|
window.get_window("main").unwrap().show().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tauri by default uses HTTPS, so use the localhost plugin to downgrade back to
|
||||||
|
// HTTP. However, when running tauri dev, we already have a localhost server
|
||||||
|
// provided by vite, so don't enable it
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
const USE_LOCALHOST_SERVER: bool = false;
|
||||||
|
#[cfg(not(debug_assertions))]
|
||||||
|
const USE_LOCALHOST_SERVER: bool = true;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
tauri::Builder::default()
|
let port = portpicker::pick_unused_port().expect("failed to find unused port");
|
||||||
|
|
||||||
|
let window_url = if USE_LOCALHOST_SERVER {
|
||||||
|
WindowUrl::External(format!("http://localhost:{}", port).parse().unwrap())
|
||||||
|
} else {
|
||||||
|
WindowUrl::App("index.html".into())
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut context = tauri::generate_context!();
|
||||||
|
let mut builder = tauri::Builder::default();
|
||||||
|
|
||||||
|
if USE_LOCALHOST_SERVER {
|
||||||
|
// rewrite the config so the IPC is enabled on this URL
|
||||||
|
context.config_mut().build.dist_dir = AppUrl::Url(window_url.clone());
|
||||||
|
context.config_mut().build.dev_path = AppUrl::Url(window_url.clone());
|
||||||
|
builder = builder.plugin(tauri_plugin_localhost::Builder::new(port).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
builder
|
||||||
.invoke_handler(tauri::generate_handler![close_splashscreen])
|
.invoke_handler(tauri::generate_handler![close_splashscreen])
|
||||||
.plugin(tauri_plugin_store::Builder::default().build())
|
.plugin(tauri_plugin_store::Builder::default().build())
|
||||||
.run(tauri::generate_context!())
|
.run(context)
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
// tauri::Builder::default()
|
||||||
|
// .run(tauri::generate_context!())
|
||||||
|
// .expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
},
|
},
|
||||||
"tauri": {
|
"tauri": {
|
||||||
"allowlist": {
|
"allowlist": {
|
||||||
"all": false,
|
|
||||||
"process": {
|
"process": {
|
||||||
"all": false,
|
"all": false,
|
||||||
"exit": true,
|
"exit": true,
|
||||||
@@ -24,6 +23,9 @@
|
|||||||
},
|
},
|
||||||
"shell": {
|
"shell": {
|
||||||
"all": true
|
"all": true
|
||||||
|
},
|
||||||
|
"http": {
|
||||||
|
"all": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bundle": {
|
"bundle": {
|
||||||
|
|||||||
+13
-49
@@ -130,7 +130,7 @@ function App() {
|
|||||||
|
|
||||||
const [serverReachable, setServerReachable] = useState(true);
|
const [serverReachable, setServerReachable] = useState(true);
|
||||||
|
|
||||||
const enqueueSnackbar = useSnackbar();
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
const createApi = async () => {
|
const createApi = async () => {
|
||||||
const server = await getServer();
|
const server = await getServer();
|
||||||
@@ -165,60 +165,25 @@ function App() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const pingServer = useQuery({
|
const pingServer = async () => {
|
||||||
queryKey: ["setup", "server"],
|
const server = await getServer();
|
||||||
queryFn: async () => {
|
|
||||||
let serverUrl = window.api.basePath.replace(/\/$/, "").trim();
|
|
||||||
const candidates =
|
|
||||||
await jellyfin.discovery.getRecommendedServerCandidates(
|
|
||||||
serverUrl,
|
|
||||||
);
|
|
||||||
const best = jellyfin.discovery.findBestServer(candidates);
|
|
||||||
if (best) {
|
|
||||||
const issues = candidates.flatMap((s) => s.issues);
|
|
||||||
if (
|
|
||||||
issues.some(
|
|
||||||
(i) =>
|
|
||||||
i instanceof VersionOutdatedIssue ||
|
|
||||||
i instanceof VersionUnsupportedIssue,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
setServerReachable(false);
|
|
||||||
enqueueSnackbar(
|
|
||||||
"Please Update your server to latest Jellyfin version to use this client",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const api = jellyfin.createApi(best.address);
|
const result = await axios.get(
|
||||||
const { data } = await getSystemApi(
|
new URL(`${server.Ip}/System/Ping`).href,
|
||||||
api,
|
);
|
||||||
).getPublicSystemInfo();
|
if (result.data == "Jellyfin Server") {
|
||||||
delete data.LocalAddress;
|
event.emit("create-jellyfin-api", server.Ip);
|
||||||
const serv = {
|
|
||||||
...data,
|
|
||||||
PublicAddress: best.address,
|
|
||||||
isDefault: false,
|
|
||||||
};
|
|
||||||
if (serv.StartupWizardCompleted) {
|
|
||||||
setServerReachable(true);
|
setServerReachable(true);
|
||||||
} else {
|
} else {
|
||||||
setServerReachable(false);
|
setServerReachable(false);
|
||||||
enqueueSnackbar(
|
|
||||||
"Server setup not complete. Please complete your server setup.",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setServerReachable(false);
|
setServerReachable(false);
|
||||||
enqueueSnackbar("Server not found.", { variant: "error" });
|
enqueueSnackbar("Unable to verfiy server address.", {
|
||||||
}
|
variant: "error",
|
||||||
return "";
|
|
||||||
},
|
|
||||||
// enabled: false,
|
|
||||||
refetchOnWindowFocus: false,
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const userLogin = async () => {
|
const userLogin = async () => {
|
||||||
const user = await getUser();
|
const user = await getUser();
|
||||||
@@ -234,7 +199,7 @@ function App() {
|
|||||||
serverAvailable().then(async (server) => {
|
serverAvailable().then(async (server) => {
|
||||||
if (server == true) {
|
if (server == true) {
|
||||||
createApi().then(() => {
|
createApi().then(() => {
|
||||||
pingServer.refetch();
|
pingServer();
|
||||||
if (serverReachable == true) {
|
if (serverReachable == true) {
|
||||||
userSaved().then((user_available) => {
|
userSaved().then((user_available) => {
|
||||||
if (user_available == true) {
|
if (user_available == true) {
|
||||||
@@ -341,7 +306,6 @@ function App() {
|
|||||||
<Dialog
|
<Dialog
|
||||||
open={!serverReachable}
|
open={!serverReachable}
|
||||||
onClose={handleRelaunch}
|
onClose={handleRelaunch}
|
||||||
disableBa
|
|
||||||
aria-labelledby="alert-dialog-text"
|
aria-labelledby="alert-dialog-text"
|
||||||
aria-describedby="alert-dialog-desc"
|
aria-describedby="alert-dialog-desc"
|
||||||
maxWidth="md"
|
maxWidth="md"
|
||||||
|
|||||||
@@ -158,77 +158,39 @@ export const ServerSetup = (props) => {
|
|||||||
sysInfo.Ip = serverIp;
|
sysInfo.Ip = serverIp;
|
||||||
setServer(sysInfo);
|
setServer(sysInfo);
|
||||||
};
|
};
|
||||||
|
const checkServer = async () => {
|
||||||
const checkServer = useQuery({
|
setServerCheckState(true);
|
||||||
queryKey: ["setup", "server"],
|
|
||||||
queryFn: async () => {
|
|
||||||
let serverUrl = serverIp.replace(/\/$/, "").trim();
|
|
||||||
const candidates =
|
|
||||||
await sdk.discovery.getRecommendedServerCandidates(
|
|
||||||
serverUrl,
|
|
||||||
);
|
|
||||||
const best = sdk.discovery.findBestServer(candidates);
|
|
||||||
if (best) {
|
|
||||||
const issues = candidates.flatMap((s) => s.issues);
|
|
||||||
if (
|
|
||||||
issues.some(
|
|
||||||
(i) =>
|
|
||||||
i instanceof VersionOutdatedIssue ||
|
|
||||||
i instanceof VersionUnsupportedIssue,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
enqueueSnackbar(
|
|
||||||
"Please Update your server to latest Jellyfin version to use this client",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const api = sdk.createApi(best.address);
|
const result = await axios.get(`${serverIp}/System/Ping`);
|
||||||
const { data } = await getSystemApi(
|
if (result.data == "Jellyfin Server") {
|
||||||
api,
|
|
||||||
).getPublicSystemInfo();
|
|
||||||
delete data.LocalAddress;
|
|
||||||
const serv = {
|
|
||||||
...data,
|
|
||||||
PublicAddress: best.address,
|
|
||||||
isDefault: false,
|
|
||||||
};
|
|
||||||
if (serv.StartupWizardCompleted) {
|
|
||||||
event.emit("create-jellyfin-api", serverIp);
|
event.emit("create-jellyfin-api", serverIp);
|
||||||
data.Ip = serverIp;
|
let sysInfo = await getSystemApi(
|
||||||
setServer(data);
|
|
||||||
const users = await getUserApi(
|
|
||||||
window.api,
|
window.api,
|
||||||
).getPublicUsers();
|
).getPublicSystemInfo();
|
||||||
|
sysInfo = sysInfo.data;
|
||||||
|
sysInfo.Ip = serverIp;
|
||||||
|
setServer(sysInfo);
|
||||||
|
const users = await getUserApi(window.api).getPublicUsers();
|
||||||
if (users.data.length >= 1) {
|
if (users.data.length >= 1) {
|
||||||
navigate("/login/users");
|
navigate("/login/users");
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
navigate("/login/manual");
|
navigate("/login/manual");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
enqueueSnackbar(
|
enqueueSnackbar(
|
||||||
"Server setup not complete. Please complete your server setup.",
|
"The provided ip address doesn't seem point to a Jellyfin server.",
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
enqueueSnackbar("Something went wrong", {
|
|
||||||
variant: "error",
|
|
||||||
});
|
|
||||||
console.error(error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
enqueueSnackbar(
|
|
||||||
"Server not found. Please check you entered address",
|
|
||||||
{ variant: "error" },
|
{ variant: "error" },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return "";
|
} catch (error) {
|
||||||
},
|
enqueueSnackbar("Unable to verfiy server address.", {
|
||||||
enabled: false,
|
variant: "error",
|
||||||
refetchOnWindowFocus: false,
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setServerCheckState(false);
|
||||||
|
return "";
|
||||||
|
};
|
||||||
|
|
||||||
const handleAddServer = () => {
|
const handleAddServer = () => {
|
||||||
// setLoading(true);
|
// setLoading(true);
|
||||||
@@ -291,14 +253,14 @@ export const ServerSetup = (props) => {
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
sx={{ width: "100%" }}
|
sx={{ width: "100%" }}
|
||||||
size="large"
|
size="large"
|
||||||
loading={checkServer.isFetching}
|
loading={checkingServer}
|
||||||
endIcon={
|
endIcon={
|
||||||
<SvgIcon>
|
<SvgIcon>
|
||||||
<path d={mdiChevronRight}></path>
|
<path d={mdiChevronRight}></path>
|
||||||
</SvgIcon>
|
</SvgIcon>
|
||||||
}
|
}
|
||||||
loadingPosition="end"
|
loadingPosition="end"
|
||||||
onClick={() => checkServer.refetch()}
|
onClick={() => checkServer()}
|
||||||
>
|
>
|
||||||
Add Server
|
Add Server
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
|
|||||||
Reference in new issue
Block a user