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>,
// 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?
{
}
// 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)
#![allow(dead_code)]
-use std::ffi::c_void;
+use std::ffi::{c_int, c_void};
#[repr(C)]
}
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);
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
}
}
+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 -------------------------------- */
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);