From a304e6964f4e22eeec5722c7da06357666b7966f Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Sun, 8 May 2022 19:32:34 -0700 Subject: [PATCH] configuration --- src-tauri/Cargo.lock | 315 +---------------------------------- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 23 ++- src/ui/App.tsx | 4 + src/ui/components/TopBar.tsx | 20 ++- src/utils/configuration.ts | 63 +++++++ 6 files changed, 105 insertions(+), 322 deletions(-) create mode 100644 src/utils/configuration.ts diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index d91c6a4..3bc5387 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -171,24 +171,6 @@ dependencies = [ "system-deps 6.0.2", ] -[[package]] -name = "attohttpc" -version = "0.19.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "262c3f7f5d61249d8c00e5546e2685cd15ebeeb1bc0f3cc5449350a1cb07319e" -dependencies = [ - "flate2", - "http", - "log", - "native-tls", - "openssl", - "serde", - "serde_json", - "serde_urlencoded", - "url", - "wildmatch", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -722,17 +704,6 @@ version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57" -[[package]] -name = "dbus" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de0a745c25b32caa56b82a3950f5fec7893a960f4c10ca3b02060b0c38d8c2ce" -dependencies = [ - "libc", - "libdbus-sys", - "winapi", -] - [[package]] name = "deflate" version = "0.7.20" @@ -1721,15 +1692,6 @@ version = "0.2.125" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" -[[package]] -name = "libdbus-sys" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c185b5b7ad900923ef3a8ff594083d4d9b5aea80bb4f32b8342363138c0d456b" -dependencies = [ - "pkg-config", -] - [[package]] name = "lock_api" version = "0.4.7" @@ -1770,19 +1732,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" -[[package]] -name = "mac-notification-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "297c13fc8ff9fa8b2d0e53850f80e0aa962628e865d447031ce58cdb062e5b29" -dependencies = [ - "cc", - "dirs-next", - "objc-foundation", - "objc_id", - "time", -] - [[package]] name = "mach" version = "0.3.2" @@ -1912,24 +1861,6 @@ dependencies = [ "uuid 0.8.2", ] -[[package]] -name = "native-tls" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" -dependencies = [ - "lazy_static", - "libc", - "log", - "openssl", - "openssl-probe", - "openssl-sys", - "schannel", - "security-framework", - "security-framework-sys", - "tempfile", -] - [[package]] name = "ndk" version = "0.4.0" @@ -2005,17 +1936,6 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "notify-rust" -version = "4.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a995a3d2834cefa389218e7a35156e8ce544bc95f836900da01ee0b26a07e9d4" -dependencies = [ - "dbus", - "mac-notification-sys", - "winrt-notification", -] - [[package]] name = "num-bigint" version = "0.4.3" @@ -2151,82 +2071,6 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9" -[[package]] -name = "open" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0524af9508f9b5c4eb41dce095860456727748f63b478d625f119a70e0d764a" -dependencies = [ - "pathdiff", - "winapi", -] - -[[package]] -name = "openssl" -version = "0.10.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb81a6430ac911acb25fe5ac8f1d2af1b4ea8a4fdfda0f1ee4292af2e2d8eb0e" -dependencies = [ - "bitflags", - "cfg-if 1.0.0", - "foreign-types", - "libc", - "once_cell", - "openssl-macros", - "openssl-sys", -] - -[[package]] -name = "openssl-macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "openssl-probe" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" - -[[package]] -name = "openssl-sys" -version = "0.9.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5fd19fb3e0a8191c1e34935718976a3e70c112ab9a24af6d7cadccd9d90bc0" -dependencies = [ - "autocfg", - "cc", - "libc", - "pkg-config", - "vcpkg", -] - -[[package]] -name = "os_info" -version = "3.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04304d855bb5385d4b595edf0147b8e281871766b75dd4c87b2bdf3c9e5c2d19" -dependencies = [ - "log", - "serde", - "winapi", -] - -[[package]] -name = "os_pipe" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c92f2b54f081d635c77e7120862d48db8e91f7f21cef23ab1b4fe9971c59f55" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "pango" version = "0.15.10" @@ -2306,12 +2150,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "pathdiff" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd" - [[package]] name = "pem" version = "1.0.2" @@ -2881,16 +2719,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "schannel" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f05ba609c234e60bee0d547fe94a4c7e9da733d1c962cf6e59efa4cd9c8bc75" -dependencies = [ - "lazy_static", - "winapi", -] - [[package]] name = "scheduled-thread-pool" version = "0.2.5" @@ -2922,29 +2750,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "security-framework" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" -dependencies = [ - "bitflags", - "core-foundation", - "core-foundation-sys", - "libc", - "security-framework-sys", -] - -[[package]] -name = "security-framework-sys" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" -dependencies = [ - "core-foundation-sys", - "libc", -] - [[package]] name = "selectors" version = "0.22.0" @@ -3034,18 +2839,6 @@ dependencies = [ "syn", ] -[[package]] -name = "serde_urlencoded" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" -dependencies = [ - "form_urlencoded", - "itoa 1.0.1", - "ryu", - "serde", -] - [[package]] name = "serde_with" version = "1.13.0" @@ -3132,16 +2925,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "shared_child" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0d94659ad3c2137fef23ae75b03d5241d633f8acded53d672decfa0e6e0caef" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "siphasher" version = "0.3.10" @@ -3264,15 +3047,6 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aaf86bbcfd1fa9670b7a129f64fc0c9fcbbfe4f1bc4210e9e98fe71ffc12cde2" -[[package]] -name = "strum" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7ac893c7d471c8a21f31cfe213ec4f6d9afeed25537c772e08ef3f005f8729e" -dependencies = [ - "strum_macros 0.22.0", -] - [[package]] name = "strum_macros" version = "0.21.1" @@ -3285,18 +3059,6 @@ dependencies = [ "syn", ] -[[package]] -name = "strum_macros" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "339f799d8b549e3744c7ac7feb216383e4005d94bdb22561b3ab8f3b808ae9fb" -dependencies = [ - "heck 0.3.3", - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "syn" version = "1.0.92" @@ -3331,8 +3093,8 @@ dependencies = [ "heck 0.3.3", "itertools", "pkg-config", - "strum 0.21.0", - "strum_macros 0.21.1", + "strum", + "strum_macros", "thiserror", "toml", "version-compare 0.0.11", @@ -3441,7 +3203,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a34cef4a0ebee0230baaa319b1709c4336f4add550149d2b005a9a5dc5d33617" dependencies = [ "anyhow", - "attohttpc", "bincode", "cocoa", "dirs-next", @@ -3455,23 +3216,17 @@ dependencies = [ "heck 0.4.0", "http", "ignore", - "notify-rust", "objc", "once_cell", - "open", - "os_info", - "os_pipe", "percent-encoding", "rand 0.8.5", "raw-window-handle", - "regex", "rfd", "semver 1.0.9", "serde", "serde_json", "serde_repr", "serialize-to-javascript", - "shared_child", "state", "tar", "tauri-macros", @@ -3514,7 +3269,6 @@ dependencies = [ "png 0.17.5", "proc-macro2", "quote", - "regex", "serde", "serde_json", "sha2", @@ -3971,12 +3725,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" -[[package]] -name = "vcpkg" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" - [[package]] name = "version-compare" version = "0.0.11" @@ -4227,12 +3975,6 @@ dependencies = [ "cc", ] -[[package]] -name = "wildmatch" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c48bd20df7e4ced539c12f570f937c6b4884928a87fee70a479d72f031d4e0" - [[package]] name = "winapi" version = "0.3.9" @@ -4264,18 +4006,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9f39345ae0c8ab072c0ac7fe8a8b411636aa34f89be19ddd0d9226544f13944" -dependencies = [ - "windows_i686_gnu 0.24.0", - "windows_i686_msvc 0.24.0", - "windows_x86_64_gnu 0.24.0", - "windows_x86_64_msvc 0.24.0", -] - [[package]] name = "windows" version = "0.30.0" @@ -4353,12 +4083,6 @@ dependencies = [ "windows_reader", ] -[[package]] -name = "windows_i686_gnu" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0866510a3eca9aed73a077490bbbf03e5eaac4e1fd70849d89539e5830501fd" - [[package]] name = "windows_i686_gnu" version = "0.30.0" @@ -4377,12 +4101,6 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" -[[package]] -name = "windows_i686_msvc" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf0ffed56b7e9369a29078d2ab3aaeceea48eb58999d2cff3aa2494a275b95c6" - [[package]] name = "windows_i686_msvc" version = "0.30.0" @@ -4425,12 +4143,6 @@ version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e44e6df0da993cda589c5ac852272fbb2a0ead67a031a017dd3eac11528a2d72" -[[package]] -name = "windows_x86_64_gnu" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384a173630588044205a2993b6864a2f56e5a8c1e7668c07b93ec18cf4888dc4" - [[package]] name = "windows_x86_64_gnu" version = "0.30.0" @@ -4449,12 +4161,6 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" -[[package]] -name = "windows_x86_64_msvc" -version = "0.24.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9bd8f062d8ca5446358159d79a90be12c543b3a965c847c8f3eedf14b321d399" - [[package]] name = "windows_x86_64_msvc" version = "0.30.0" @@ -4482,17 +4188,6 @@ dependencies = [ "toml", ] -[[package]] -name = "winrt-notification" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "007a0353840b23e0c6dc73e5b962ff58ed7f6bc9ceff3ce7fe6fbad8d496edf4" -dependencies = [ - "strum 0.22.0", - "windows 0.24.0", - "xml-rs", -] - [[package]] name = "wry" version = "0.16.0" @@ -4574,12 +4269,6 @@ dependencies = [ "libc", ] -[[package]] -name = "xml-rs" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3" - [[package]] name = "yasna" version = "0.5.0" diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 027f54e..0689d45 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -17,7 +17,7 @@ tauri-build = { version = "1.0.0-rc.8", features = [] } [dependencies] serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } -tauri = { version = "1.0.0-rc.9", features = ["api-all"] } +tauri = { version = "1.0.0-rc.9", features = ["dialog-all", "fs-create-dir", "fs-read-dir", "fs-read-file", "fs-write-file", "path-all"] } hudsucker = "0.17.2" [features] diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index dbb56ab..8bd67c5 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -12,7 +12,22 @@ }, "tauri": { "allowlist": { - "all": true + "fs": { + "scope": [ + "$DATA", + "$DATA/cultivation/*" + ], + "readDir": true, + "readFile": true, + "writeFile": true, + "createDir": true + }, + "path": { + "all": true + }, + "dialog": { + "all": true + } }, "bundle": { "active": true, @@ -29,7 +44,7 @@ "icons/icon.icns", "icons/icon.ico" ], - "identifier": "com.tauri.dev", + "identifier": "com.cultivation.grasscutters", "longDescription": "", "macOS": { "entitlements": null, @@ -56,10 +71,10 @@ "windows": [ { "fullscreen": false, - "height": 600, + "height": 730, "resizable": true, "title": "Cultivation", - "width": 800, + "width": 1280, "decorations": false } ] diff --git a/src/ui/App.tsx b/src/ui/App.tsx index 903d662..558fd5c 100644 --- a/src/ui/App.tsx +++ b/src/ui/App.tsx @@ -3,12 +3,16 @@ import logo from './logo.svg' import './App.css' import './custom.css' +// Config +import { getConfigOption } from '../utils/configuration' + // Major Components import Topbar from './components/TopBar' import BigButton from './components/common/BigButton' function playGame() { alert('cum') + getConfigOption('test') } function App() { diff --git a/src/ui/components/TopBar.tsx b/src/ui/components/TopBar.tsx index 3774ac9..1009b91 100644 --- a/src/ui/components/TopBar.tsx +++ b/src/ui/components/TopBar.tsx @@ -4,10 +4,22 @@ import './TopBar.css' import closeIcon from '../../resources/icons/close.svg' import minIcon from '../../resources/icons/min.svg' import cogBtn from '../../resources/icons/cog.svg' +import { app } from '@tauri-apps/api' -export default class TopBar extends React.Component { - constructor(props: unknown[]) { +interface IProps { + [key: string]: never +} + +interface IState { + version: string +} +export default class TopBar extends React.Component { + constructor(props: Record) { super(props) + + app.getVersion().then(version => { + this.setState({ version }) + }) } handleClose() { @@ -22,8 +34,8 @@ export default class TopBar extends React.Component { return (
- Cultivation - v0.1.0 + Cultivation + {this.state?.version}
diff --git a/src/utils/configuration.ts b/src/utils/configuration.ts new file mode 100644 index 0000000..ec20dcc --- /dev/null +++ b/src/utils/configuration.ts @@ -0,0 +1,63 @@ +import { fs } from '@tauri-apps/api' +import { dataDir } from '@tauri-apps/api/path' + +let configFilePath: string + +export async function setConfigOption(key: string, value: any): Promise { + return +} + +export async function getConfigOption(key: string): Promise { + const config = await getConfig() +} + +export async function getConfig() { + const raw = await readConfigFile() + let parsed + + try { + parsed = JSON.parse(raw) + } catch(e) { + // We could not open the file + console.log(e) + } + + return parsed +} + +export async function saveConfig(obj: { [key: string]: any }) { + return +} + +async function readConfigFile() { + const local = await dataDir() + + if (!configFilePath) configFilePath = local + 'cultivation\\configuration.json' + + // Ensure Cultivation dir exists + const dirs = await fs.readDir(local) + + if (!dirs.find((fileOrDir) => fileOrDir?.name === 'cultivation')) { + // Create dir + await fs.createDir(local + 'cultivation') + } + + const dataFiles = await fs.readDir(local + 'cultivation') + + // Ensure config exists + if (!dataFiles.find((fileOrDir) => fileOrDir?.name === 'configuration.json')) { + // Create config file + const file: fs.FsTextFileOption = { + path: local + 'cultivation\\configuration.json', + contents: '{}' + } + } + + // Finally read the file + + return await fs.readTextFile(local + 'cultivation\\configuration.json') +} + +async function writeConfigFile() { + return +} \ No newline at end of file