git stashing this, added specta

This commit is contained in:
LynithDev 2024-06-02 11:23:38 +02:00
parent 327d895258
commit 9fb55128e2
10 changed files with 213 additions and 33 deletions

32
.idea/codeStyles/Project.xml generated Normal file
View file

@ -0,0 +1,32 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JSCodeStyleSettings version="0">
<option name="IMPORT_SORT_MODULE_NAME" value="true" />
</JSCodeStyleSettings>
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="JAVA">
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JSON">
<indentOptions>
<option name="INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
<codeStyleSettings language="JavaScript">
<option name="IF_BRACE_FORCE" value="1" />
<option name="DOWHILE_BRACE_FORCE" value="1" />
<option name="WHILE_BRACE_FORCE" value="1" />
<option name="FOR_BRACE_FORCE" value="1" />
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
</codeStyleSettings>
</code_scheme>
</component>

5
.idea/codeStyles/codeStyleConfig.xml generated Normal file
View file

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

View file

@ -4,7 +4,6 @@ members = [
"core",
"debugger",
"desktop/src-tauri",
"testing",
]
[workspace.package]
@ -33,7 +32,7 @@ tauri-plugin-updater = { git = "https://github.com/tauri-apps/plugins-workspace"
rspc = { version = "0.2.0", features = [ "specta2" ] }
specta = { version = "=2.0.0-rc.12" }
tauri-specta = { version = "=2.0.0-rc.9", features = [
tauri-specta = { version = "=2.0.0-rc.10", features = [
"javascript",
"typescript"
] }

View file

@ -14,12 +14,22 @@ authors = { workspace = true }
default = []
# feature flag allowing us to interact with tauri (for loading animations, errors showing on gui, etc)
# also allows us to compile onelauncher core without tauri
tauri = [ "dep:tauri" ]
tauri = [
"dep:tauri",
"dep:tauri-specta",
"dep:specta"
]
cli = [ "dep:indicatif" ]
[dependencies]
onelauncher_debug = { path = "../debugger" }
# GUI-only deps
tauri = { workspace = true, optional = true }
tauri-specta = { workspace = true, optional = true }
specta = { workspace = true, optional = true }
# CLI-only deps
indicatif = { workspace = true, optional = true }
interpulse = { workspace = true }

1
desktop/.gitignore vendored
View file

@ -1,2 +1,3 @@
/dist-isolation
/coverage
./src/bindings.ts

View file

@ -41,6 +41,9 @@ tauri-plugin-single-instance = { workspace = true }
tauri-plugin-updater = { workspace = true }
tauri-plugin-authenticator = { workspace = true }
tauri-specta = { workspace = true }
specta = { workspace = true }
tokio = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }

View file

@ -0,0 +1,43 @@
use tauri_specta::{Builder, ExportLanguage};
use crate::api;
#[macro_export]
macro_rules! collect_commands {
() => {
{
use crate::api::commands::*;
tauri_specta::ts::builder()
.commands(tauri_specta::collect_commands![
initialize_state,
is_dev
])
}
};
}
pub fn test() -> Builder {
use crate::api::commands::*;
tauri_specta::ts::builder()
.commands(tauri_specta::collect_commands![
initialize_state,
is_dev
])
}
#[specta::specta]
#[tracing::instrument(skip_all)]
#[tauri::command]
pub async fn initialize_state(app: tauri::AppHandle) -> api::Result<()> {
onelauncher::ProxyState::initialize(app).await?;
let s = onelauncher::State::get().await?;
onelauncher::State::update();
s.processor.write().await.restore().await?;
Ok(())
}
#[specta::specta]
#[tauri::command]
pub fn is_dev() -> bool {
cfg!(debug_assertions)
}

View file

@ -4,6 +4,8 @@ use tauri::plugin::TauriPlugin;
use tauri::Manager;
use tokio::sync::Mutex;
pub mod commands;
pub fn init<R: tauri::Runtime>() -> TauriPlugin<R> {
tauri::plugin::Builder::new("onelauncher")
.setup(|app, _| {
@ -11,14 +13,31 @@ pub fn init<R: tauri::Runtime>() -> TauriPlugin<R> {
Ok(())
})
.invoke_handler(tauri::generate_handler![])
.build()
}
pub type Result<T> = std::result::Result<T, OneLauncherSerializableError>;
#[derive(thiserror::Error, Debug)]
#[derive(thiserror::Error, Debug, Serialize, specta::Type)]
pub enum OneLauncherSerializableError {
#[error("{0}")]
CommonError(String),
}
impl From<OneLauncherError> for OneLauncherSerializableError {
fn from(value: OneLauncherError) -> Self {
Self::CommonError(value.to_string())
}
}
impl From<onelauncher::Error> for OneLauncherSerializableError {
fn from(value: onelauncher::Error) -> Self {
Self::CommonError(value.to_string())
}
}
#[derive(thiserror::Error, Debug)]
pub enum OneLauncherError {
#[error("{0}")]
OneLauncher(#[from] onelauncher::Error),
@ -37,14 +56,14 @@ pub enum OneLauncherSerializableError {
// (yoinked under MIT license)
macro_rules! impl_serialize_err {
($($variant:ident),* $(,)?) => {
impl Serialize for OneLauncherSerializableError {
impl Serialize for OneLauncherError {
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
where
S: Serializer,
{
use serde::ser::SerializeStruct;
match self {
OneLauncherSerializableError::OneLauncher(onelauncher_error) => {
OneLauncherError::OneLauncher(onelauncher_error) => {
$crate::error::display_tracing_error(onelauncher_error);
let mut state = serializer.serialize_struct("OneLauncher", 2)?;
@ -53,7 +72,7 @@ macro_rules! impl_serialize_err {
state.end()
}
$(
OneLauncherSerializableError::$variant(message) => {
OneLauncherError::$variant(message) => {
let mut state = serializer.serialize_struct(stringify!($variant), 2)?;
state.serialize_field("field_name", stringify!($variant))?;
state.serialize_field("message", &message.to_string())?;

View file

@ -1,25 +1,10 @@
use tauri::Manager;
use crate::api::commands;
pub mod api;
pub mod error;
pub mod ext;
// #[tracing::instrument(skip_all)]
// #[tauri::command]
// async fn initialize_state(app: tauri::AppHandle) -> api::Result<()> {
// onelauncher::ProxyState::initialize(app).await?;
// let s = onelauncher::State::get().await?;
// onelauncher::State::update();
// s.processor.write().await.restore().await?;
// Ok(())
// }
#[tauri::command]
fn is_dev() -> bool {
cfg!(debug_assertions)
}
#[derive(Clone, serde::Serialize)]
struct SingleInstancePayload {
args: Vec<String>,
@ -33,7 +18,7 @@ pub async fn run() {
let _log_guard = onelauncher::start_logger();
tracing::info!("initialized tracing subscriber. loading onelauncher...");
run_app(tauri::Builder::default(), |app| {
run_app(|app| {
if let Err(err) = setup(app) {
tracing::error!("failed to setup app: {:?}", err);
}
@ -41,11 +26,10 @@ pub async fn run() {
.await;
}
pub async fn run_app<R: tauri::Runtime, F: FnOnce(&mut tauri::App<R>) + Send + 'static>(
builder: tauri::Builder<R>,
pub async fn run_app<F: FnOnce(&mut tauri::App) + Send + 'static>(
setup: F,
) {
let builder = builder
let builder = tauri::Builder::default()
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
println!("{}, {argv:?}, {cwd}", app.package_info().name);
@ -55,7 +39,7 @@ pub async fn run_app<R: tauri::Runtime, F: FnOnce(&mut tauri::App<R>) + Send + '
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(ext::updater::plugin())
.manage(ext::updater::State::default())
// .plugin(tauri_plugin_window_state::Builder::default().build())
.plugin(tauri_plugin_window_state::Builder::default().build())
.menu(tauri::menu::Menu::new)
.setup(move |app| {
setup(app);
@ -64,10 +48,14 @@ pub async fn run_app<R: tauri::Runtime, F: FnOnce(&mut tauri::App<R>) + Send + '
let builder = builder
.plugin(api::init())
.invoke_handler(tauri::generate_handler![
// initialize_state,
is_dev,
]);
.invoke_handler({
let builder = commands::test();
#[cfg(debug_assertions)]
let builder = builder.path("../src/bindings.ts");
builder.build().unwrap()
});
let app = builder
.build(tauri::tauri_build_context!())

80
desktop/src/bindings.ts Normal file
View file

@ -0,0 +1,80 @@
// This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually.
export const commands = {
async initializeState() : Promise<Result<null, OneLauncherSerializableError>> {
try {
return { status: "ok", data: await TAURI_INVOKE("initialize_state") };
} catch (e) {
if(e instanceof Error) throw e;
else return { status: "error", error: e as any };
}
},
async isDev() : Promise<boolean> {
return await TAURI_INVOKE("is_dev");
}
}
/** user-defined types **/
export type OneLauncherSerializableError = { CommonError: string }
/** tauri-specta globals **/
import { invoke as TAURI_INVOKE } from "@tauri-apps/api/core";
import * as TAURI_API_EVENT from "@tauri-apps/api/event";
import { type WebviewWindow as __WebviewWindow__ } from "@tauri-apps/api/webviewWindow";
type __EventObj__<T> = {
listen: (
cb: TAURI_API_EVENT.EventCallback<T>
) => ReturnType<typeof TAURI_API_EVENT.listen<T>>;
once: (
cb: TAURI_API_EVENT.EventCallback<T>
) => ReturnType<typeof TAURI_API_EVENT.once<T>>;
emit: T extends null
? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit>
: (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>;
};
export type Result<T, E> =
| { status: "ok"; data: T }
| { status: "error"; error: E };
function __makeEvents__<T extends Record<string, any>>(
mappings: Record<keyof T, string>
) {
return new Proxy(
{} as unknown as {
[K in keyof T]: __EventObj__<T[K]> & {
(handle: __WebviewWindow__): __EventObj__<T[K]>;
};
},
{
get: (_, event) => {
const name = mappings[event as keyof T];
return new Proxy((() => {}) as any, {
apply: (_, __, [window]: [__WebviewWindow__]) => ({
listen: (arg: any) => window.listen(name, arg),
once: (arg: any) => window.once(name, arg),
emit: (arg: any) => window.emit(name, arg),
}),
get: (_, command: keyof __EventObj__<any>) => {
switch (command) {
case "listen":
return (arg: any) => TAURI_API_EVENT.listen(name, arg);
case "once":
return (arg: any) => TAURI_API_EVENT.once(name, arg);
case "emit":
return (arg: any) => TAURI_API_EVENT.emit(name, arg);
}
},
});
},
}
);
}