generics + DashInterface impl (#334)
This commit is contained in:
@@ -31,12 +31,13 @@ enum Task {
|
||||
Launch,
|
||||
}
|
||||
|
||||
struct LaunchParams<'a> {
|
||||
struct LaunchParams<'a, T> {
|
||||
application: &'a DesktopEntry,
|
||||
run_mode: RunMode,
|
||||
globals: &'a WguiGlobals,
|
||||
frontend_tasks: &'a FrontendTasks,
|
||||
interface: &'a mut BoxDashInterface,
|
||||
interface: &'a mut BoxDashInterface<T>,
|
||||
data: &'a mut T,
|
||||
on_launched: &'a dyn Fn(),
|
||||
}
|
||||
|
||||
@@ -157,7 +158,12 @@ impl View {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update(&mut self, layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> {
|
||||
pub fn update<T>(
|
||||
&mut self,
|
||||
layout: &mut Layout,
|
||||
interface: &mut BoxDashInterface<T>,
|
||||
data: &mut T,
|
||||
) -> anyhow::Result<()> {
|
||||
loop {
|
||||
let tasks = self.tasks.drain();
|
||||
if tasks.is_empty() {
|
||||
@@ -166,7 +172,7 @@ impl View {
|
||||
for task in tasks {
|
||||
match task {
|
||||
Task::SetRunMode(run_mode) => self.action_set_run_mode(layout, run_mode)?,
|
||||
Task::Launch => self.action_launch(interface),
|
||||
Task::Launch => self.action_launch(interface, data),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,18 +194,19 @@ impl View {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_launch(&mut self, interface: &mut BoxDashInterface) {
|
||||
fn action_launch<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T) {
|
||||
View::try_launch(LaunchParams {
|
||||
application: &self.entry,
|
||||
frontend_tasks: &self.frontend_tasks,
|
||||
globals: &self.globals,
|
||||
run_mode: self.run_mode.clone(),
|
||||
interface,
|
||||
data,
|
||||
on_launched: &self.on_launched,
|
||||
});
|
||||
}
|
||||
|
||||
fn try_launch(params: LaunchParams) {
|
||||
fn try_launch<T>(params: LaunchParams<T>) {
|
||||
let globals = params.globals.clone();
|
||||
let frontend_tasks = params.frontend_tasks.clone();
|
||||
|
||||
@@ -213,7 +220,7 @@ impl View {
|
||||
))));
|
||||
}
|
||||
|
||||
fn launch(params: LaunchParams) -> anyhow::Result<()> {
|
||||
fn launch<T>(params: LaunchParams<T>) -> anyhow::Result<()> {
|
||||
let mut env = Vec::<String>::new();
|
||||
|
||||
if params.run_mode == RunMode::Wayland {
|
||||
@@ -238,13 +245,16 @@ impl View {
|
||||
let mut userdata = HashMap::new();
|
||||
userdata.insert("desktop-entry".to_string(), serde_json::to_string(params.application)?);
|
||||
|
||||
params.interface.process_launch(WvrProcessLaunchParams {
|
||||
env,
|
||||
exec,
|
||||
name: params.application.app_name.to_string(),
|
||||
args,
|
||||
userdata,
|
||||
})?;
|
||||
params.interface.process_launch(
|
||||
params.data,
|
||||
WvrProcessLaunchParams {
|
||||
env,
|
||||
exec,
|
||||
name: params.application.app_name.to_string(),
|
||||
args,
|
||||
userdata,
|
||||
},
|
||||
)?;
|
||||
|
||||
params
|
||||
.frontend_tasks
|
||||
|
||||
@@ -71,7 +71,12 @@ impl View {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update(&mut self, layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> {
|
||||
pub fn update<T>(
|
||||
&mut self,
|
||||
layout: &mut Layout,
|
||||
interface: &mut BoxDashInterface<T>,
|
||||
data: &mut T,
|
||||
) -> anyhow::Result<()> {
|
||||
loop {
|
||||
let tasks = self.tasks.drain();
|
||||
if tasks.is_empty() {
|
||||
@@ -79,8 +84,8 @@ impl View {
|
||||
}
|
||||
for task in tasks {
|
||||
match task {
|
||||
Task::Refresh => self.refresh(layout, interface)?,
|
||||
Task::TerminateProcess(process) => self.action_terminate_process(interface, process)?,
|
||||
Task::Refresh => self.refresh(layout, interface, data)?,
|
||||
Task::TerminateProcess(process) => self.action_terminate_process(interface, data, process)?,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,11 +201,16 @@ fn fill_process_list(
|
||||
}
|
||||
|
||||
impl View {
|
||||
fn refresh(&mut self, layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> {
|
||||
fn refresh<T>(
|
||||
&mut self,
|
||||
layout: &mut Layout,
|
||||
interface: &mut BoxDashInterface<T>,
|
||||
data: &mut T,
|
||||
) -> anyhow::Result<()> {
|
||||
layout.remove_children(self.id_list_parent);
|
||||
|
||||
let mut text: Option<Translation> = None;
|
||||
match interface.process_list() {
|
||||
match interface.process_list(data) {
|
||||
Ok(list) => {
|
||||
if list.is_empty() {
|
||||
text = Some(Translation::from_translation_key("PROCESS_LIST.NO_PROCESSES_FOUND"))
|
||||
@@ -236,12 +246,13 @@ impl View {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_terminate_process(
|
||||
fn action_terminate_process<T>(
|
||||
&mut self,
|
||||
interface: &mut BoxDashInterface,
|
||||
interface: &mut BoxDashInterface<T>,
|
||||
data: &mut T,
|
||||
process: packet_server::WvrProcess,
|
||||
) -> anyhow::Result<()> {
|
||||
interface.process_terminate(process.handle)?;
|
||||
interface.process_terminate(data, process.handle)?;
|
||||
self.tasks.push(Task::Refresh);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ use wgui::{
|
||||
taffy::{self, prelude::length},
|
||||
task::Tasks,
|
||||
widget::{
|
||||
ConstructEssentials,
|
||||
label::{WidgetLabel, WidgetLabelParams},
|
||||
ConstructEssentials,
|
||||
},
|
||||
};
|
||||
use wlx_common::dash_interface::BoxDashInterface;
|
||||
@@ -84,7 +84,12 @@ impl View {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update(&mut self, layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> {
|
||||
pub fn update<T>(
|
||||
&mut self,
|
||||
layout: &mut Layout,
|
||||
interface: &mut BoxDashInterface<T>,
|
||||
data: &mut T,
|
||||
) -> anyhow::Result<()> {
|
||||
loop {
|
||||
let tasks = self.tasks.drain();
|
||||
if tasks.is_empty() {
|
||||
@@ -94,23 +99,24 @@ impl View {
|
||||
match task {
|
||||
Task::WindowClicked(display) => self.action_window_clicked(display)?,
|
||||
Task::WindowOptionsFinish => self.action_window_options_finish(),
|
||||
Task::Refresh => self.refresh(layout, interface)?,
|
||||
Task::Refresh => self.refresh(layout, interface, data)?,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut state = self.state.borrow_mut();
|
||||
if let Some((_, view)) = &mut state.view_window_options {
|
||||
view.update(layout, interface)?;
|
||||
view.update(layout, interface, data)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn construct_window_button(
|
||||
pub fn construct_window_button<T>(
|
||||
ess: &mut ConstructEssentials,
|
||||
interface: &mut BoxDashInterface,
|
||||
interface: &mut BoxDashInterface<T>,
|
||||
data: &mut T,
|
||||
globals: &WguiGlobals,
|
||||
window: &packet_server::WvrWindow,
|
||||
) -> anyhow::Result<(WidgetPair, Rc<ComponentButton>)> {
|
||||
@@ -137,7 +143,7 @@ pub fn construct_window_button(
|
||||
},
|
||||
)?;
|
||||
|
||||
let process_name = match interface.process_get(window.process_handle.clone()) {
|
||||
let process_name = match interface.process_get(data, window.process_handle.clone()) {
|
||||
Some(process) => process.name.clone(),
|
||||
None => String::from("Unknown"),
|
||||
};
|
||||
@@ -171,15 +177,16 @@ pub fn construct_window_button(
|
||||
Ok((widget_button, button))
|
||||
}
|
||||
|
||||
fn fill_window_list(
|
||||
fn fill_window_list<T>(
|
||||
globals: &WguiGlobals,
|
||||
ess: &mut ConstructEssentials,
|
||||
interface: &mut BoxDashInterface,
|
||||
interface: &mut BoxDashInterface<T>,
|
||||
data: &mut T,
|
||||
list: Vec<packet_server::WvrWindow>,
|
||||
tasks: &Tasks<Task>,
|
||||
) -> anyhow::Result<()> {
|
||||
for entry in list {
|
||||
let (_, button) = construct_window_button(ess, interface, globals, &entry)?;
|
||||
let (_, button) = construct_window_button(ess, interface, data, globals, &entry)?;
|
||||
|
||||
button.on_click({
|
||||
let tasks = tasks.clone();
|
||||
@@ -199,11 +206,16 @@ impl View {
|
||||
self.tasks.push(Task::Refresh);
|
||||
}
|
||||
|
||||
fn refresh(&mut self, layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> {
|
||||
fn refresh<T>(
|
||||
&mut self,
|
||||
layout: &mut Layout,
|
||||
interface: &mut BoxDashInterface<T>,
|
||||
data: &mut T,
|
||||
) -> anyhow::Result<()> {
|
||||
layout.remove_children(self.id_list_parent);
|
||||
|
||||
let mut text: Option<Translation> = None;
|
||||
match interface.window_list() {
|
||||
match interface.window_list(data) {
|
||||
Ok(list) => {
|
||||
if list.is_empty() {
|
||||
text = Some(Translation::from_translation_key("NO_WINDOWS_FOUND"))
|
||||
@@ -215,6 +227,7 @@ impl View {
|
||||
parent: self.id_list_parent,
|
||||
},
|
||||
interface,
|
||||
data,
|
||||
list,
|
||||
&self.tasks,
|
||||
)?
|
||||
@@ -252,19 +265,20 @@ impl View {
|
||||
let state = self.state.clone();
|
||||
let tasks = self.tasks.clone();
|
||||
|
||||
//TODO
|
||||
|
||||
Rc::new(move |data| {
|
||||
state.borrow_mut().view_window_options = Some((
|
||||
data.handle,
|
||||
window_options::View::new(window_options::Params {
|
||||
globals: globals.clone(),
|
||||
layout: data.layout,
|
||||
parent_id: data.id_content,
|
||||
on_submit: tasks.make_callback(Task::WindowOptionsFinish),
|
||||
window: window.clone(),
|
||||
frontend_tasks: frontend_tasks.clone(),
|
||||
interface: data.interface,
|
||||
})?,
|
||||
));
|
||||
// state.borrow_mut().view_window_options = Some((
|
||||
// data.handle,
|
||||
// window_options::View::new(window_options::Params {
|
||||
// globals: globals.clone(),
|
||||
// layout: data.layout,
|
||||
// parent_id: data.id_content,
|
||||
// on_submit: tasks.make_callback(Task::WindowOptionsFinish),
|
||||
// window: window.clone(),
|
||||
// frontend_tasks: frontend_tasks.clone(),
|
||||
// })?,
|
||||
// ));
|
||||
Ok(())
|
||||
})
|
||||
},
|
||||
|
||||
@@ -34,18 +34,19 @@ pub struct View {
|
||||
on_submit: Rc<dyn Fn()>,
|
||||
}
|
||||
|
||||
pub struct Params<'a> {
|
||||
pub struct Params<'a, T> {
|
||||
pub globals: WguiGlobals,
|
||||
pub frontend_tasks: FrontendTasks,
|
||||
pub layout: &'a mut Layout,
|
||||
pub parent_id: WidgetID,
|
||||
pub on_submit: Rc<dyn Fn()>,
|
||||
pub window: packet_server::WvrWindow,
|
||||
pub interface: &'a mut BoxDashInterface,
|
||||
pub interface: &'a mut BoxDashInterface<T>,
|
||||
pub data: &'a mut T,
|
||||
}
|
||||
|
||||
impl View {
|
||||
pub fn new(params: Params) -> anyhow::Result<Self> {
|
||||
pub fn new<T>(params: Params<T>) -> anyhow::Result<Self> {
|
||||
let doc_params = &ParseDocumentParams {
|
||||
globals: params.globals.clone(),
|
||||
path: AssetPath::BuiltIn("gui/view/window_options.xml"),
|
||||
@@ -67,6 +68,7 @@ impl View {
|
||||
parent: window_parent,
|
||||
},
|
||||
params.interface,
|
||||
params.data,
|
||||
¶ms.globals,
|
||||
¶ms.window,
|
||||
)?;
|
||||
@@ -93,12 +95,17 @@ impl View {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update(&mut self, _layout: &mut Layout, interface: &mut BoxDashInterface) -> anyhow::Result<()> {
|
||||
pub fn update<T>(
|
||||
&mut self,
|
||||
_layout: &mut Layout,
|
||||
interface: &mut BoxDashInterface<T>,
|
||||
data: &mut T,
|
||||
) -> anyhow::Result<()> {
|
||||
for task in self.tasks.drain() {
|
||||
match task {
|
||||
Task::SetVisible(v) => self.action_set_visible(interface, v),
|
||||
Task::Close => self.action_close(interface),
|
||||
Task::Kill => self.action_kill(interface),
|
||||
Task::SetVisible(v) => self.action_set_visible(interface, data, v),
|
||||
Task::Close => self.action_close(interface, data),
|
||||
Task::Kill => self.action_kill(interface, data),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -106,8 +113,8 @@ impl View {
|
||||
}
|
||||
|
||||
impl View {
|
||||
fn action_set_visible(&mut self, interface: &mut BoxDashInterface, visible: bool) {
|
||||
if let Err(e) = interface.window_set_visible(self.window.handle.clone(), visible) {
|
||||
fn action_set_visible<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T, visible: bool) {
|
||||
if let Err(e) = interface.window_set_visible(data, self.window.handle.clone(), visible) {
|
||||
self
|
||||
.frontend_tasks
|
||||
.push(FrontendTask::PushToast(Translation::from_raw_text_string(format!(
|
||||
@@ -119,8 +126,8 @@ impl View {
|
||||
(*self.on_submit)();
|
||||
}
|
||||
|
||||
fn action_close(&mut self, interface: &mut BoxDashInterface) {
|
||||
if let Err(e) = interface.window_request_close(self.window.handle.clone()) {
|
||||
fn action_close<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T) {
|
||||
if let Err(e) = interface.window_request_close(data, self.window.handle.clone()) {
|
||||
self
|
||||
.frontend_tasks
|
||||
.push(FrontendTask::PushToast(Translation::from_raw_text_string(format!(
|
||||
@@ -132,16 +139,16 @@ impl View {
|
||||
(*self.on_submit)();
|
||||
}
|
||||
|
||||
fn action_kill_process(&mut self, interface: &mut BoxDashInterface) -> anyhow::Result<()> {
|
||||
fn action_kill_process<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T) -> anyhow::Result<()> {
|
||||
let process = interface
|
||||
.process_get(self.window.process_handle.clone())
|
||||
.process_get(data, self.window.process_handle.clone())
|
||||
.context("Process not found")?;
|
||||
interface.process_terminate(process.handle)?;
|
||||
interface.process_terminate(data, process.handle)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_kill(&mut self, interface: &mut BoxDashInterface) {
|
||||
if let Err(e) = self.action_kill_process(interface) {
|
||||
fn action_kill<T>(&mut self, interface: &mut BoxDashInterface<T>, data: &mut T) {
|
||||
if let Err(e) = self.action_kill_process(interface, data) {
|
||||
self
|
||||
.frontend_tasks
|
||||
.push(FrontendTask::PushToast(Translation::from_raw_text_string(format!(
|
||||
|
||||
Reference in New Issue
Block a user