From: Olaf Wintermann Date: Mon, 11 May 2026 19:25:45 +0000 (+0200) Subject: add function for calling the main thread X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=443dc8a44ca5983494ec8d211a31d967a3d1d38a;p=note.git add function for calling the main thread --- diff --git a/application/src/backend.rs b/application/src/backend.rs index 7691741..19c3d61 100644 --- a/application/src/backend.rs +++ b/application/src/backend.rs @@ -5,7 +5,7 @@ use migration::{Migrator, MigratorTrait}; use ui_rs::ui; use entity::profile; -use entity::profile::Entity as UserSettings; +use entity::profile::Entity as Profile; pub struct Backend { rt: Arc, @@ -59,7 +59,7 @@ impl Backend { // If a profile id was specified, we are trying to use that, // but if it doesn't exist, an error is returned if let Some(id) = profile_id { - if let Some(model) = UserSettings::find_by_id(id) + if let Some(model) = Profile::find_by_id(id) .one(&self.db) .await? { @@ -71,7 +71,7 @@ impl Backend { } // Try to find a profile for the specified host/user - if let Some(model) = UserSettings::find() + if let Some(model) = Profile::find() .filter(profile::Column::Host.eq(host.clone())) .filter(profile::Column::User.eq(user.clone())) .one(&self.db) diff --git a/ui-rs/src/ui/ffi.rs b/ui-rs/src/ui/ffi.rs index 58fbd2d..baae610 100644 --- a/ui-rs/src/ui/ffi.rs +++ b/ui-rs/src/ui/ffi.rs @@ -28,7 +28,7 @@ #![allow(dead_code)] -use std::ffi::c_void; +use std::ffi::{c_int, c_void}; #[repr(C)] @@ -96,6 +96,9 @@ pub struct UiMenuBuilder { } pub type UiCallback = Option; + +pub type UiThreadFunc = extern "C" fn(data: *mut c_void) -> c_int; + pub type UiDestructor = extern "C" fn(object: *mut c_void); diff --git a/ui-rs/src/ui/toolkit.rs b/ui-rs/src/ui/toolkit.rs index 3330b39..38ff894 100644 --- a/ui-rs/src/ui/toolkit.rs +++ b/ui-rs/src/ui/toolkit.rs @@ -33,7 +33,7 @@ use crate::ui::{action_event_wrapper, event, ffi, ui_object_get_context, ui_obje use std::marker::PhantomData; use std::mem; -use crate::ui::ffi::UiCallback; +use crate::ui::ffi::{UiCallback, UiThreadFunc}; pub struct UiContext { pub ptr: *mut ffi::UiContext @@ -701,6 +701,26 @@ pub fn app_set_configdir(path: &str) { } } +pub fn call_mainthread(f: F) +where F: FnOnce() { + let b = Box::new(f); + let ptr = Box::into_raw(b); + unsafe { + ui_call_mainthread(mainthread_callback::, ptr as *mut c_void); + } +} + +extern "C" fn mainthread_callback(data: *mut c_void) -> c_int +where F: FnOnce() { + unsafe { + // Reconstruct the Box + let callback: Box = Box::from_raw(data as *mut F); + + (*callback)(); + } + + 0 +} /* -------------------------------- C functions -------------------------------- */ @@ -710,6 +730,7 @@ extern "C" { fn ui_getappdir() -> *mut c_char; fn ui_setappdir(path: *const c_char); fn ui_configfile(name: *const c_char) -> *mut c_char; + pub fn ui_call_mainthread(func: UiThreadFunc, data: *mut c_void); fn ui_document_new(size: usize) -> *mut c_void; fn ui_document_ref(doc: *mut c_void);