Mountain/Track/Effect/CreateEffectForRequest/mod.rs
1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3//! # CreateEffectForRequest (Track)
4//!
5//! Central routing table that maps string-based commands/RPC methods to typed
6//! effects ([`MappedEffect`]). Each domain module handles its own match arms
7//! and returns `None` for unrecognised methods, enabling the chain-of-
8//! responsibility pattern below.
9//!
10//! ## Domain modules
11//!
12//! | Module | Commands handled |
13//! |-------------------|----------------------------------------------------------|
14//! | Authentication | `Authentication.GetSession`, `Authentication.GetAccounts`|
15//! | Clipboard | `Clipboard.Read`, `Clipboard.Write` |
16//! | Commands | `executeCommand`, `Command.Execute`, `Command.GetAll` |
17//! | Configuration | `config.get`, `config.update`, `Configuration.*` |
18//! | Debug | `Debug.Start`, `Debug.RegisterConfigurationProvider`, `Debug.Stop` |
19//! | Diagnostics | `Diagnostic.Set`, `Diagnostic.Clear` |
20//! | Documents | `Document.Save`, `Document.SaveAs` |
21//! | FileSystem | `FileSystem.*`, `FileWatcher.*`, `openDocument` aliases |
22//! | Git | `$gitExec` |
23//! | Keybinding | `Keybinding.GetResolved` |
24//! | LanguageFeatures | `register_*_provider` (one arm per provider type) |
25//! | Languages | `Languages.GetAll` |
26//! | NativeHost | `NativeHost.OpenExternal` |
27//! | SCM | `$scm:*` |
28//! | Search | `findFiles`, `findTextInFiles`, `Search.TextSearch` |
29//! | Secrets | `secrets.get`, `secrets.store`, `secrets.delete` |
30//! | StatusBar | `$statusBar:*`, `$setStatusBarMessage`, `$disposeStatusBarMessage` |
31//! | Storage | `Storage.Get`, `Storage.Set` |
32//! | Task | `Task.Fetch`, `Task.Execute` |
33//! | Terminal | `$terminal:*`, `Terminal.*` |
34//! | TreeView | `$tree:register`, `tree.*` |
35//! | UserInterface | `UserInterface.*`, `Window.*` |
36//! | Webview | `$webview:*`, `webview.*`, `$resolveCustomEditor` |
37//! | Workspace | `applyEdit`, `showTextDocument`, `$updateWorkspaceFolders` |
38
39pub mod Authentication;
40
41pub mod Clipboard;
42
43pub mod Commands;
44
45pub mod Configuration;
46
47pub mod Debug;
48
49pub mod Diagnostics;
50
51pub mod Documents;
52
53pub mod FileReadAlias;
54
55pub mod FileSystem;
56
57pub mod FileWatcher;
58
59pub mod Git;
60
61pub mod Keybinding;
62
63pub mod LanguageFeatures;
64
65pub mod Languages;
66
67pub mod NativeHost;
68
69pub mod SCM;
70
71pub mod Search;
72
73pub mod Secrets;
74
75pub mod StatusBar;
76
77pub mod Storage;
78
79pub mod Task;
80
81pub mod Terminal;
82
83pub mod TreeView;
84
85pub mod UserInterface;
86
87pub mod Webview;
88
89pub mod WindowUI;
90
91pub mod Workspace;
92
93use serde_json::Value;
94use tauri::{AppHandle, Runtime};
95
96use crate::Track::Effect::MappedEffectType::MappedEffect;
97
98/// Maps a string-based method name (command or RPC) to its corresponding effect
99/// constructor, returning a boxed closure ([`MappedEffect`]) that can be
100/// executed by the ApplicationRunTime.
101///
102/// Delegates to domain modules in priority order. The first module that returns
103/// `Some(result)` wins; unknown methods fall through to an error.
104pub fn Fn<R:Runtime>(
105 _ApplicationHandle:&AppHandle<R>,
106
107 MethodName:&str,
108
109 Parameters:Value,
110) -> Result<MappedEffect, String> {
111 macro_rules! Try {
112 ($Module:ident) => {
113 if let Some(Result) = $Module::CreateEffect::<R>(MethodName, Parameters.clone()) {
114 return Result;
115 }
116 };
117 }
118
119 Try!(Commands);
120
121 Try!(Configuration);
122
123 Try!(Diagnostics);
124
125 Try!(Documents);
126
127 Try!(FileReadAlias);
128
129 Try!(FileSystem);
130
131 Try!(FileWatcher);
132
133 Try!(Keybinding);
134
135 Try!(LanguageFeatures);
136
137 Try!(Languages);
138
139 Try!(Search);
140
141 Try!(Storage);
142
143 Try!(StatusBar);
144
145 Try!(Terminal);
146
147 Try!(TreeView);
148
149 Try!(UserInterface);
150
151 Try!(WindowUI);
152
153 Try!(Webview);
154
155 Try!(Debug);
156
157 Try!(SCM);
158
159 Try!(Workspace);
160
161 Try!(Secrets);
162
163 Try!(Clipboard);
164
165 Try!(NativeHost);
166
167 Try!(Git);
168
169 Try!(Task);
170
171 Try!(Authentication);
172
173 crate::dev_log!("ipc", "warn: [EffectCreation] Unknown method: {}", MethodName);
174
175 Err(format!("Unknown method: {}", MethodName))
176}