Skip to content

Commit 8bc384f

Browse files
authored
Merge pull request #117 from pragmatrix/ai-refactor
Split up DesktopSystem
2 parents 45a01f5 + 50bdd47 commit 8bc384f

18 files changed

+1628
-1181
lines changed

.github/copilot-instructions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Update it whenever you learn something new about the project's patterns, convent
1111
- Comment only to explain non-obvious reasoning or intent.
1212
- Order functions high-level first, utilities last; order types by importance (public API first, private helpers last).
1313
- Prefer directory submodules with `mod.rs` over sibling `foo.rs` submodule files when introducing new submodule trees.
14+
- When splitting large modules, extract low-coupling impl blocks first and preserve existing external imports via local re-exports in the parent module.
1415

1516
## Rust
1617
- Prefer `derive_more` traits (Debug, Deref) over manual implementations.
@@ -33,14 +34,17 @@ Update it whenever you learn something new about the project's patterns, convent
3334
- For transient UI indicators (hover/focus highlights), derive visibility/target from current resolved state rather than only from enter/exit edge events.
3435
- For context-specific behavior, prefer targeted follow-up evaluation over broad global rule changes that affect unrelated paths.
3536
- When a generic pass applies fallback state, recompute context-specific state immediately afterward for impacted entities.
37+
- For visual side effects derived from state transitions, prefer computing them in the centralized effects/update phase using previous/current state snapshots instead of duplicating eager updates across input and command paths.
3638
- Keep invariant gating at a single layer where practical; avoid repeating identical mode/eligibility checks across caller and callee.
39+
- When an operation must not emit follow-up commands, model it as `Result<()>` and enforce the invariant at the forwarding boundary.
3740
- For internal invariant violations, prefer explicit panics over silent fallback/continue paths.
3841
- When code guarantees an invariant, avoid defensive fallback branches for that path; keep the direct path and fail explicitly if the invariant is violated.
3942
- For purely defensive invariant checks on hot paths, prefer debug-only assertions to avoid unnecessary release-build work.
4043
- For platform-specific window commands, detect shortcuts where aggregated input state is available and keep the actual window mutation in the shell/window abstraction.
4144
- When multiple transient affordances represent the same interaction mode, keep them behind one shared state instead of parallel flags.
4245
- Cache repeated window state requests at the caller when the underlying platform mutation may hop to the main thread or otherwise be non-trivial.
4346
- On macOS, prefer native menu selector wiring for commands that users can remap in App Shortcuts, instead of hardcoded key-chord matching.
47+
- When refactoring eventful flows, extract pure target/decision helpers first and keep side-effect dispatch ordering unchanged until tests lock transition semantics.
4448

4549
## Testing
4650
- Don't add tests unless explicitly asked.

desktop/src/desktop.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use massive_shell::{ApplicationContext, FontManager, Scene, ShellEvent};
1515
use massive_shell::{AsyncWindowRenderer, ShellWindow};
1616

1717
use crate::DesktopEnvironment;
18-
use crate::desktop_system::{DesktopCommand, DesktopSystem, ProjectCommand};
18+
use crate::desktop_system::{
19+
DesktopCommand, DesktopSystem, ProjectCommand, TransactionEffectsMode,
20+
};
1921
use crate::event_sourcing::Transaction;
2022
use crate::instance_manager::{InstanceManager, ViewPath};
2123
use crate::projects::{
@@ -125,10 +127,9 @@ impl Desktop {
125127
desktop_groups_transaction + project_setup_transaction + primary_view_transaction,
126128
&scene,
127129
&mut instance_manager,
130+
TransactionEffectsMode::Setup,
128131
)?;
129132

130-
system.update_effects(false, true)?;
131-
132133
Ok(Self {
133134
scene,
134135
renderer,
@@ -163,16 +164,22 @@ impl Desktop {
163164
&self.instance_manager,
164165
self.renderer.geometry(),
165166
)?;
166-
let cursor_visible = self.system.cursor_visible();
167+
let cursor_visible = self.system.is_cursor_visible();
167168
if self.cursor_visible != cursor_visible {
168169
self.window.set_cursor_visible(cursor_visible);
169170
self.cursor_visible = cursor_visible;
170171
}
171172
self.system
172-
.transact(cmd, &self.scene, &mut self.instance_manager)?;
173-
174-
let allow_camera_movements = !input_event.any_buttons_pressed();
175-
self.system.update_effects(true, allow_camera_movements)?;
173+
.transact(
174+
cmd,
175+
&self.scene,
176+
&mut self.instance_manager,
177+
if input_event.any_buttons_pressed() {
178+
TransactionEffectsMode::CameraLocked.into()
179+
} else {
180+
None
181+
},
182+
)?;
176183
}
177184

178185
self.renderer.resize_redraw(&window_event)?;
@@ -190,7 +197,12 @@ impl Desktop {
190197
if self.system.is_present(&instance_id) {
191198
// Did it end on its own? -> Act as the user ended it.
192199
// Robustness: This should probably handled differently.
193-
self.system.transact(DesktopCommand::StopInstance(instance_id), &self.scene, &mut self.instance_manager)?;
200+
self.system.transact(
201+
DesktopCommand::StopInstance(instance_id),
202+
&self.scene,
203+
&mut self.instance_manager,
204+
None,
205+
)?;
194206
}
195207

196208
// Feature: Display the error to the user?
@@ -234,13 +246,15 @@ impl Desktop {
234246
DesktopCommand::PresentView(instance, info),
235247
&self.scene,
236248
&mut self.instance_manager,
249+
None,
237250
)?;
238251
}
239252
InstanceCommand::DestroyView(id, collector) => {
240253
self.system.transact(
241254
DesktopCommand::HideView((instance, id).into()),
242255
&self.scene,
243256
&mut self.instance_manager,
257+
None,
244258
)?;
245259
self.instance_manager.remove_view((instance, id).into());
246260
// Feature: Don't push the remaining changes immediately and fade the remaining

0 commit comments

Comments
 (0)