generics + DashInterface impl (#334)
This commit is contained in:
@@ -38,12 +38,12 @@ pub struct FrontendWidgets {
|
||||
|
||||
pub type FrontendTasks = Tasks<FrontendTask>;
|
||||
|
||||
pub struct Frontend {
|
||||
pub struct Frontend<T> {
|
||||
pub layout: Layout,
|
||||
globals: WguiGlobals,
|
||||
|
||||
pub settings: Box<dyn settings::SettingsIO>,
|
||||
pub interface: BoxDashInterface,
|
||||
pub interface: BoxDashInterface<T>,
|
||||
|
||||
// async runtime executor
|
||||
pub executor: AsyncExecutor,
|
||||
@@ -51,7 +51,7 @@ pub struct Frontend {
|
||||
#[allow(dead_code)]
|
||||
state: ParserState,
|
||||
|
||||
current_tab: Option<Box<dyn Tab>>,
|
||||
current_tab: Option<Box<dyn Tab<T>>>,
|
||||
|
||||
pub tasks: FrontendTasks,
|
||||
|
||||
@@ -68,9 +68,9 @@ pub struct Frontend {
|
||||
pub(crate) desktop_finder: DesktopFinder,
|
||||
}
|
||||
|
||||
pub struct InitParams {
|
||||
pub struct InitParams<T> {
|
||||
pub settings: Box<dyn settings::SettingsIO>,
|
||||
pub interface: BoxDashInterface,
|
||||
pub interface: BoxDashInterface<T>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -86,8 +86,8 @@ pub enum FrontendTask {
|
||||
PushToast(Translation),
|
||||
}
|
||||
|
||||
impl Frontend {
|
||||
pub fn new(params: InitParams) -> anyhow::Result<Frontend> {
|
||||
impl<T: 'static> Frontend<T> {
|
||||
pub fn new(params: InitParams<T>) -> anyhow::Result<Frontend<T>> {
|
||||
let mut assets = Box::new(assets::Asset {});
|
||||
|
||||
let font_binary_bold = assets.load_from_path_gzip("Quicksand-Bold.ttf.gz")?;
|
||||
@@ -164,15 +164,15 @@ impl Frontend {
|
||||
Ok(frontend)
|
||||
}
|
||||
|
||||
pub fn update(&mut self, width: f32, height: f32, timestep_alpha: f32) -> anyhow::Result<()> {
|
||||
pub fn update(&mut self, data: &mut T, width: f32, height: f32, timestep_alpha: f32) -> anyhow::Result<()> {
|
||||
let mut tasks = self.tasks.drain();
|
||||
|
||||
while let Some(task) = tasks.pop_front() {
|
||||
self.process_task(task)?;
|
||||
self.process_task(data, task)?;
|
||||
}
|
||||
|
||||
if let Some(mut tab) = self.current_tab.take() {
|
||||
tab.update(self)?;
|
||||
tab.update(self, data)?;
|
||||
|
||||
self.current_tab = Some(tab);
|
||||
}
|
||||
@@ -237,7 +237,6 @@ impl Frontend {
|
||||
self.globals.clone(),
|
||||
self.settings.as_ref(),
|
||||
&mut self.layout,
|
||||
&mut self.interface,
|
||||
self.tasks.clone(),
|
||||
params,
|
||||
)?;
|
||||
@@ -273,7 +272,7 @@ impl Frontend {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn process_task(&mut self, task: FrontendTask) -> anyhow::Result<()> {
|
||||
fn process_task(&mut self, data: &mut T, task: FrontendTask) -> anyhow::Result<()> {
|
||||
match task {
|
||||
FrontendTask::SetTab(tab_type) => self.set_tab(tab_type)?,
|
||||
FrontendTask::RefreshClock => self.update_time()?,
|
||||
@@ -282,7 +281,7 @@ impl Frontend {
|
||||
FrontendTask::RefreshPopupManager => self.refresh_popup_manager()?,
|
||||
FrontendTask::ShowAudioSettings => self.action_show_audio_settings()?,
|
||||
FrontendTask::UpdateAudioSettingsView => self.action_update_audio_settings()?,
|
||||
FrontendTask::RecenterPlayspace => self.action_recenter_playspace()?,
|
||||
FrontendTask::RecenterPlayspace => self.action_recenter_playspace(data)?,
|
||||
FrontendTask::PushToast(content) => self.toast_manager.push(content),
|
||||
};
|
||||
Ok(())
|
||||
@@ -293,7 +292,7 @@ impl Frontend {
|
||||
let widget_content = self.state.fetch_widget(&self.layout.state, "content")?;
|
||||
self.layout.remove_children(widget_content.id);
|
||||
|
||||
let tab: Box<dyn Tab> = match tab_type {
|
||||
let tab: Box<dyn Tab<T>> = match tab_type {
|
||||
TabType::Home => Box::new(TabHome::new(self, widget_content.id)?),
|
||||
TabType::Apps => Box::new(TabApps::new(self, widget_content.id)?),
|
||||
TabType::Games => Box::new(TabGames::new(self, widget_content.id)?),
|
||||
@@ -407,8 +406,8 @@ impl Frontend {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn action_recenter_playspace(&mut self) -> anyhow::Result<()> {
|
||||
self.interface.recenter_playspace()?;
|
||||
fn action_recenter_playspace(&mut self, data: &mut T) -> anyhow::Result<()> {
|
||||
self.interface.recenter_playspace(data)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{cell::RefCell, collections::HashMap, rc::Rc};
|
||||
use std::{cell::RefCell, collections::HashMap, marker::PhantomData, rc::Rc};
|
||||
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
@@ -28,7 +28,7 @@ struct State {
|
||||
view_launcher: Option<(PopupHandle, views::app_launcher::View)>,
|
||||
}
|
||||
|
||||
pub struct TabApps {
|
||||
pub struct TabApps<T> {
|
||||
#[allow(dead_code)]
|
||||
parser_state: ParserState,
|
||||
|
||||
@@ -36,14 +36,15 @@ pub struct TabApps {
|
||||
entries: Vec<DesktopEntry>,
|
||||
app_list: AppList,
|
||||
tasks: Tasks<Task>,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl Tab for TabApps {
|
||||
impl<T> Tab<T> for TabApps<T> {
|
||||
fn get_type(&self) -> TabType {
|
||||
TabType::Apps
|
||||
}
|
||||
|
||||
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
|
||||
fn update(&mut self, frontend: &mut Frontend<T>, data: &mut T) -> anyhow::Result<()> {
|
||||
let mut state = self.state.borrow_mut();
|
||||
|
||||
for task in self.tasks.drain() {
|
||||
@@ -53,7 +54,7 @@ impl Tab for TabApps {
|
||||
}
|
||||
|
||||
if let Some((_, launcher)) = &mut state.view_launcher {
|
||||
launcher.update(&mut frontend.layout, &mut frontend.interface)?;
|
||||
launcher.update(&mut frontend.layout, &mut frontend.interface, data)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -108,8 +109,8 @@ fn on_app_click(
|
||||
})
|
||||
}
|
||||
|
||||
impl TabApps {
|
||||
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
impl<T> TabApps<T> {
|
||||
pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
let doc_params = &ParseDocumentParams {
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
path: AssetPath::BuiltIn("gui/tab/apps.xml"),
|
||||
@@ -151,14 +152,15 @@ impl TabApps {
|
||||
entries,
|
||||
state,
|
||||
tasks,
|
||||
marker: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl AppList {
|
||||
fn mount_entry(
|
||||
fn mount_entry<T>(
|
||||
&mut self,
|
||||
frontend: &mut Frontend,
|
||||
frontend: &mut Frontend<T>,
|
||||
parser_state: &mut ParserState,
|
||||
doc_params: &ParseDocumentParams,
|
||||
list_parent: &WidgetPair,
|
||||
@@ -197,9 +199,9 @@ impl AppList {
|
||||
data.fetch_component_as::<ComponentButton>("button")
|
||||
}
|
||||
|
||||
fn mount_entries(
|
||||
fn mount_entries<T>(
|
||||
&mut self,
|
||||
frontend: &mut Frontend,
|
||||
frontend: &mut Frontend<T>,
|
||||
entries: &[DesktopEntry],
|
||||
parser_state: &mut ParserState,
|
||||
doc_params: &ParseDocumentParams,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
layout::WidgetID,
|
||||
@@ -10,26 +12,27 @@ use crate::{
|
||||
views::game_list,
|
||||
};
|
||||
|
||||
pub struct TabGames {
|
||||
pub struct TabGames<T> {
|
||||
#[allow(dead_code)]
|
||||
pub state: ParserState,
|
||||
|
||||
view_game_list: game_list::View,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl Tab for TabGames {
|
||||
impl<T> Tab<T> for TabGames<T> {
|
||||
fn get_type(&self) -> TabType {
|
||||
TabType::Games
|
||||
}
|
||||
|
||||
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
|
||||
fn update(&mut self, frontend: &mut Frontend<T>, _data: &mut T) -> anyhow::Result<()> {
|
||||
self.view_game_list.update(&mut frontend.layout, &frontend.executor)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TabGames {
|
||||
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
impl<T> TabGames<T> {
|
||||
pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
let state = wgui::parser::parse_from_assets(
|
||||
&ParseDocumentParams {
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
@@ -50,6 +53,10 @@ impl TabGames {
|
||||
parent_id: game_list_parent,
|
||||
})?;
|
||||
|
||||
Ok(Self { state, view_game_list })
|
||||
Ok(Self {
|
||||
state,
|
||||
view_game_list,
|
||||
marker: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
components::button::ComponentButton,
|
||||
@@ -15,12 +17,13 @@ use crate::{
|
||||
various,
|
||||
};
|
||||
|
||||
pub struct TabHome {
|
||||
pub struct TabHome<T> {
|
||||
#[allow(dead_code)]
|
||||
pub state: ParserState,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl Tab for TabHome {
|
||||
impl<T> Tab<T> for TabHome<T> {
|
||||
fn get_type(&self) -> TabType {
|
||||
TabType::Home
|
||||
}
|
||||
@@ -44,8 +47,8 @@ fn configure_label_hello(common: &mut CallbackDataCommon, label_hello: Widget, s
|
||||
label_hello.set_text(common, Translation::from_raw_text(&translated));
|
||||
}
|
||||
|
||||
impl TabHome {
|
||||
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
impl<T> TabHome<T> {
|
||||
pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
let state = wgui::parser::parse_from_assets(
|
||||
&ParseDocumentParams {
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
@@ -73,6 +76,9 @@ impl TabHome {
|
||||
tasks.handle_button(&btn_processes, FrontendTask::SetTab(TabType::Processes));
|
||||
tasks.handle_button(&btn_settings, FrontendTask::SetTab(TabType::Settings));
|
||||
|
||||
Ok(Self { state })
|
||||
Ok(Self {
|
||||
state,
|
||||
marker: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ pub enum TabType {
|
||||
Settings,
|
||||
}
|
||||
|
||||
pub trait Tab {
|
||||
pub trait Tab<T> {
|
||||
#[allow(dead_code)]
|
||||
fn get_type(&self) -> TabType;
|
||||
|
||||
fn update(&mut self, _: &mut Frontend) -> anyhow::Result<()> {
|
||||
fn update(&mut self, _: &mut Frontend<T>, _: &mut T) -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
layout::WidgetID,
|
||||
@@ -9,19 +11,20 @@ use crate::{
|
||||
tab::{Tab, TabType},
|
||||
};
|
||||
|
||||
pub struct TabMonado {
|
||||
pub struct TabMonado<T> {
|
||||
#[allow(dead_code)]
|
||||
pub state: ParserState,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl Tab for TabMonado {
|
||||
impl<T> Tab<T> for TabMonado<T> {
|
||||
fn get_type(&self) -> TabType {
|
||||
TabType::Games
|
||||
}
|
||||
}
|
||||
|
||||
impl TabMonado {
|
||||
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
impl<T> TabMonado<T> {
|
||||
pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
let state = wgui::parser::parse_from_assets(
|
||||
&ParseDocumentParams {
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
@@ -32,6 +35,9 @@ impl TabMonado {
|
||||
parent_id,
|
||||
)?;
|
||||
|
||||
Ok(Self { state })
|
||||
Ok(Self {
|
||||
state,
|
||||
marker: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::marker::PhantomData;
|
||||
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
layout::WidgetID,
|
||||
@@ -10,32 +12,33 @@ use crate::{
|
||||
views::{process_list, window_list},
|
||||
};
|
||||
|
||||
pub struct TabProcesses {
|
||||
pub struct TabProcesses<T> {
|
||||
#[allow(dead_code)]
|
||||
pub state: ParserState,
|
||||
|
||||
view_window_list: window_list::View,
|
||||
view_process_list: process_list::View,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl Tab for TabProcesses {
|
||||
impl<T> Tab<T> for TabProcesses<T> {
|
||||
fn get_type(&self) -> TabType {
|
||||
TabType::Games
|
||||
}
|
||||
|
||||
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
|
||||
fn update(&mut self, frontend: &mut Frontend<T>, data: &mut T) -> anyhow::Result<()> {
|
||||
self
|
||||
.view_window_list
|
||||
.update(&mut frontend.layout, &mut frontend.interface)?;
|
||||
.update(&mut frontend.layout, &mut frontend.interface, data)?;
|
||||
self
|
||||
.view_process_list
|
||||
.update(&mut frontend.layout, &mut frontend.interface)?;
|
||||
.update(&mut frontend.layout, &mut frontend.interface, data)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl TabProcesses {
|
||||
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
impl<T> TabProcesses<T> {
|
||||
pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
let globals = frontend.layout.state.globals.clone();
|
||||
let state = wgui::parser::parse_from_assets(
|
||||
&ParseDocumentParams {
|
||||
@@ -61,6 +64,7 @@ impl TabProcesses {
|
||||
globals,
|
||||
})?,
|
||||
state,
|
||||
marker: PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::rc::Rc;
|
||||
use std::{marker::PhantomData, rc::Rc};
|
||||
|
||||
use wgui::{
|
||||
assets::AssetPath,
|
||||
@@ -18,19 +18,20 @@ enum Task {
|
||||
ToggleSetting(SettingType, bool),
|
||||
}
|
||||
|
||||
pub struct TabSettings {
|
||||
pub struct TabSettings<T> {
|
||||
#[allow(dead_code)]
|
||||
pub state: ParserState,
|
||||
|
||||
tasks: Tasks<Task>,
|
||||
marker: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl Tab for TabSettings {
|
||||
impl<T> Tab<T> for TabSettings<T> {
|
||||
fn get_type(&self) -> TabType {
|
||||
TabType::Settings
|
||||
}
|
||||
|
||||
fn update(&mut self, frontend: &mut Frontend) -> anyhow::Result<()> {
|
||||
fn update(&mut self, frontend: &mut Frontend<T>, _data: &mut T) -> anyhow::Result<()> {
|
||||
for task in self.tasks.drain() {
|
||||
match task {
|
||||
Task::ToggleSetting(setting, n) => self.toggle_setting(frontend, setting, n),
|
||||
@@ -60,8 +61,8 @@ impl SettingType {
|
||||
}
|
||||
}
|
||||
|
||||
fn init_setting_checkbox(
|
||||
frontend: &mut Frontend,
|
||||
fn init_setting_checkbox<T>(
|
||||
frontend: &mut Frontend<T>,
|
||||
tasks: &Tasks<Task>,
|
||||
checkbox: Rc<ComponentCheckbox>,
|
||||
setting: SettingType,
|
||||
@@ -86,8 +87,8 @@ fn init_setting_checkbox(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl TabSettings {
|
||||
pub fn new(frontend: &mut Frontend, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
impl<T> TabSettings<T> {
|
||||
pub fn new(frontend: &mut Frontend<T>, parent_id: WidgetID) -> anyhow::Result<Self> {
|
||||
let state = wgui::parser::parse_from_assets(
|
||||
&ParseDocumentParams {
|
||||
globals: frontend.layout.state.globals.clone(),
|
||||
@@ -136,10 +137,14 @@ impl TabSettings {
|
||||
None,
|
||||
)?;
|
||||
|
||||
Ok(Self { state, tasks })
|
||||
Ok(Self {
|
||||
state,
|
||||
tasks,
|
||||
marker: PhantomData,
|
||||
})
|
||||
}
|
||||
|
||||
fn toggle_setting(&mut self, frontend: &mut Frontend, setting: SettingType, state: bool) {
|
||||
fn toggle_setting(&mut self, frontend: &mut Frontend<T>, setting: SettingType, state: bool) {
|
||||
*setting.get_bool(frontend.settings.get_mut()) = state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ use wgui::{
|
||||
taffy::Display,
|
||||
widget::label::WidgetLabel,
|
||||
};
|
||||
use wlx_common::dash_interface::BoxDashInterface;
|
||||
|
||||
use crate::{
|
||||
frontend::{FrontendTask, FrontendTasks},
|
||||
@@ -61,7 +60,6 @@ pub struct PopupContentFuncData<'a> {
|
||||
pub layout: &'a mut Layout,
|
||||
pub settings: &'a dyn SettingsIO,
|
||||
pub handle: PopupHandle,
|
||||
pub interface: &'a mut BoxDashInterface,
|
||||
pub id_content: WidgetID,
|
||||
}
|
||||
|
||||
@@ -127,7 +125,6 @@ impl PopupManager {
|
||||
globals: WguiGlobals,
|
||||
settings: &dyn SettingsIO,
|
||||
layout: &mut Layout,
|
||||
interface: &mut BoxDashInterface,
|
||||
frontend_tasks: FrontendTasks,
|
||||
params: MountPopupParams,
|
||||
) -> anyhow::Result<()> {
|
||||
@@ -184,7 +181,6 @@ impl PopupManager {
|
||||
handle: popup_handle.clone(),
|
||||
id_content,
|
||||
settings,
|
||||
interface,
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -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