diff --git a/.cargo/config.toml b/.cargo/config.toml index 48c6e34b..40371165 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -5,3 +5,4 @@ rustflags = [ ] [alias] +prisma = "run -p prisma-cli --bin prisma --" diff --git a/.gitignore b/.gitignore index 3b9a11a3..d239a252 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ repl-result-out* .direnv # Prisma -crates/prisma/src/prisma.rs +crates/prisma/src/prisma dev.db dev.db-journal diff --git a/Cargo.toml b/Cargo.toml index 1dd59d6b..0022d128 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -205,6 +205,7 @@ opt-level = 3 opt-level = 3 incremental = false + # sets the default for dependencies, except workspace members. [profile.dev-debug.package."*"] inherits = "dev" diff --git a/apps/desktop/src-tauri/Info.plist b/apps/desktop/src-tauri/Info.plist index a2f70cdb..5b2f640d 100644 --- a/apps/desktop/src-tauri/Info.plist +++ b/apps/desktop/src-tauri/Info.plist @@ -10,7 +10,7 @@ OneLauncher CFBundleURLSchemes - onelauncher + OneLauncher diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index 0dd48e2c..18f52807 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -17,15 +17,19 @@ default = [] tauri = [ "dep:tauri", "dep:tauri-specta", - "dep:specta" + "dep:specta", ] cli = [ "dep:indicatif" ] [dependencies] +onelauncher_prisma = { path = "../prisma" } + # GUI-only deps tauri = { workspace = true, optional = true } tauri-specta = { workspace = true, optional = true } specta = { workspace = true, optional = true } +# rspc = { workspace = true } +# rspc-tauri2 = { workspace = true, optional = true } # CLI-only deps indicatif = { workspace = true, optional = true } @@ -49,6 +53,7 @@ serde = { workspace = true } serde_json = { workspace = true } serde_ini = { workspace = true } flate2 = { workspace = true } +dashmap = { workspace = true } paste = { workspace = true } futures = { workspace = true } tar = { workspace = true } diff --git a/crates/core/prisma/migrations/20240725024623_init/migration.sql b/crates/core/prisma/migrations/20240725024623_init/migration.sql new file mode 100644 index 00000000..a43ab655 --- /dev/null +++ b/crates/core/prisma/migrations/20240725024623_init/migration.sql @@ -0,0 +1,115 @@ +-- CreateTable +CREATE TABLE "settings" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT DEFAULT 0, + "theme" TEXT NOT NULL DEFAULT 'dark', + "hide_close_prompt" BOOLEAN NOT NULL DEFAULT true, + "disable_animations" BOOLEAN NOT NULL DEFAULT false, + "disable_analytics" BOOLEAN NOT NULL DEFAULT false, + "debug_mode" BOOLEAN NOT NULL DEFAULT false, + "hide_on_launch" BOOLEAN NOT NULL DEFAULT false, + "force_fullscreen" BOOLEAN NOT NULL DEFAULT false, + "disable_discord" BOOLEAN NOT NULL DEFAULT false, + "custom_java_args" TEXT NOT NULL, + "custom_env_args" TEXT NOT NULL, + "max_async_io_operations" INTEGER NOT NULL DEFAULT 10, + "max_async_fetches" INTEGER NOT NULL DEFAULT 10, + "resolution_x" INTEGER NOT NULL DEFAULT 854, + "resolution_y" INTEGER NOT NULL DEFAULT 480, + "memory_max" INTEGER NOT NULL DEFAULT 2048, + "memory_min" INTEGER NOT NULL DEFAULT 1024, + "hook_pre" TEXT, + "hook_wrapper" TEXT, + "hook_post" TEXT +); + +-- CreateTable +CREATE TABLE "java_version" ( + "major_version" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "full_version" TEXT NOT NULL, + "architecture" TEXT NOT NULL, + "path" TEXT NOT NULL +); + +-- CreateTable +CREATE TABLE "minecraft_user" ( + "uuid" TEXT NOT NULL PRIMARY KEY, + "active" BOOLEAN NOT NULL DEFAULT false, + "username" TEXT NOT NULL, + "access_token" TEXT NOT NULL, + "refresh_token" TEXT NOT NULL, + "expires" INTEGER NOT NULL +); + +-- CreateTable +CREATE TABLE "minecraft_device_token" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT DEFAULT 0, + "uuid" TEXT NOT NULL, + "private_key" TEXT NOT NULL, + "x" TEXT NOT NULL, + "y" TEXT NOT NULL, + "issue_instant" INTEGER NOT NULL, + "not_after" INTEGER NOT NULL, + "token" TEXT NOT NULL, + "display_claims" TEXT NOT NULL +); + +-- CreateTable +CREATE TABLE "cache" ( + "id" TEXT NOT NULL PRIMARY KEY, + "data_type" TEXT NOT NULL, + "alias" TEXT, + "data" TEXT, + "expires" DATETIME NOT NULL, + "created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- CreateTable +CREATE TABLE "cluster" ( + "path" TEXT NOT NULL PRIMARY KEY, + "stage" TEXT NOT NULL, + "name" TEXT NOT NULL, + "icon_path" TEXT, + "mc_version" TEXT NOT NULL, + "loader" TEXT NOT NULL DEFAULT 'vanilla', + "loader_version" TEXT DEFAULT 'stable', + "groups" TEXT NOT NULL, + "created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "modified_at" DATETIME NOT NULL, + "played_at" DATETIME, + "overall_played" INTEGER NOT NULL DEFAULT 0, + "recently_played" INTEGER NOT NULL DEFAULT 0, + "override_java_path" TEXT, + "override_custom_java_args" TEXT NOT NULL, + "override_custom_env_args" TEXT NOT NULL, + "override_memory_max" INTEGER, + "override_memory_min" INTEGER, + "override_force_fullscreen" INTEGER, + "override_resolution_x" INTEGER, + "override_resolution_y" INTEGER, + "override_hook_pre" TEXT, + "override_hook_wrapper" TEXT, + "override_hook_post" TEXT +); + +-- CreateTable +CREATE TABLE "process" ( + "pid" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "start_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "name" TEXT NOT NULL, + "executable" TEXT NOT NULL, + "cluster_path" TEXT NOT NULL, + "post_exit" TEXT, + CONSTRAINT "process_cluster_path_fkey" FOREIGN KEY ("cluster_path") REFERENCES "cluster" ("path") ON DELETE RESTRICT ON UPDATE CASCADE +); + +-- CreateIndex +CREATE UNIQUE INDEX "minecraft_user_active_key" ON "minecraft_user"("active"); + +-- CreateIndex +CREATE UNIQUE INDEX "cache_data_type_alias_key" ON "cache"("data_type", "alias"); + +-- CreateIndex +CREATE INDEX "process_cluster_path_idx" ON "process"("cluster_path"); + +-- CreateIndex +CREATE UNIQUE INDEX "process_pid_key" ON "process"("pid"); diff --git a/crates/core/prisma/migrations/migration_lock.toml b/crates/core/prisma/migrations/migration_lock.toml new file mode 100644 index 00000000..e5e5c470 --- /dev/null +++ b/crates/core/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "sqlite" \ No newline at end of file diff --git a/crates/core/prisma/schema.prisma b/crates/core/prisma/schema.prisma new file mode 100644 index 00000000..80c49481 --- /dev/null +++ b/crates/core/prisma/schema.prisma @@ -0,0 +1,139 @@ +datasource db { + provider = "sqlite" + url = "file:dev.db" +} + +generator client { + provider = "cargo prisma" + output = "../../prisma/src/prisma" + module_path = "prisma" + client_format = "folder" +} + +model Settings { + id Int @id @default(0) + theme String @default("dark") + hide_close_prompt Boolean @default(true) + disable_animations Boolean @default(false) + disable_analytics Boolean @default(false) + debug_mode Boolean @default(false) + hide_on_launch Boolean @default(false) + force_fullscreen Boolean @default(false) + disable_discord Boolean @default(false) + + custom_java_args String + custom_env_args String + + max_async_io_operations Int @default(10) + max_async_fetches Int @default(10) + + resolution_x Int @default(854) + resolution_y Int @default(480) + + memory_max Int @default(2048) + memory_min Int @default(1024) + + hook_pre String? + hook_wrapper String? + hook_post String? + + @@map("settings") +} + +model JavaVersion { + major_version Int @id + full_version String + architecture String + path String + + @@map("java_version") +} + +model MinecraftUser { + uuid String @id + active Boolean @default(false) + username String + access_token String + refresh_token String + expires Int + + @@unique([active]) + @@map("minecraft_user") +} + +model MinecraftDeviceToken { + id Int @id @default(0) + uuid String + private_key String + x String + y String + issue_instant Int + not_after Int + token String + display_claims String + + @@map("minecraft_device_token") +} + +model Cache { + id String @id + data_type String + alias String? + data String? + expires DateTime + created DateTime @default(now()) + + @@unique([data_type, alias]) + @@map("cache") +} + +model Cluster { + path String @id + stage String + name String + icon_path String? + + mc_version String + loader String @default("vanilla") + loader_version String? @default("stable") + + groups String + + created_at DateTime @default(now()) + modified_at DateTime + played_at DateTime? + + overall_played Int @default(0) + recently_played Int @default(0) + + override_java_path String? + override_custom_java_args String + override_custom_env_args String + override_memory_max Int? + override_memory_min Int? + override_force_fullscreen Int? + override_resolution_x Int? + override_resolution_y Int? + override_hook_pre String? + override_hook_wrapper String? + override_hook_post String? + + processes Process[] + + @@map("cluster") +} + +model Process { + pid Int @id + start_time DateTime @default(now()) + name String + executable String + cluster_path String + post_exit String? + + cluster Cluster @relation(fields: [cluster_path], references: [path]) + + @@unique([pid]) + @@index([cluster_path]) + @@map("process") +} diff --git a/crates/prisma-cli/Cargo.toml b/crates/prisma-cli/Cargo.toml new file mode 100644 index 00000000..ab73cec7 --- /dev/null +++ b/crates/prisma-cli/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "prisma-cli" +version = { workspace = true } +license = { workspace = true } +edition = { workspace = true } +repository = { workspace = true } +documentation = { workspace = true } +readme = { workspace = true } +homepage = { workspace = true } +authors = { 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..400cca59 --- /dev/null +++ b/crates/prisma/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "onelauncher_prisma" +version = { workspace = true } +license = { workspace = true } +edition = { workspace = true } +repository = { workspace = true } +documentation = { workspace = true } +readme = { workspace = true } +homepage = { workspace = true } +authors = { workspace = true } + +[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..aedd2283 --- /dev/null +++ b/crates/prisma/src/lib.rs @@ -0,0 +1,3 @@ +#![recursion_limit = "256"] +#[allow(warnings, unused)] +pub mod prisma; diff --git a/crates/testing/src/main.rs b/crates/testing/src/main.rs index 38ca240b..ba8328ea 100644 --- a/crates/testing/src/main.rs +++ b/crates/testing/src/main.rs @@ -107,9 +107,9 @@ async fn launch_and_authenticate() -> onelauncher::Result<()> { } } - let name = "examplecluster".to_string(); - let game = "1.20.4".to_string(); - let loader = Loader::Vanilla; + let name = "Example".to_string(); + let game = "1.21".to_string(); + let loader = Loader::Fabric; let loader_version = "stable".to_string(); let cluster = create_cluster( diff --git a/package.json b/package.json index 47ebc28a..53097c38 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,13 @@ "format": "pnpm lint:fix && cargo +nightly fmt", "lint": "pnpm eslint . --cache", "lint:fix": "pnpm lint --fix", + "format": "pnpm lint:fix && pnpm core:prisma format", + "prep": "pnpm gen:prisma", "release:node": "pnpm bumpp -r", - "core": "cd crates/core && cargo" + "core": "cd crates/core && cargo", + "gen:prisma": "pnpm core prisma generate", + "gen:migrations": "pnpm core prisma migrate dev", + "gen:code": "pnpm core test gen" }, "devDependencies": { "@flowr/eslint-config": "^3.10.0",