@@ -67,17 +67,24 @@ private async Task InitializeServerAsync()
6767 var certCacheDir = Path . Combine ( pluginDataDir , "certificates" ) ;
6868
6969 this . _certificateManager = new CertificateManager ( certCacheDir ) ;
70- var certLoaded = await this . _certificateManager . InitializeAsync ( ) ;
70+ await this . _certificateManager . InitializeAsync ( ) ;
7171
7272 this . UpdatePluginStatus ( ) ;
7373
7474 this . _httpsServer = new HttpsServer (
7575 HttpPort ,
7676 HttpsPort ,
7777 this . _certificateManager . Certificate ,
78- this . HandleHttpRequest ) ;
78+ this . HandleHttpRequest ,
79+ this . RunHapticByIndex ,
80+ HapticWaveforms ) ;
7981
8082 this . _httpsServer . Start ( ) ;
83+
84+ if ( ! String . IsNullOrEmpty ( this . _httpsServer . BindError ) )
85+ {
86+ this . OnPluginStatusChanged ( Loupedeck . PluginStatus . Error , this . _httpsServer . BindError ) ;
87+ }
8188 }
8289 catch ( Exception ex )
8390 {
@@ -183,22 +190,27 @@ private Object HandleTriggerHaptic(String waveform)
183190 } ;
184191 }
185192
186- try
193+ PluginLog . Verbose ( $ "Queueing haptic: { waveform } ") ;
194+ Task . Run ( ( ) =>
187195 {
188- this . PluginEvents . RaiseEvent ( waveform ) ;
189- PluginLog . Info ( $ "Triggered haptic: { waveform } ") ;
190-
191- return new
196+ PluginLog . Verbose ( $ "Starting haptic task: { waveform } ") ;
197+ try
192198 {
193- success = true ,
194- waveform = waveform
195- } ;
196- }
197- catch ( Exception ex )
199+ this . PluginEvents . RaiseEvent ( waveform ) ;
200+ PluginLog . Info ( $ "Triggered haptic: { waveform } ") ;
201+ }
202+ catch ( Exception ex )
203+ {
204+ PluginLog . Error ( ex , $ "Failed haptic task: { waveform } ") ;
205+ }
206+ } ) ;
207+
208+ PluginLog . Verbose ( $ "Returning response for: { waveform } ") ;
209+ return new
198210 {
199- PluginLog . Error ( ex , $ "Failed to trigger haptic: { waveform } " ) ;
200- return new { success = false , error = $ "Failed to trigger haptic: { ex . Message } " } ;
201- }
211+ success = true ,
212+ waveform = waveform
213+ } ;
202214 }
203215
204216 private void RegisterHapticEvents ( )
@@ -209,5 +221,25 @@ private void RegisterHapticEvents()
209221 }
210222 PluginLog . Info ( $ "Registered { HapticWaveforms . Count } haptic events") ;
211223 }
224+
225+ private void RunHapticByIndex ( Int32 index )
226+ {
227+ if ( index < 0 || index >= HapticWaveforms . Count )
228+ {
229+ PluginLog . Warning ( $ "Invalid haptic index: { index } ") ;
230+ return ;
231+ }
232+
233+ var waveform = HapticWaveforms [ index ] ;
234+ try
235+ {
236+ this . PluginEvents . RaiseEvent ( waveform ) ;
237+ PluginLog . Verbose ( $ "Triggered haptic by index: { index } -> { waveform } ") ;
238+ }
239+ catch ( Exception ex )
240+ {
241+ PluginLog . Error ( ex , $ "Failed to trigger haptic: { waveform } ") ;
242+ }
243+ }
212244 }
213245}
0 commit comments