Skip to content

Commit 111e9ed

Browse files
Merge pull request #379 from DhanishMecha/feat/running-apps-merge
feat: Running apps api integration
2 parents fdf8812 + 28ab60f commit 111e9ed

File tree

17 files changed

+1908
-680
lines changed

17 files changed

+1908
-680
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ networkmanager = { path = "dbus/freedesktop/networkmanager" }
4747
bluez = { path = "dbus/freedesktop/bluez" }
4848
upower = { path = "dbus/freedesktop/upower" }
4949
pulseaudio = { path = "dbus/freedesktop/pulseaudio" }
50+
tracing = "0.1.41"
51+
tracing-subscriber = { version = "0.3.20", features = [ "env-filter" ] }

shell/crates/running_apps/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,14 @@ keywords.workspace = true
1414
gpui = { workspace = true }
1515
rust-embed = { workspace = true }
1616
anyhow = { workspace = true }
17+
serde = { workspace = true }
1718
commons = { path = "../commons" }
19+
tokio = { workspace = true }
20+
futures = { workspace = true }
21+
notify = { workspace = true }
22+
tracing = { workspace = true }
23+
tracing-subscriber = { workspace = true }
24+
wayland-protocols-async = { git = "https://github.com/mecha-org/wayland-protocols-async.git", rev = "0c2c8f6ab9d944e24fdff89f08fd8fe6a67eb6d3" }
25+
indexmap = "2.1.0"
26+
lazy_static = "1.5.0"
27+
xdg = "2.4.1"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod constants;
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
mod ui;
2-
2+
pub mod config;
3+
pub mod models;
4+
pub mod services;
35
pub mod prelude {
4-
pub use crate::ui::RunningApps;
6+
// pub use crate::ui::*;
7+
pub use crate::config::*;
8+
pub use crate::services::*;
9+
pub use crate::models::*;
510
}
Lines changed: 112 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,122 @@
11
use commons::prelude::*;
22
use gpui::prelude::*;
33
use gpui::*;
4-
use running_apps::prelude::*;
4+
use running_apps::models::models::{ AppCard, RunningApps };
5+
use running_apps::prelude::app_manager::{ AppManagerService, AppMessage };
6+
use tokio::sync::mpsc;
7+
use tracing::{ error, info };
8+
use tracing_subscriber::EnvFilter;
59

