🚧 wip: it builds somehow

This commit is contained in:
Pauline 2024-07-29 22:03:45 +02:00
parent db678b9a9d
commit ef729dd8e5
No known key found for this signature in database
GPG key ID: 722BB181973296AE
23 changed files with 655 additions and 345 deletions

View file

@ -19,10 +19,7 @@ crate-type = [
]
[build-dependencies]
tauri-build = { workspace = true, features = [
"isolation",
"codegen",
] }
tauri-build = { workspace = true, features = [ "isolation" ] }
[dependencies]
onelauncher = { workspace = true, features = [ "tauri" ] }

View file

@ -1,39 +1,3 @@
fn main() {
tauri_build::try_build(
tauri_build::Attributes::new()
.codegen(tauri_build::CodegenContext::new())
.plugin(
"onelauncher",
tauri_build::InlinedPlugin::new().commands(&[
// User
"auth_login",
"get_users",
"get_user",
"remove_user",
"get_default_user",
"set_default_user",
// Cluster
"create_cluster",
"edit_cluster",
"remove_cluster",
"get_cluster",
"get_clusters",
"run_cluster",
// Processor
"get_running_clusters",
"get_processes_by_path",
"kill_process",
// Settings
"get_settings",
"set_settings",
// Metadata
"get_minecraft_versions",
// Package
"random_mods",
"get_mod",
"download_mod",
]),
),
)
.expect("failed to run tauri-build")
tauri_build::build();
}

View file

@ -1 +0,0 @@
schemas/

View file

@ -1,14 +1,20 @@
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "permissions that were migrated from v1",
"local": true,
"windows": [
"*"
],
"description": "capabilities for the main window",
"windows": ["*"],
"permissions": [
"onelauncher:default",
"app:default",
"webview:default",
"image:default",
"menu:default",
"path:default",
"resources:default",
"tray:default",
"window:default",
"window:allow-close",
"window:allow-create",
"window:allow-destroy",
"window:allow-start-dragging",
"window:allow-minimize",
@ -18,6 +24,9 @@
"event:default",
"shell:allow-open",
"clipboard-manager:allow-write-text",
"dialog:allow-open"
"dialog:allow-open",
"dialog:allow-save",
"dialog:allow-confirm",
"webview:allow-internal-toggle-devtools"
]
}

View file

@ -1,36 +0,0 @@
[default]
description = "Default permissions for the plugin"
permissions = [
# User
"allow-auth-login",
"allow-get-users",
"allow-get-user",
"allow-remove-user",
"allow-get-default-user",
"allow-set-default-user",
# Cluster
"allow-create-cluster",
"allow-edit-cluster",
"allow-remove-cluster",
"allow-get-cluster",
"allow-get-clusters",
"allow-run-cluster",
# Processor
"allow-get-running-clusters",
"allow-get-processes-by-path",
"allow-kill-process",
# Settings
"allow-get-settings",
"allow-set-settings",
# Metadata
"allow-get-minecraft-versions",
# Package
"allow-random-mods",
"allow-get-mod",
"allow-download-mod",
]

View file

@ -15,34 +15,38 @@ use uuid::Uuid;
macro_rules! collect_commands {
() => {{
use $crate::api::commands::*;
use $crate::ext::updater::*;
tauri_specta::collect_commands![
// User
auth_login,
get_users,
get_user,
get_default_user,
set_default_user,
remove_user,
// Cluster
create_cluster,
edit_cluster,
remove_cluster,
get_cluster,
get_clusters,
run_cluster,
// Processor
get_running_clusters,
get_processes_by_path,
kill_process,
// Settings
get_settings,
set_settings,
// Metadata
get_minecraft_versions,
// Package
random_mods,
get_mod,
download_mod,
// User
auth_login,
get_users,
get_user,
get_default_user,
set_default_user,
remove_user,
// Cluster
create_cluster,
edit_cluster,
remove_cluster,
get_cluster,
get_clusters,
run_cluster,
// Processor
get_running_clusters,
get_processes_by_path,
kill_process,
// Settings
get_settings,
set_settings,
// Metadata
get_minecraft_versions,
// Package
random_mods,
get_mod,
download_mod,
// Updater
check_for_update,
install_update,
]
}};
}
@ -90,17 +94,18 @@ pub async fn edit_cluster(
name: Option<String>,
icon_path: Option<String>,
) -> Result<(), String> {
let cluster = cluster::get_by_uuid(uuid, None).await?.ok_or("cluster does not exist")?;
let cluster = cluster::get_by_uuid(uuid, None)
.await?
.ok_or("cluster does not exist")?;
cluster::edit(&cluster.cluster_path(), move |cluster| {
if let Some(name) = name.clone() {
cluster.meta.name = name;
}
async move {
Ok(())
}
}).await?;
async move { Ok(()) }
})
.await?;
let icon_path = icon_path.and_then(|x| PathBuf::from_str(x.as_str()).ok());
cluster::edit_icon(&cluster.cluster_path(), icon_path.as_deref()).await?;

View file

@ -10,5 +10,5 @@ macro_rules! collect_events {
InternetPayload,
OfflinePayload,
]
}}
}
}};
}

