diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 00000000..6f8c0413 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[alias] +prisma = "run -p prisma-cli --bin prisma --" diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..4001a875 --- /dev/null +++ b/.npmrc @@ -0,0 +1,4 @@ +; make all engine requirements (e.g. node version) strictly kept +engine-strict=true +; tempfix for pnpm#5909: https://github.com/pnpm/pnpm/issues/5909#issuecomment-1397758156 +prefer-symlinked-executables=false diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..3c032078 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +18 diff --git a/.rustfmt.toml b/.rustfmt.toml new file mode 100644 index 00000000..09008c01 --- /dev/null +++ b/.rustfmt.toml @@ -0,0 +1,12 @@ +max_width = 100 +hard_tabs = true +newline_style = "Unix" +use_small_heuristics = "Default" +reorder_imports = true +reorder_modules = true +remove_nested_parens = true +edition = "2021" +merge_derives = true +use_try_shorthand = false +use_field_init_shorthand = false +force_explicit_abi = true diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000..7c6d1e45 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,50 @@ +[workspace] +resolver = "2" +members = [ + "src-tauri", + "crates/*", +] + +[workspace.package] +license = "GPL-3.0-only" +edition = "2021" +repository = "https://github.com/polyfrost/nexus" + +[workspace.dependencies] +prisma-client-rust = { git = "https://github.com/Brendonovich/prisma-client-rust", features = [ + "specta", + "sqlite-create-many", + "migrations", + "sqlite", +], default-features = false, branch = "rspc-0.2.0" } +prisma-client-rust-cli = { git = "https://github.com/Brendonovich/prisma-client-rust", features = [ + "specta", + "sqlite-create-many", + "migrations", + "sqlite", +], default-features = false, branch = "rspc-0.2.0" } +prisma-client-rust-sdk = { git = "https://github.com/Brendonovich/prisma-client-rust", features = [ "sqlite", ], default-features = false, branch = "rspc-0.2.0" } +rspc = { git = "https://github.com/oscartbeaumont/rspc" } +specta = { git = "https://github.com/oscartbeaumont/specta" } +tauri-specta = { git = "https://github.com/oscartbeaumont/tauri-specta" } +tauri = { version = "2.0.0-beta", features = [] } +tokio = { version = "1", features = [ "full" ] } +serde = { version = "1", features = [ "derive" ] } +uuid = { version = "1.7.0", features = [ "serde" ] } +serde_json = "1" +tracing = "0.1" +tracing-subscriber = "0.3" +tracing-appender = "0.2" + +[profile.dev] +# Make compilation faster on macOS +split-debuginfo = "unpacked" + +# Set the settings for build scripts and proc-macros. +[profile.dev.build-override] +opt-level = 3 + +# Set the default for dependencies, except workspace members. +[profile.dev.package."*"] +opt-level = 3 +incremental = false diff --git a/crates/prisma-cli/Cargo.toml b/crates/prisma-cli/Cargo.toml new file mode 100644 index 00000000..2c529713 --- /dev/null +++ b/crates/prisma-cli/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "prisma-cli" +version = "0.1.0" +license = { workspace = true } +repository = { workspace = true } +edition = { workspace = true } + +[dependencies] +prisma-client-rust-cli = { workspace = true } diff --git a/crates/prisma-cli/src/bin/prisma.rs b/crates/prisma-cli/src/bin/prisma.rs new file mode 100644 index 00000000..f7580155 --- /dev/null +++ b/crates/prisma-cli/src/bin/prisma.rs @@ -0,0 +1,3 @@ +fn main() { + prisma_client_rust_cli::run(); +} diff --git a/crates/prisma/Cargo.toml b/crates/prisma/Cargo.toml new file mode 100644 index 00000000..e4b3bdd3 --- /dev/null +++ b/crates/prisma/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "poly-prisma" +version = "0.1.0" +edition = "2021" + +[dependencies] +prisma-client-rust = { workspace = true } +serde = { workspace = true } +serde_json = { workspace = true } +uuid = { workspace = true } diff --git a/crates/prisma/src/lib.rs b/crates/prisma/src/lib.rs new file mode 100644 index 00000000..1fac3e75 --- /dev/null +++ b/crates/prisma/src/lib.rs @@ -0,0 +1,2 @@ +#[allow(warnings, unused)] +pub mod prisma; diff --git a/package.json b/package.json index 16f9deb3..7cd1ee61 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,9 @@ "serve": "vite preview", "tauri": "tauri", "lint": "eslint . --cache", - "format": "pnpm lint --fix" + "format": "pnpm lint --fix", + "prisma": "cd src-tauri && cargo prisma", + "codegen": "cargo test -p polyfrost-launcher api::tests::export -- --exact" }, "dependencies": { "@fontsource/poppins": "^5.0.12", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 4b40a0bc..6d3a7103 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -9,16 +9,31 @@ edition = "2021" tauri-build = { version = "2.0.0-beta", features = [] } [dependencies] -tauri = { version = "2.0.0-beta", features = [] } -tokio = { version = "1", features = [ "full" ] } -serde = { version = "1", features = [ "derive" ] } +poly-prisma = { path = "../crates/prisma" } +rspc = { workspace = true, features = [ + "tracing", + "unstable", +] } +tauri-specta = { workspace = true, features = [ "typescript" ] } +specta = { workspace = true } +prisma-client-rust = { workspace = true } +tauri = { workspace = true, features = [] } +tokio = { workspace = true, features = [ + "sync", + "rt-multi-thread", + "io-util", + "macros", + "time", + "process", +] } +serde = { workspace = true } serde_json = "1" tauri-plugin-shell = "2.0.0-beta.2" tauri-plugin-http = "2.0.0-beta" flate2 = "1.0.28" tar = "0.4.40" zip = "0.6.6" -uuid = { version = "1.7.0", features = [ "serde" ] } +uuid = { workspace = true } async-trait = "0.1.78" [features] diff --git a/src-tauri/prisma/schema.prisma b/src-tauri/prisma/schema.prisma new file mode 100644 index 00000000..aa1e9266 --- /dev/null +++ b/src-tauri/prisma/schema.prisma @@ -0,0 +1,62 @@ +datasource db { + provider = "sqlite" + url = "file:dev.db" +} + +generator client { + provider = "cargo prisma" + output = "../../crates/prisma/src/prisma" + module_path = "prisma" + client_format = "folder" +} + +// todo: replace all `path` fields with a model with a checksum n shit + +// represents a single minecraft instance +model Instance { + id Int @id @default(autoincrement()) + name String? + path String? + hidden Boolean? + + time_played DateTime + last_played DateTime + date_created DateTime + + mods Mod[] + // java_instance JavaInstance + + @@map("instance") +} + +model JavaInstance { + id Int @id @default(autoincrement()) + name String? + path String? + version String? + arch String? + + /// @local + instance_id Int? + // instance Instance? @relation(fields: [instance_id], references: [id]) + + @@map("java_instance") +} + +model Mod { + id Int @id @default(autoincrement()) + + name String? + path String? + enabled Boolean @default(true) + hidden Boolean? + date_added DateTime? + + /// @local + instance_id Int? + instance Instance? @relation(fields: [instance_id], references: [id], onDelete: SetNull) + + @@map("location") +} + +// todo the rest of this shit loll diff --git a/src-tauri/src/api.rs b/src-tauri/src/api.rs new file mode 100644 index 00000000..c3a611e4 --- /dev/null +++ b/src-tauri/src/api.rs @@ -0,0 +1,32 @@ +use std::sync::Arc; + +use crate::Node; + +pub type Ctx = Arc; +pub type Router = rspc::Router; + +#[derive(Debug, Clone, Serialize, Type)] +pub enum CoreEvent { + InvalidateOperation(), + MSALogin(), +} + +pub(crate) fn mount() -> Arc { + let r = R + .router(); + + let r = r.build({ + let config = rspc::ExportConfig::new(std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../src/client.ts")).set_header("/* eslint-disable */"); + config + }); + + r +} + +#[cfg(test)] +mod tests { + #[test] + fn export() { + super::mount(); + } +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 055f5a42..30aafb72 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -1,4 +1,51 @@ +use std::{env, f32::consts::E, path::{Path, PathBuf}, sync::Arc}; + +use rspc::Router; +use tokio::sync::broadcast; + pub mod auth; pub mod game; pub mod utils; -pub mod constants; \ No newline at end of file +pub mod constants; + +pub(crate) mod api; + +// represents all data and stuff idk +// holds references to services like http and microsoft and stuff for ease of use +pub struct Node { + pub config: something, + pub data_dir: PathBuf, + pub env: Arc<>, +} + +impl Node { + pub async fn new( + data_dir: impl AsRef, + env: idikdjasdgjsbana, + ) -> Result<(Arc, Arc), NodeError> { + let data_dir = data_dir.as_ref(); + + print!("starting with data dir '{}'", data_dir.display()); + + let env = Arc::new(env); + + let _ = fs::create_dir_all(&data_dir).await; + let event_bus = broadcast::channel(1024); + + + let node = Arc::new(Node { + data_dir: data_dir.to_path_buf(), + env, + }); + + let router = api::mount(); + + Ok((node, router)); + } +} + +#[derive(Error, Debug)] +pub enum NodeError { + #[error("the error error error: {0}")] + ErrorErrorError(String), +}