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 | `$languageFeatures:registerProvider` |
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;
40pub mod Clipboard;
41pub mod Commands;
42pub mod Configuration;
43pub mod Debug;
44pub mod Diagnostics;
45pub mod Documents;
46pub mod FileReadAlias;
47pub mod FileSystem;
48pub mod FileWatcher;
49pub mod Git;
50pub mod Keybinding;
51pub mod LanguageFeatures;
52pub mod Languages;
53pub mod NativeHost;
54pub mod SCM;
55pub mod Search;
56pub mod Secrets;
57pub mod StatusBar;
58pub mod Storage;
59pub mod Task;
60pub mod Terminal;
61pub mod TreeView;
62pub mod UserInterface;
63pub mod Webview;
64pub mod WindowUI;
65pub mod Workspace;
66
67use serde_json::Value;
68use tauri::{AppHandle, Runtime};
69
70use crate::Track::Effect::MappedEffectType::MappedEffect;
71
72/// Maps a string-based method name (command or RPC) to its corresponding effect
73/// constructor, returning a boxed closure ([`MappedEffect`]) that can be
74/// executed by the ApplicationRunTime.
75///
76/// Delegates to domain modules in priority order. The first module that returns
77/// `Some(result)` wins; unknown methods fall through to an error.
78pub fn Fn<R:Runtime>(
79 _ApplicationHandle:&AppHandle<R>,
80 MethodName:&str,
81 Parameters:Value,
82) -> Result<MappedEffect, String> {
83 macro_rules! Try {
84 ($Module:ident) => {
85 if let Some(Result) = $Module::CreateEffect::<R>(MethodName, Parameters.clone()) {
86 return Result;
87 }
88 };
89 }
90
91 Try!(Commands);
92 Try!(Configuration);
93 Try!(Diagnostics);
94 Try!(Documents);
95 Try!(FileReadAlias);
96 Try!(FileSystem);
97 Try!(FileWatcher);
98 Try!(Keybinding);
99 Try!(LanguageFeatures);
100 Try!(Languages);
101 Try!(Search);
102 Try!(Storage);
103 Try!(StatusBar);
104 Try!(Terminal);
105 Try!(TreeView);
106 Try!(UserInterface);
107 Try!(WindowUI);
108 Try!(Webview);
109 Try!(Debug);
110 Try!(SCM);
111 Try!(Workspace);
112 Try!(Secrets);
113 Try!(Clipboard);
114 Try!(NativeHost);
115 Try!(Git);
116 Try!(Task);
117 Try!(Authentication);
118
119 crate::dev_log!("ipc", "warn: [EffectCreation] Unknown method: {}", MethodName);
120 Err(format!("Unknown method: {}", MethodName))
121}