View file

@ -1,12 +1,12 @@
use onelauncher::constants::*;
use serde::Serialize;
use specta::Type;
use tauri_specta::StaticCollection;
use onelauncher::constants::*;
pub fn get_static_collection() -> StaticCollection {
StaticCollection::default()
.register("PROGRAM_INFO", get_program_info())
.to_owned()
.to_owned()
}
#[derive(Serialize, Type)]
@ -32,4 +32,4 @@ fn get_program_info() -> ProgramInfo {
platform: TARGET_OS.into(),
arch: NATIVE_ARCH.into(),
}
}
}

View file

View file

View file

@ -1 +1,3 @@
pub mod updater;
pub mod macos;
pub mod menu;

View file

@ -3,7 +3,7 @@ use tauri::{Manager, Runtime};
use tauri_plugin_updater::{Update as TauriPluginUpdate, UpdaterExt};
use tokio::sync::Mutex;
#[derive(Debug, Clone, serde::Serialize)]
#[derive(Debug, Clone, specta::Type, serde::Serialize)]
pub struct Update {
pub version: String,
}
@ -32,7 +32,7 @@ async fn get_update(app: tauri::AppHandle) -> Result<Option<TauriPluginUpdate>,
.map_err(|e| e.to_string())
}
#[derive(Clone, serde::Serialize)]
#[derive(Clone, serde::Serialize, specta::Type)]
#[serde(rename_all = "camelCase", tag = "status")]
pub enum UpdateEvent {
Loading,
@ -43,6 +43,7 @@ pub enum UpdateEvent {
}
#[tauri::command]
#[specta::specta]
pub async fn check_for_update(app: tauri::AppHandle) -> Result<Option<Update>, String> {
app.emit("updater", UpdateEvent::Loading).ok();
@ -70,6 +71,7 @@ pub async fn check_for_update(app: tauri::AppHandle) -> Result<Option<Update>, S
}
#[tauri::command]
#[specta::specta]
pub async fn install_update(
app: tauri::AppHandle,
state: tauri::State<'_, State>,

View file

@ -41,12 +41,12 @@ pub async fn run_app<F: FnOnce(&mut tauri::App) + Send + 'static>(setup: F) {
let builder = tauri_specta::ts::builder()
.config(
specta::ts::ExportConfig::default()
.bigint(specta::ts::BigIntExportBehavior::BigInt)
.bigint(specta::ts::BigIntExportBehavior::BigInt),
)
.header("// @ts-ignore")
.statics(get_static_collection())
.commands(collect_commands!())
.events(collect_events!());
.header("/* eslint-disable -- auto-generated file */")
.statics(get_static_collection())
.commands(collect_commands!())
.events(collect_events!());
#[cfg(debug_assertions)]
let builder = builder.path("../frontend/src/bindings.ts");
@ -66,6 +66,7 @@ pub async fn run_app<F: FnOnce(&mut tauri::App) + Send + 'static>(setup: F) {
.plugin(ext::updater::plugin())
.manage(ext::updater::State::default())
.plugin(tauri_plugin_dialog::init())
// TODO: add back tauri-plugin-window-state -- it's buggy at the moment
// .plugin(tauri_plugin_window_state::Builder::default().build())
.plugin(api::init())
.menu(tauri::menu::Menu::new)
@ -77,19 +78,17 @@ pub async fn run_app<F: FnOnce(&mut tauri::App) + Send + 'static>(setup: F) {
});
let app = builder
.build(tauri::tauri_build_context!())
.build(tauri::generate_context!())
.expect("failed to build tauri application");
if let Err(err) = initialize_state(app.app_handle().clone()).await {
tracing::error!("{err}");
};
app.run(|_app_handle, _event| {})
app.run(|_, _| {})
}
fn setup(app: &mut tauri::App) -> Result<(), Box<dyn std::error::Error>> {
// todo setup deep linking once docs are done
let win = app.get_webview_window("main").unwrap();
win.show().unwrap();

View file

@ -31,9 +31,9 @@
"@tauri-apps/plugin-shell": "github:tauri-apps/tauri-plugin-shell#v2",
"@thisbeyond/solid-dnd": "^0.7.5",
"@thisbeyond/solid-select": "^0.15.0",
"@unocss/reset": "^0.61.6",
"@unocss/reset": "^0.61.7",
"@untitled-theme/icons-solid": "^0.10.5",
"overlayscrollbars": "^2.9.2",
"overlayscrollbars": "^2.10.0",
"overlayscrollbars-solid": "^0.5.5",
"solid-js": "^1.8.19",
"solid-transition-group": "^0.2.3",
@ -46,7 +46,7 @@
"@types/uuid": "^10.0.0",
"jsdom": "^24.1.1",
"sass": "^1.77.8",
"unocss": "^0.61.6",
"unocss": "^0.61.7",
"vite-plugin-solid": "^2.10.2",
"vite-plugin-solid-svg": "^0.8.1",
"vite-tsconfig-paths": "^4.3.2"

View file

@ -1,6 +1,5 @@
import { Edit02Icon, ImagePlusIcon, PlayIcon, Save01Icon, Share07Icon, Trash01Icon, XIcon } from '@untitled-theme/icons-solid';
import { Edit02Icon, ImagePlusIcon, PlayIcon, Save01Icon, Share07Icon, Trash01Icon } from '@untitled-theme/icons-solid';
import { Show, createSignal, untrack } from 'solid-js';
import type { BeforeLeaveEventArgs } from '@solidjs/router';
import { useBeforeLeave, useNavigate } from '@solidjs/router';
import * as dialog from '@tauri-apps/plugin-dialog';
import ClusterCover from '../../components/game/ClusterCover';

View file

@ -108,7 +108,7 @@ pub async fn run_credentials(
if let Some(command) = cmd.next() {
let full_path = path.full_path().await?;
let result = Command::new(command)
.args(&cmd.collect::<Vec<&str>>())
.args(cmd.collect::<Vec<&str>>())
.current_dir(&full_path)
.spawn()
.map_err(|e| IOError::with_path(e, &full_path))?

View file

@ -7,7 +7,7 @@ use crate::proxy::send::{init_ingress, send_ingress};
use crate::utils::http::{fetch_advanced, fetch_json};
use crate::utils::io::{self, IOError};
use crate::utils::java::{self, get_java_version, JavaVersion};
use crate::{constants, State};
use crate::State;
pub async fn filter_java_version(java_version: Option<u32>) -> crate::Result<Vec<JavaVersion>> {
let java = java::locate_java().await?;

View file

@ -157,19 +157,19 @@ struct SearchResults {
hits: Vec<ModrinthPackage>,
}
pub async fn search(query: &str) -> Result<Vec<ModrinthPackage>> {
// TODO: Fix date_created and date_updated inconsistency (published and updated)
let response: SearchResults = serde_json::from_slice(
&fetch(
format_url!("/search?query={}", query).as_str(),
None,
&State::get().await?.fetch_semaphore,
)
.await?,
)?;
// pub async fn search(query: &str) -> Result<Vec<ModrinthPackage>> {
// // TODO: Fix date_created and date_updated inconsistency (published and updated)
// let response: SearchResults = serde_json::from_slice(
// &fetch(
// format_url!("/search?query={}", query).as_str(),
// None,
// &State::get().await?.fetch_semaphore,
// )
// .await?,
// )?;
Ok(response.hits)
}
// Ok(response.hits)
// }
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]

View file

@ -20,8 +20,8 @@ pub async fn is_valid_modrinth(instance_folder: PathBuf) -> bool {
}
pub async fn import_modrinth(
modrinth_instance_folder: PathBuf,
cluster_path: ClusterPath,
_modrinth_instance_folder: PathBuf,
_cluster_path: ClusterPath,
) -> crate::Result<()> {
Ok(())
}

View file

@ -1,7 +1,8 @@
use super::IngressId;
use crate::{api::proxy::{
use crate::api::proxy::{
ClusterPayloadType, Ingress, IngressType, InternetPayload, ProcessPayloadType, ProxyError,
}, proxy::OfflinePayload};
};
use crate::proxy::OfflinePayload;
use crate::store::{ClusterPath, IngressProcessType, IngressProcessor};
use uuid::Uuid;
@ -135,7 +136,6 @@ pub async fn send_ingress(
.set_position((display * CLI_TOTAL_INGRESS as f64).round() as u64);
}
#[cfg(feature = "tauri")]
proxy_state
.app
@ -168,7 +168,8 @@ pub async fn send_message(message: &str) -> crate::Result<()> {
let proxy_state = crate::ProxyState::get().await?;
MessagePayload {
message: message.to_string(),
}.emit(proxy_state.app.app_handle())?;
}
.emit(proxy_state.app.app_handle())?;
}
tracing::warn!("{}", message);
@ -230,7 +231,8 @@ pub async fn send_process(
pid,
event,
message: message.to_string(),
}.emit(proxy_state.app.app_handle())?;
}
.emit(proxy_state.app.app_handle())?;
}
Ok(())
@ -265,7 +267,8 @@ pub async fn send_cluster(
path,
name: name.to_string(),
event,
}.emit(proxy_state.app.app_handle())?;
}
.emit(proxy_state.app.app_handle())?;
}
Ok(())

View file

@ -394,7 +394,8 @@ impl Cluster {
file_name: &str,
) -> crate::Result<()> {
let icon = io::read(icon).await?;
self.set_icon_bytes(cache_path, io_semaphore, icon.into(), file_name).await?;
self.set_icon_bytes(cache_path, io_semaphore, icon.into(), file_name)
.await?;
Ok(())
}

View file

@ -641,7 +641,7 @@ impl Processor {
let mut cmd = hook.split(' ');
if let Some(c) = cmd.next() {
let mut c = Command::new(c);
c.args(&cmd.collect::<Vec<&str>>())
c.args(cmd.collect::<Vec<&str>>())
.current_dir(cluster_path.full_path().await?);
Some(c)
} else {

732
pnpm-lock.yaml generated

File diff suppressed because it is too large Load diff