]> uap-core.de Git - note.git/commitdiff
add function for calling the main thread
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 11 May 2026 19:25:45 +0000 (21:25 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Mon, 11 May 2026 19:25:45 +0000 (21:25 +0200)
application/src/backend.rs
ui-rs/src/ui/ffi.rs
ui-rs/src/ui/toolkit.rs

index 7691741cd4ec3fdc07da86266bfbe97c6cfa1b84..19c3d61e9ffad274dcbb0f6adfadf05777dab5d2 100644 (file)
@@ -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<Runtime>,
@@ -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)
index 58fbd2d2557b461ef71188f9cc7e9a2c01581bd8..baae61064859e96029d7b27059a0b44ce12895e2 100644 (file)
@@ -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<extern "C" fn(event: *const UiEvent, *mut c_void)>;
+
+pub type UiThreadFunc = extern "C" fn(data: *mut c_void) -> c_int;
+
 pub type UiDestructor = extern "C" fn(object: *mut c_void);
 
 
index 3330b39a7bf4da8714717f40eea447fa45225b4b..38ff894bfc970509421173d1a0502fc20bf350da 100644 (file)
@@ -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: F)
+where F: FnOnce() {
+    let b = Box::new(f);
+    let ptr = Box::into_raw(b);
+    unsafe {
+        ui_call_mainthread(mainthread_callback::<F>, ptr as *mut c_void);
+    }
+}
+
+extern "C" fn mainthread_callback<F>(data: *mut c_void) -> c_int
+where F: FnOnce() {
+    unsafe {
+        // Reconstruct the Box<F>
+        let callback: Box<F> = 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);