610
fn main() {
11+
tracing_subscriber
12+
::fmt()
13+
.with_env_filter(EnvFilter::from_default_env()) // reads RUST_LOG
14+
.init();
15+
716
let application = gpui::Application::new().with_assets(Assets {});
817
application.run(|cx| {
9-
let window_bounds =
10-
WindowBounds::Windowed(Bounds::centered(None, size(px(540.0), px(620.0)), cx));
11-
12-
cx.open_window(
13-
WindowOptions {
14-
window_bounds: Some(window_bounds),
15-
..Default::default()
16-
},
17-
|_window, cx| cx.new(|_cx| RunningApps::new()),
18-
)
19-
.unwrap();
18+
let window_bounds = WindowBounds::Windowed(
19+
Bounds::centered(None, size(px(540.0), px(620.0)), cx)
20+
);
21+
22+
let (message_tx, message_rx) = mpsc::channel(120);
23+
let (app_channel_tx, mut app_channel_rx) = mpsc::channel(120);
24+
25+
let running_apps_handle = cx
26+
.open_window(
27+
WindowOptions {
28+
window_bounds: Some(window_bounds),
29+
..Default::default()
30+
},
31+
|_window, cx| cx.new(|_cx| RunningApps::new(message_tx))
32+
)
33+
.unwrap();
34+
35+
cx.background_executor()
36+
.spawn(async move {
37+
tokio::runtime::Builder
38+
::new_multi_thread()
39+
.enable_all()
40+
.build()
41+
.unwrap()
42+
.block_on(async {
43+
let mut app_manager = AppManagerService::new();
44+
app_manager.run(message_rx, app_channel_tx).await;
45+
});
46+
})
47+
.detach();
48+
49+
cx.spawn(async move |cx| {
50+
info!("📬 Message receiver task started");
51+
let rhandle = running_apps_handle;
52+
53+
loop {
54+
match app_channel_rx.recv().await {
55+
Some(message) => {
56+
if
57+
let AppMessage::AppsUpdated {
58+
apps,
59+
app_id: _,
60+
active_apps_count: _,
61+
} = message
62+
{
63+
let apps_clone = apps.clone();
64+
let mut latest_apps: Vec<AppCard> = Vec::new();
65+
66+
for (i, app) in apps_clone.iter().enumerate() {
67+
latest_apps.push(AppCard {
68+
id: i,
69+
app_id: app.app_id.clone(),
70+
offset_y: px(0.0),
71+
target_offset_y: px(0.0),
72+
app_name: app.name.clone(),
73+
app_icon_path: app.icon_path.clone(),
74+
});
75+
}
76+
77+
let new_apps_count = latest_apps.len();
78+
79+
let _ = rhandle.update(
80+
cx,
81+
|this: &mut RunningApps, _, cx: &mut Context<'_, RunningApps>| {
82+
let old_apps_count = this.apps.len();
83+
84+
this.apps = latest_apps;
85+
86+
// Only recalculate scroll if the number of apps changed
87+
if old_apps_count != new_apps_count {
88+
let last_index = if this.apps.is_empty() {
89+
0
90+
} else {
91+
this.apps.len() - 1
92+
};
93+
let initial_offset =
94+
this.calculate_center_offset(last_index);
95+
96+
this.scroll_offset = initial_offset;
97+
this.target_scroll_offset = initial_offset;
98+
this.current_center_index = last_index;
99+
100+
// Reset animation/drag states
101+
this.is_animating = false;
102+
this.is_dragging = false;
103+
}
104+
// If count is the same, preserve current scroll position
105+
// (scroll_offset, target_scroll_offset, current_center_index remain unchanged)
106+
107+
cx.notify();
108+
}
109+
);
110+
}
111+
}
112+
None => {
113+
error!("❌ app_channel closed, exiting loop");
114+
break;
115+
}
116+
}
117+
}
118+
}).detach();
119+
20120
cx.activate(true);
21121
});
22122
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod models;

shell/crates/running_apps/src/ui/models.rs renamed to shell/crates/running_apps/src/models/models.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
use crate::ui::icon::IconName;
21
use gpui::*;
2+
use tokio::sync::mpsc;
3+
4+
use crate::prelude::app_manager::AppManagerMessage;
5+
36
pub struct RunningApps {
47
pub scroll_offset: Pixels,
58
pub is_dragging: bool,
@@ -14,11 +17,12 @@ pub struct RunningApps {
1417
pub is_removing: bool,
1518
pub removing_card_id: Option<usize>,
1619
pub current_center_index: usize,
17-
pub is_cleaning_up: bool, // Flag for clean up animation
20+
pub is_cleaning_up: bool,
1821
pub position: f32,
1922
pub bar_drag_offset: f32,
2023
pub bar_drag_start_y: Option<f32>,
2124
pub show_apps: bool,
25+
pub message_tx: mpsc::Sender<AppManagerMessage>,
2226
}
2327

2428
#[derive(Clone, Copy, PartialEq)]
@@ -30,8 +34,9 @@ pub enum DragDirection {
3034
#[derive(Clone)]
3135
pub struct AppCard {
3236
pub id: usize,
37+
pub app_id: String,
3338
pub offset_y: Pixels,
3439
pub target_offset_y: Pixels,
35-
pub app_name: String,
36-
pub app_icon_path: IconName,
40+
pub app_name: Option<String>,
41+
pub app_icon_path: Option<String>,
3742
}

0 commit comments

Comments
 (0)