From 3969c26a58a3a1e64b89bf762569205a52e00164 Mon Sep 17 00:00:00 2001 From: Thoronium <107363768+NotThorny@users.noreply.github.com> Date: Mon, 24 Apr 2023 20:21:52 -0600 Subject: [PATCH 01/10] Improve mod browser load time Add pages to mod browser Still WIP --- src-tauri/src/web.rs | 28 ++++++++------- src/ui/Mods.tsx | 30 +++++++++++++++- src/ui/components/mods/ModList.tsx | 3 +- src/ui/components/mods/ModPages.css | 30 ++++++++++++++++ src/ui/components/mods/ModPages.tsx | 54 +++++++++++++++++++++++++++++ src/utils/gamebanana.ts | 11 +----- 6 files changed, 132 insertions(+), 24 deletions(-) create mode 100644 src/ui/components/mods/ModPages.css create mode 100644 src/ui/components/mods/ModPages.tsx diff --git a/src-tauri/src/web.rs b/src-tauri/src/web.rs index d8a70ad..e1337b6 100644 --- a/src-tauri/src/web.rs +++ b/src-tauri/src/web.rs @@ -1,21 +1,25 @@ +use http::header; +use once_cell::sync::Lazy; use reqwest::header::{CONTENT_TYPE, USER_AGENT}; +static CLIENT: Lazy = Lazy::new(|| { + let mut headers = header::HeaderMap::new(); + headers.insert(USER_AGENT, header::HeaderValue::from_static("cultivation")); + headers.insert(CONTENT_TYPE, header::HeaderValue::from_static("application/json")); + + let client = reqwest::Client::builder() + .default_headers(headers); + client.build().unwrap() +}); pub(crate) async fn query(site: &str) -> String { - let client = reqwest::Client::new(); - - let response = client + CLIENT .get(site) - .header(USER_AGENT, "cultivation") - .header(CONTENT_TYPE, "application/json") .send() .await - .ok(); - - if response.is_some() { - response.unwrap().text().await.unwrap() - } else { - false.to_string() - } + .expect("Failed to get web response") + .text() + .await + .unwrap() } #[tauri::command] diff --git a/src/ui/Mods.tsx b/src/ui/Mods.tsx index 3129ebc..39584e4 100644 --- a/src/ui/Mods.tsx +++ b/src/ui/Mods.tsx @@ -14,6 +14,7 @@ import Back from '../resources/icons/back.svg' import Menu from './components/menu/Menu' import BigButton from './components/common/BigButton' import Tr from '../utils/language' +import { ModPages } from './components/mods/ModPages' interface IProps { downloadHandler: DownloadHandler @@ -23,8 +24,20 @@ interface IState { isDownloading: boolean category: string downloadList: { name: string; url: string; mod: ModData }[] | null + page: number } +const pages = [ + { + name: -1, + title: '<', + }, + { + name: 1, + title: '>', + } +] + const headers = [ { name: 'ripe', @@ -53,10 +66,12 @@ export class Mods extends React.Component { isDownloading: false, category: '', downloadList: null, + page: 1, } this.setCategory = this.setCategory.bind(this) this.addDownload = this.addDownload.bind(this) + this.setPage = this.setPage.bind(this) } async addDownload(mod: ModData) { @@ -111,6 +126,17 @@ export class Mods extends React.Component { ) } + async setPage(value: number) { + const current = this.state.page; + if (current + value == 0) return; + this.setState( + { + page: current + value, + }, + this.forceUpdate + ) + } + render() { return (
@@ -162,7 +188,9 @@ export class Mods extends React.Component { - + + +
) } diff --git a/src/ui/components/mods/ModList.tsx b/src/ui/components/mods/ModList.tsx index 76ecda1..b7a18e5 100644 --- a/src/ui/components/mods/ModList.tsx +++ b/src/ui/components/mods/ModList.tsx @@ -8,6 +8,7 @@ import { ModTile } from './ModTile' interface IProps { mode: string + page: number addDownload: (mod: ModData) => void } @@ -62,7 +63,7 @@ export class ModList extends React.Component { return } - const mods = await getMods(this.props.mode) + const mods = await getMods(this.props.mode, this.props.page) const horny = await getConfigOption('horny_mode') this.setState({ diff --git a/src/ui/components/mods/ModPages.css b/src/ui/components/mods/ModPages.css new file mode 100644 index 0000000..d0bae5f --- /dev/null +++ b/src/ui/components/mods/ModPages.css @@ -0,0 +1,30 @@ +.ModPages { + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-around; + width: 100%; + + padding: 10px; + + font-size: 20px; + font-weight: bold; + color: #fff; + background: rgba(77, 77, 77, 0.6); +} + +.ModPagesTitle { + display: flex; + justify-content: center; + + width: 100%; + max-width: 20%; +} + +.ModPagesTitle:hover { + cursor: pointer; +} + +.ModPagesTitle.selected { + border-bottom: 0px solid #fff; +} diff --git a/src/ui/components/mods/ModPages.tsx b/src/ui/components/mods/ModPages.tsx new file mode 100644 index 0000000..8f2bc32 --- /dev/null +++ b/src/ui/components/mods/ModPages.tsx @@ -0,0 +1,54 @@ +import React from 'react' + +import './ModPages.css' + +interface IProps { + headers: { + title: string + name: number + }[] + onClick: (value: number) => void + defaultHeader: number +} + +interface IState { + selected: number +} + +export class ModPages extends React.Component { + constructor(props: IProps) { + super(props) + + this.state = { + selected: this.props.defaultHeader, + } + } + + setSelected(value: number) { + const current = this.state.selected; + if (current + value == 0) return; + this.setState({ + selected: current + value, + }) + + this.props.onClick(value) + } + + render() { + return ( +
+ {this.props.headers.map((header, index) => { + return ( +
this.setSelected(header.name)} + > + {header.title} +
+ ) + })} +
+ ) + } +} diff --git a/src/utils/gamebanana.ts b/src/utils/gamebanana.ts index 61c332f..6d602b0 100644 --- a/src/utils/gamebanana.ts +++ b/src/utils/gamebanana.ts @@ -117,12 +117,10 @@ interface ModDownload { containsExe: boolean } -export async function getMods(mode: string) { +export async function getMods(mode: string, page: number) { let modList: GamebananaResponse[] = [] let hadMods = true - let page = 1 - while (hadMods) { const resp = JSON.parse( await invoke('list_submissions', { mode, @@ -133,13 +131,6 @@ export async function getMods(mode: string) { if (resp.length === 0) hadMods = false modList = [...modList, ...resp] - page++ - - console.log(page) - console.log(resp) - } - - console.log(modList) return formatGamebananaData(modList) } From b78479a2938a949140da7505a91eacf3498e14c6 Mon Sep 17 00:00:00 2001 From: Thoronium <107363768+NotThorny@users.noreply.github.com> Date: Mon, 24 Apr 2023 20:48:18 -0600 Subject: [PATCH 02/10] Linting --- src-tauri/src/release.rs | 3 ++- src/ui/Mods.tsx | 13 +++++++++---- src/ui/components/mods/ModPages.tsx | 4 ++-- src/utils/gamebanana.ts | 17 +++++++---------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src-tauri/src/release.rs b/src-tauri/src/release.rs index dd36607..9056f77 100644 --- a/src-tauri/src/release.rs +++ b/src-tauri/src/release.rs @@ -6,7 +6,8 @@ pub struct Release { #[tauri::command] pub async fn get_latest_release() -> Release { - let url = "https://api.github.com/repos/Grasscutters/Cultivation/releases/latest"; + // NotThorny edition requests to repo so as to avoid update spam from official repo -alpha version diff. + let url = "https://api.github.com/repos/NotThorny/Cultivation/releases/latest"; let client = reqwest::Client::new(); let response = client .get(url) diff --git a/src/ui/Mods.tsx b/src/ui/Mods.tsx index 39584e4..623d1f7 100644 --- a/src/ui/Mods.tsx +++ b/src/ui/Mods.tsx @@ -35,7 +35,7 @@ const pages = [ { name: 1, title: '>', - } + }, ] const headers = [ @@ -127,8 +127,8 @@ export class Mods extends React.Component { } async setPage(value: number) { - const current = this.state.page; - if (current + value == 0) return; + const current = this.state.page + if (current + value == 0) return this.setState( { page: current + value, @@ -190,7 +190,12 @@ export class Mods extends React.Component { - + ) } diff --git a/src/ui/components/mods/ModPages.tsx b/src/ui/components/mods/ModPages.tsx index 8f2bc32..79720d5 100644 --- a/src/ui/components/mods/ModPages.tsx +++ b/src/ui/components/mods/ModPages.tsx @@ -25,8 +25,8 @@ export class ModPages extends React.Component { } setSelected(value: number) { - const current = this.state.selected; - if (current + value == 0) return; + const current = this.state.selected + if (current + value == 0) return this.setState({ selected: current + value, }) diff --git a/src/utils/gamebanana.ts b/src/utils/gamebanana.ts index 6d602b0..830e31f 100644 --- a/src/utils/gamebanana.ts +++ b/src/utils/gamebanana.ts @@ -119,18 +119,15 @@ interface ModDownload { export async function getMods(mode: string, page: number) { let modList: GamebananaResponse[] = [] - let hadMods = true - const resp = JSON.parse( - await invoke('list_submissions', { - mode, - page: '' + page, - }) - ) + const resp = JSON.parse( + await invoke('list_submissions', { + mode, + page: '' + page, + }) + ) - if (resp.length === 0) hadMods = false - - modList = [...modList, ...resp] + modList = [...modList, ...resp] return formatGamebananaData(modList) } From df48f888ff293444d5a1299f97a94ab51e4f62c4 Mon Sep 17 00:00:00 2001 From: Thoronium <107363768+NotThorny@users.noreply.github.com> Date: Tue, 25 Apr 2023 14:19:17 -0600 Subject: [PATCH 03/10] Mod browser page number --- src-tauri/src/release.rs | 2 +- src/ui/Mods.css | 2 +- src/ui/Mods.tsx | 7 ++++++- src/ui/components/mods/ModPages.css | 21 ++++++++++++++++++++- src/ui/components/news/NewsSection.tsx | 2 +- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src-tauri/src/release.rs b/src-tauri/src/release.rs index 9056f77..647f454 100644 --- a/src-tauri/src/release.rs +++ b/src-tauri/src/release.rs @@ -17,7 +17,7 @@ pub async fn get_latest_release() -> Release { .unwrap(); let text = response.text().await.unwrap(); - println!("Response: {}", text); + //println!("Response: {}", text); // Parse "tag_name" from JSON let json: serde_json::Value = serde_json::from_str(&text).unwrap(); diff --git a/src/ui/Mods.css b/src/ui/Mods.css index 709ca26..520a3a8 100644 --- a/src/ui/Mods.css +++ b/src/ui/Mods.css @@ -1,6 +1,6 @@ .Mods { backdrop-filter: blur(10px); - height: 90%; + height: 80%; width: 100%; } diff --git a/src/ui/Mods.tsx b/src/ui/Mods.tsx index 623d1f7..612f277 100644 --- a/src/ui/Mods.tsx +++ b/src/ui/Mods.tsx @@ -188,7 +188,12 @@ export class Mods extends React.Component { - + {this.state.category != 'installed' && ( + <> +

{this.state.page}

+ + + )} { case 'latest_version': news = ( - Latest version: Grasscutter 1.4.6 - Cultivation 1.0.10 + Latest version: Grasscutter 1.4.8 - Cultivation 1.0.26 ) break From e38467f054853ae6df2c555440f1e32bac1ac94c Mon Sep 17 00:00:00 2001 From: Thoronium <107363768+NotThorny@users.noreply.github.com> Date: Tue, 25 Apr 2023 19:44:23 -0600 Subject: [PATCH 04/10] Mod browser searching --- src/ui/Mods.tsx | 29 +++++++++++++++++-- src/ui/components/mods/ModList.tsx | 45 +++++++++++++++++------------ src/ui/components/mods/ModPages.css | 17 +++++++++++ src/utils/gamebanana.ts | 22 ++++++++++++++ 4 files changed, 93 insertions(+), 20 deletions(-) diff --git a/src/ui/Mods.tsx b/src/ui/Mods.tsx index 612f277..dd1e8f7 100644 --- a/src/ui/Mods.tsx +++ b/src/ui/Mods.tsx @@ -15,6 +15,7 @@ import Menu from './components/menu/Menu' import BigButton from './components/common/BigButton' import Tr from '../utils/language' import { ModPages } from './components/mods/ModPages' +import TextInput from './components/common/TextInput' interface IProps { downloadHandler: DownloadHandler @@ -25,6 +26,7 @@ interface IState { category: string downloadList: { name: string; url: string; mod: ModData }[] | null page: number + search: string } const pages = [ @@ -59,14 +61,17 @@ const headers = [ * @TODO Categorizaiton/sorting (by likes, views, etc) */ export class Mods extends React.Component { + timeout: number constructor(props: IProps) { super(props) + this.timeout = 0 this.state = { isDownloading: false, category: '', downloadList: null, page: 1, + search: '', } this.setCategory = this.setCategory.bind(this) @@ -137,6 +142,17 @@ export class Mods extends React.Component { ) } + async setSearch(text: string) { + if(this.timeout) clearTimeout(this.timeout); + this.timeout = window.setTimeout(() => { + this.setState({ + search: text, + }, + this.forceUpdate + ) + }, 300) + } + render() { return (
@@ -190,16 +206,25 @@ export class Mods extends React.Component { {this.state.category != 'installed' && ( <> -

{this.state.page}

+
+ {this.setSearch(text)}} + initalValue={''} + /> +
)}
) diff --git a/src/ui/components/mods/ModList.tsx b/src/ui/components/mods/ModList.tsx index b7a18e5..5aaea37 100644 --- a/src/ui/components/mods/ModList.tsx +++ b/src/ui/components/mods/ModList.tsx @@ -1,6 +1,6 @@ import React from 'react' import { getConfigOption } from '../../../utils/configuration' -import { getInstalledMods, getMods, ModData, PartialModData } from '../../../utils/gamebanana' +import { getAllMods, getInstalledMods, getMods, ModData, PartialModData } from '../../../utils/gamebanana' import { LoadingCircle } from './LoadingCircle' import './ModList.css' @@ -9,6 +9,7 @@ import { ModTile } from './ModTile' interface IProps { mode: string page: number + search: string addDownload: (mod: ModData) => void } @@ -16,11 +17,11 @@ interface IState { horny: boolean modList: ModData[] | null installedList: - | { - path: string - info: ModData | PartialModData - }[] - | null + | { + path: string + info: ModData | PartialModData + }[] + | null } export class ModList extends React.Component { @@ -63,7 +64,15 @@ export class ModList extends React.Component { return } - const mods = await getMods(this.props.mode, this.props.page) + let mods: ModData[] + + if (!(this.props.search == '')) { + // idk the api so just filter all mods to search + mods = (await getAllMods(this.props.mode)).filter(mod => mod.name.toLowerCase().includes(this.props.search.toLowerCase())) + } else { + mods = await getMods(this.props.mode, this.props.page) + } + const horny = await getConfigOption('horny_mode') this.setState({ @@ -80,21 +89,21 @@ export class ModList extends React.Component { return (
{(this.state.modList && this.props.mode !== 'installed') || - (this.state.installedList && this.props.mode === 'installed') ? ( + (this.state.installedList && this.props.mode === 'installed') ? (
{this.props.mode === 'installed' ? this.state.installedList?.map((mod) => ( - - )) + + )) : this.state.modList?.map((mod: ModData) => ( - - ))} + + ))}
) : ( diff --git a/src/ui/components/mods/ModPages.css b/src/ui/components/mods/ModPages.css index 46dfed8..a40a734 100644 --- a/src/ui/components/mods/ModPages.css +++ b/src/ui/components/mods/ModPages.css @@ -47,3 +47,20 @@ font-weight: bold; color: #fff; } + +.ModPagesPage input { + text-align: center; + padding: 3px; + border-radius: 3px; + height: 18px; + font-size: 20px; + font-weight: bold; + color: #fff; + background: rgba(77, 77, 77, 0.6); +} + +.ModPagesPage .TextInputWrapper { + background: rgba(77, 77, 77, 0.6); + z-index: -1; + display: inline-block; +} diff --git a/src/utils/gamebanana.ts b/src/utils/gamebanana.ts index 830e31f..642dc07 100644 --- a/src/utils/gamebanana.ts +++ b/src/utils/gamebanana.ts @@ -132,6 +132,28 @@ export async function getMods(mode: string, page: number) { return formatGamebananaData(modList) } +export async function getAllMods(mode: string) { + let modList: GamebananaResponse[] = [] + let hadMods = true + let page = 1 + + while (hadMods) { + const resp = JSON.parse( + await invoke('list_submissions', { + mode, + page: '' + page, + }) + ) + + if (resp.length === 0) hadMods = false + + modList = [...modList, ...resp] + page++ + } + + return formatGamebananaData(modList) +} + export async function formatGamebananaData(obj: GamebananaResponse[]) { if (!obj) return [] From 6e711073ad74574eee8736312760c22bc1ff0a53 Mon Sep 17 00:00:00 2001 From: Thoronium <107363768+NotThorny@users.noreply.github.com> Date: Wed, 26 Apr 2023 14:51:19 -0600 Subject: [PATCH 05/10] Linting & prettier Bump version --- src-tauri/src/main.rs | 4 +-- src-tauri/src/patch.rs | 4 +-- src-tauri/src/release.rs | 4 +-- src-tauri/src/system_helpers.rs | 2 +- src-tauri/tauri.conf.json | 2 +- src/ui/Mods.tsx | 19 ++++++++------ src/ui/components/mods/ModList.tsx | 36 ++++++++++++++------------ src/ui/components/news/NewsSection.tsx | 2 +- 8 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index d088b93..d1455f8 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -107,9 +107,9 @@ async fn parse_args(inp: &Vec) -> Result { if game_path.is_some() { if args.value_of("non-elevated-game")? { - system_helpers::run_un_elevated(game_path.unwrap().to_string(), Some(game_args)) + system_helpers::run_un_elevated(game_path.unwrap(), Some(game_args)) } else { - system_helpers::run_program(game_path.unwrap().to_string(), Some(game_args)) + system_helpers::run_program(game_path.unwrap(), Some(game_args)) } } } diff --git a/src-tauri/src/patch.rs b/src-tauri/src/patch.rs index 789eaef..66c7bcc 100644 --- a/src-tauri/src/patch.rs +++ b/src-tauri/src/patch.rs @@ -53,9 +53,7 @@ pub async fn unpatch_game() -> bool { pub async fn get_game_rsa_path() -> Option { let config = config::get_config(); - if config.game_install_path.is_none() { - return None; - } + config.game_install_path.as_ref()?; let mut game_folder = PathBuf::from(config.game_install_path.unwrap()); game_folder.pop(); diff --git a/src-tauri/src/release.rs b/src-tauri/src/release.rs index 647f454..4341ba1 100644 --- a/src-tauri/src/release.rs +++ b/src-tauri/src/release.rs @@ -6,8 +6,7 @@ pub struct Release { #[tauri::command] pub async fn get_latest_release() -> Release { - // NotThorny edition requests to repo so as to avoid update spam from official repo -alpha version diff. - let url = "https://api.github.com/repos/NotThorny/Cultivation/releases/latest"; + let url = "https://api.github.com/repos/Grasscutters/Cultivation/releases/latest"; let client = reqwest::Client::new(); let response = client .get(url) @@ -17,6 +16,7 @@ pub async fn get_latest_release() -> Release { .unwrap(); let text = response.text().await.unwrap(); + // This includes ip when github rate limits you, so avoid it for now to avoid leaks through screenshots //println!("Response: {}", text); // Parse "tag_name" from JSON diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index ff8bddf..f25e193 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -230,7 +230,7 @@ pub fn service_status(service: String) -> bool { } }; let status_result = my_service.query_status(); - if status_result.is_ok() { + if let Ok(..) = status_result { let status = status_result.unwrap(); println!("{} service status: {:?}", service, status.current_state); if status.current_state == Stopped { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 6bc39a5..9dc97f7 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -7,7 +7,7 @@ }, "package": { "productName": "Cultivation", - "version": "1.0.26" + "version": "1.0.27" }, "tauri": { "allowlist": { diff --git a/src/ui/Mods.tsx b/src/ui/Mods.tsx index dd1e8f7..4d13ae8 100644 --- a/src/ui/Mods.tsx +++ b/src/ui/Mods.tsx @@ -143,12 +143,13 @@ export class Mods extends React.Component { } async setSearch(text: string) { - if(this.timeout) clearTimeout(this.timeout); + if (this.timeout) clearTimeout(this.timeout) this.timeout = window.setTimeout(() => { - this.setState({ - search: text, - }, - this.forceUpdate + this.setState( + { + search: text, + }, + this.forceUpdate ) }, 300) } @@ -207,13 +208,15 @@ export class Mods extends React.Component { {this.state.category != 'installed' && ( <>
- {this.setSearch(text)}} + onChange={(text: string) => { + this.setSearch(text) + }} initalValue={''} - /> + />
diff --git a/src/ui/components/mods/ModList.tsx b/src/ui/components/mods/ModList.tsx index 5aaea37..91552f7 100644 --- a/src/ui/components/mods/ModList.tsx +++ b/src/ui/components/mods/ModList.tsx @@ -17,11 +17,11 @@ interface IState { horny: boolean modList: ModData[] | null installedList: - | { - path: string - info: ModData | PartialModData - }[] - | null + | { + path: string + info: ModData | PartialModData + }[] + | null } export class ModList extends React.Component { @@ -68,7 +68,9 @@ export class ModList extends React.Component { if (!(this.props.search == '')) { // idk the api so just filter all mods to search - mods = (await getAllMods(this.props.mode)).filter(mod => mod.name.toLowerCase().includes(this.props.search.toLowerCase())) + mods = (await getAllMods(this.props.mode)).filter((mod) => + mod.name.toLowerCase().includes(this.props.search.toLowerCase()) + ) } else { mods = await getMods(this.props.mode, this.props.page) } @@ -89,21 +91,21 @@ export class ModList extends React.Component { return (
{(this.state.modList && this.props.mode !== 'installed') || - (this.state.installedList && this.props.mode === 'installed') ? ( + (this.state.installedList && this.props.mode === 'installed') ? (
{this.props.mode === 'installed' ? this.state.installedList?.map((mod) => ( - - )) + + )) : this.state.modList?.map((mod: ModData) => ( - - ))} + + ))}
) : ( diff --git a/src/ui/components/news/NewsSection.tsx b/src/ui/components/news/NewsSection.tsx index fa89803..237266b 100644 --- a/src/ui/components/news/NewsSection.tsx +++ b/src/ui/components/news/NewsSection.tsx @@ -124,7 +124,7 @@ export default class NewsSection extends React.Component { case 'latest_version': news = ( - Latest version: Grasscutter 1.4.8 - Cultivation 1.0.26 + Latest version: Grasscutter 1.4.8 - Cultivation 1.0.27 ) break From 26d1df2927818452a623820b2d6493c85ae379f3 Mon Sep 17 00:00:00 2001 From: Thoronium <107363768+NotThorny@users.noreply.github.com> Date: Wed, 26 Apr 2023 14:56:19 -0600 Subject: [PATCH 06/10] Slightly extend typing timer --- src/ui/Mods.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/Mods.tsx b/src/ui/Mods.tsx index 4d13ae8..ab43cc7 100644 --- a/src/ui/Mods.tsx +++ b/src/ui/Mods.tsx @@ -151,7 +151,7 @@ export class Mods extends React.Component { }, this.forceUpdate ) - }, 300) + }, 500) } render() { From d13c8e8861a845f5f05ce445ac3fd6a451906dcb Mon Sep 17 00:00:00 2001 From: Thoronium <107363768+NotThorny@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:01:49 -0600 Subject: [PATCH 07/10] rustfmt --- src-tauri/src/web.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/web.rs b/src-tauri/src/web.rs index e1337b6..5615561 100644 --- a/src-tauri/src/web.rs +++ b/src-tauri/src/web.rs @@ -4,10 +4,12 @@ use reqwest::header::{CONTENT_TYPE, USER_AGENT}; static CLIENT: Lazy = Lazy::new(|| { let mut headers = header::HeaderMap::new(); headers.insert(USER_AGENT, header::HeaderValue::from_static("cultivation")); - headers.insert(CONTENT_TYPE, header::HeaderValue::from_static("application/json")); + headers.insert( + CONTENT_TYPE, + header::HeaderValue::from_static("application/json"), + ); - let client = reqwest::Client::builder() - .default_headers(headers); + let client = reqwest::Client::builder().default_headers(headers); client.build().unwrap() }); From 5374e2b0b959781d6c497ca55df9b42997d2bced Mon Sep 17 00:00:00 2001 From: Thoronium <107363768+NotThorny@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:03:06 -0600 Subject: [PATCH 08/10] whitespace --- src-tauri/src/web.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/web.rs b/src-tauri/src/web.rs index 5615561..14fbce8 100644 --- a/src-tauri/src/web.rs +++ b/src-tauri/src/web.rs @@ -6,8 +6,8 @@ static CLIENT: Lazy = Lazy::new(|| { headers.insert(USER_AGENT, header::HeaderValue::from_static("cultivation")); headers.insert( CONTENT_TYPE, - header::HeaderValue::from_static("application/json"), - ); + header::HeaderValue::from_static("application/json"), + ); let client = reqwest::Client::builder().default_headers(headers); client.build().unwrap() From 17fed553da1558ba46b0d1348c8046ae64bdc254 Mon Sep 17 00:00:00 2001 From: Thoronium <107363768+NotThorny@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:17:27 -0600 Subject: [PATCH 09/10] Fix unix build --- src-tauri/src/main.rs | 2 ++ src-tauri/src/system_helpers.rs | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index d1455f8..2d52b62 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -308,6 +308,7 @@ fn is_grasscutter_running() -> bool { !proc.is_empty() } +#[cfg(windows)] #[tauri::command] fn restart_grasscutter(window: tauri::Window) -> bool { let pid: usize = *GC_PID.lock().unwrap(); @@ -338,6 +339,7 @@ fn restart_grasscutter(window: tauri::Window) -> bool { } } +#[cfg(windows)] #[tauri::command] fn enable_grasscutter_watcher(window: tauri::Window, process: String) { let grasscutter_name = process.clone(); diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index f25e193..c3537f1 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -1,12 +1,12 @@ use duct::cmd; use ini::Ini; -use std::ffi::OsStr; use std::path::PathBuf; -use windows_service::service::{ServiceAccess, ServiceState::Stopped}; -use windows_service::service_manager::{ServiceManager, ServiceManagerAccess}; #[cfg(windows)] +use std::ffi::OsStr; use registry::{Data, Hive, Security}; +use windows_service::service::{ServiceAccess, ServiceState::Stopped}; +use windows_service::service_manager::{ServiceManager, ServiceManagerAccess}; #[tauri::command] pub fn run_program(path: String, args: Option) { @@ -262,6 +262,10 @@ pub fn start_service(service: String) -> bool { true } +#[cfg(unix)] +#[tauri::command] +pub fn start_service(service: String) -> bool {} + #[cfg(windows)] #[tauri::command] pub fn stop_service(service: String) -> bool { @@ -281,6 +285,10 @@ pub fn stop_service(service: String) -> bool { true } +#[cfg(unix)] +#[tauri::command] +pub fn stop_service(service: String) -> bool {} + #[cfg(unix)] #[tauri::command] pub fn wipe_registry(_exec_name: String) {} From 96c4e4b886530aee2ccdbbe2fc96895a33384bc6 Mon Sep 17 00:00:00 2001 From: Thoronium <107363768+NotThorny@users.noreply.github.com> Date: Wed, 26 Apr 2023 15:45:41 -0600 Subject: [PATCH 10/10] Fix unix build (real) --- src-tauri/src/main.rs | 10 ++++++++++ src-tauri/src/system_helpers.rs | 16 ++++++++++------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 2d52b62..ccfcd5d 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -339,6 +339,10 @@ fn restart_grasscutter(window: tauri::Window) -> bool { } } +#[cfg(unix)] +#[tauri::command] +fn restart_grasscutter(window: tauri::Window) {} + #[cfg(windows)] #[tauri::command] fn enable_grasscutter_watcher(window: tauri::Window, process: String) { @@ -400,6 +404,12 @@ fn enable_grasscutter_watcher(window: tauri::Window, process: String) { }); } +#[cfg(unix)] +#[tauri::command] +fn enable_grasscutter_watcher(window: tauri::Window, process: String) { + let gc_pid = Pid::from(696969); +} + #[tauri::command] async fn connect(port: u16, certificate_path: String) { // Log message to console. diff --git a/src-tauri/src/system_helpers.rs b/src-tauri/src/system_helpers.rs index c3537f1..c1a65a0 100644 --- a/src-tauri/src/system_helpers.rs +++ b/src-tauri/src/system_helpers.rs @@ -1,12 +1,14 @@ use duct::cmd; use ini::Ini; use std::path::PathBuf; +use std::ffi::OsStr; #[cfg(windows)] -use std::ffi::OsStr; -use registry::{Data, Hive, Security}; -use windows_service::service::{ServiceAccess, ServiceState::Stopped}; -use windows_service::service_manager::{ServiceManager, ServiceManagerAccess}; +use { + registry::{Data, Hive, Security}, + windows_service::service::{ServiceAccess, ServiceState::Stopped}, + windows_service::service_manager::{ServiceManager, ServiceManagerAccess}, +}; #[tauri::command] pub fn run_program(path: String, args: Option) { @@ -264,7 +266,9 @@ pub fn start_service(service: String) -> bool { #[cfg(unix)] #[tauri::command] -pub fn start_service(service: String) -> bool {} +pub fn start_service(service: String) { + let started = OsStr::new("Started service!"); +} #[cfg(windows)] #[tauri::command] @@ -287,7 +291,7 @@ pub fn stop_service(service: String) -> bool { #[cfg(unix)] #[tauri::command] -pub fn stop_service(service: String) -> bool {} +pub fn stop_service(service: String) {} #[cfg(unix)] #[tauri::command]