@@ -209,6 +209,28 @@ const patchMonacoCssNestingWarnings = async (dashboardDir) => {
209209 }
210210} ;
211211
212+ const LEGACY_DESKTOP_BRIDGE_PATTERNS = {
213+ trayRestartGuard :
214+ / i f \s * \( \s * ! d e s k t o p B r i d g e \? \. i s E l e c t r o n \s * \| \| \s * ! d e s k t o p B r i d g e \. o n T r a y R e s t a r t B a c k e n d \s * \) \s * \{ / ,
215+ typeIsElectron : / ^ \s + i s E l e c t r o n : \s * b o o l e a n ; \r ? \n / m,
216+ typeIsElectronRuntime : / ^ \s + i s E l e c t r o n R u n t i m e : \s * \( \) \s * = > \s * P r o m i s e < b o o l e a n > ; \r ? \n / m,
217+ electronAppFlagToken : / \b i s E l e c t r o n A p p \b / ,
218+ electronAppFlagReplace : / \b i s E l e c t r o n A p p \b / g,
219+ desktopReleaseEnvGuard :
220+ / t y p e o f \s + w i n d o w \s * ! = = \s * ' u n d e f i n e d ' \s * & & \s * ! ! w i n d o w \. a s t r b o t D e s k t o p \? \. i s E l e c t r o n / ,
221+ desktopReleaseRuntimeGuard :
222+ / i s D e s k t o p R e l e a s e M o d e \. v a l u e \s * = \s * ! ! w i n d o w \. a s t r b o t D e s k t o p \? \. i s E l e c t r o n \s * \| \| \s * \r ? \n \s * ! ! \( \s * a w a i t \s + w i n d o w \. a s t r b o t D e s k t o p \? \. i s E l e c t r o n R u n t i m e \? \. \( \) \s * \) \s * ; / ,
223+ legacyRuntimeUsage : / w i n d o w \. a s t r b o t D e s k t o p \? \. i s E l e c t r o n R u n t i m e \? \. \( \) / ,
224+ restartGuard : / i f \s * \( \s * d e s k t o p B r i d g e \? \. i s E l e c t r o n \s * \) \s * \{ / ,
225+ } ;
226+
227+ const MODERN_DESKTOP_BRIDGE_PATTERNS = {
228+ trayRestartGuard : / i f \s * \( \s * ! d e s k t o p B r i d g e \? \. o n T r a y R e s t a r t B a c k e n d \s * \) \s * \{ / ,
229+ desktopBridgeTypeIsDesktop : / ^ \s + i s D e s k t o p : \s * b o o l e a n ; \r ? \n / m,
230+ desktopBridgeTypeRuntime : / ^ \s + i s D e s k t o p R u n t i m e : \s * \( \) \s * = > \s * P r o m i s e < b o o l e a n > ; \r ? \n / m,
231+ restartCapabilityGuard : / c o n s t h a s D e s k t o p R e s t a r t C a p a b i l i t y \s * = / ,
232+ } ;
233+
212234const patchRequiredLegacyFile = async ( { filePath, transform, patchLabel, isAlreadyModern } ) => {
213235 if ( ! existsSync ( filePath ) ) {
214236 throw new Error (
@@ -247,22 +269,22 @@ const patchRequiredLegacyFile = async ({ filePath, transform, patchLabel, isAlre
247269
248270const patchLegacyDesktopBridgeArtifacts = async ( dashboardDir ) => {
249271 const hasModernTrayRestartGuard = ( source ) =>
250- / i f \s * \( \s * ! d e s k t o p B r i d g e \? \. o n T r a y R e s t a r t B a c k e n d \s * \) \s * \{ / . test ( source ) ;
272+ MODERN_DESKTOP_BRIDGE_PATTERNS . trayRestartGuard . test ( source ) ;
251273 const hasModernDesktopBridgeTypes = ( source ) =>
252- / ^ \s + i s D e s k t o p : \s * b o o l e a n ; \n / m . test ( source ) &&
253- / ^ \s + i s D e s k t o p R u n t i m e : \s * \( \) \s * = > \s * P r o m i s e < b o o l e a n > ; \n / m . test ( source ) ;
274+ MODERN_DESKTOP_BRIDGE_PATTERNS . desktopBridgeTypeIsDesktop . test ( source ) &&
275+ MODERN_DESKTOP_BRIDGE_PATTERNS . desktopBridgeTypeRuntime . test ( source ) ;
254276 const hasLegacyDesktopReleaseGuards = ( source ) =>
255- / \b i s E l e c t r o n A p p \b / . test ( source ) ||
256- / w i n d o w \. a s t r b o t D e s k t o p \? \. i s E l e c t r o n / . test ( source ) ||
257- / w i n d o w \. a s t r b o t D e s k t o p \? \. i s E l e c t r o n R u n t i m e \? \. \( \) / . test ( source ) ;
277+ LEGACY_DESKTOP_BRIDGE_PATTERNS . electronAppFlagToken . test ( source ) ||
278+ LEGACY_DESKTOP_BRIDGE_PATTERNS . desktopReleaseEnvGuard . test ( source ) ||
279+ LEGACY_DESKTOP_BRIDGE_PATTERNS . legacyRuntimeUsage . test ( source ) ;
258280 const hasModernRestartCapabilityGuard = ( source ) =>
259- source . includes ( 'const hasDesktopRestartCapability =' ) ;
281+ MODERN_DESKTOP_BRIDGE_PATTERNS . restartCapabilityGuard . test ( source ) ;
260282
261283 await patchRequiredLegacyFile ( {
262284 filePath : path . join ( dashboardDir , 'src' , 'App.vue' ) ,
263285 transform : ( source ) =>
264286 source . replace (
265- / i f \s * \( \s * ! d e s k t o p B r i d g e \? \. i s E l e c t r o n \s * \| \| \s * ! d e s k t o p B r i d g e \. o n T r a y R e s t a r t B a c k e n d \s * \) \s * \{ / ,
287+ LEGACY_DESKTOP_BRIDGE_PATTERNS . trayRestartGuard ,
266288 'if (!desktopBridge?.onTrayRestartBackend) {' ,
267289 ) ,
268290 patchLabel : 'tray restart desktop guard' ,
@@ -273,9 +295,12 @@ const patchLegacyDesktopBridgeArtifacts = async (dashboardDir) => {
273295 filePath : path . join ( dashboardDir , 'src' , 'types' , 'electron-bridge.d.ts' ) ,
274296 transform : ( source ) => {
275297 let patched = source ;
276- patched = patched . replace ( / ^ \s + i s E l e c t r o n : \s * b o o l e a n ; \n / m, ' isDesktop: boolean;\n' ) ;
277298 patched = patched . replace (
278- / ^ \s + i s E l e c t r o n R u n t i m e : \s * \( \) \s * = > \s * P r o m i s e < b o o l e a n > ; \n / m,
299+ LEGACY_DESKTOP_BRIDGE_PATTERNS . typeIsElectron ,
300+ ' isDesktop: boolean;\n' ,
301+ ) ;
302+ patched = patched . replace (
303+ LEGACY_DESKTOP_BRIDGE_PATTERNS . typeIsElectronRuntime ,
279304 ' isDesktopRuntime: () => Promise<boolean>;\n' ,
280305 ) ;
281306 return patched ;
@@ -287,13 +312,16 @@ const patchLegacyDesktopBridgeArtifacts = async (dashboardDir) => {
287312 await patchRequiredLegacyFile ( {
288313 filePath : path . join ( dashboardDir , 'src' , 'layouts' , 'full' , 'vertical-header' , 'VerticalHeader.vue' ) ,
289314 transform : ( source ) => {
290- let patched = source . replaceAll ( / \b i s E l e c t r o n A p p \b / g, 'isDesktopReleaseMode' ) ;
315+ let patched = source . replaceAll (
316+ LEGACY_DESKTOP_BRIDGE_PATTERNS . electronAppFlagReplace ,
317+ 'isDesktopReleaseMode' ,
318+ ) ;
291319 patched = patched . replace (
292- / t y p e o f w i n d o w ! = = ' u n d e f i n e d ' \s * & & \s * ! ! w i n d o w \. a s t r b o t D e s k t o p \? \. i s E l e c t r o n / ,
320+ LEGACY_DESKTOP_BRIDGE_PATTERNS . desktopReleaseEnvGuard ,
293321 'false' ,
294322 ) ;
295323 patched = patched . replace (
296- / i s D e s k t o p R e l e a s e M o d e \. v a l u e \s * = \s * ! ! w i n d o w \. a s t r b o t D e s k t o p \? \. i s E l e c t r o n \s * \| \| \s * \n \s * ! ! \( a w a i t w i n d o w \. a s t r b o t D e s k t o p \? \. i s E l e c t r o n R u n t i m e \? \. \( \) \) ; / ,
324+ LEGACY_DESKTOP_BRIDGE_PATTERNS . desktopReleaseRuntimeGuard ,
297325 'isDesktopReleaseMode.value = false;' ,
298326 ) ;
299327 return patched ;
@@ -305,11 +333,11 @@ const patchLegacyDesktopBridgeArtifacts = async (dashboardDir) => {
305333 await patchRequiredLegacyFile ( {
306334 filePath : path . join ( dashboardDir , 'src' , 'utils' , 'restartAstrBot.ts' ) ,
307335 transform : ( source ) => {
308- if ( source . includes ( 'const hasDesktopRestartCapability =' ) ) {
336+ if ( MODERN_DESKTOP_BRIDGE_PATTERNS . restartCapabilityGuard . test ( source ) ) {
309337 return source ;
310338 }
311339 return source . replace (
312- / i f \s * \( \s * d e s k t o p B r i d g e \? \. i s E l e c t r o n \s * \) \s * \{ / ,
340+ LEGACY_DESKTOP_BRIDGE_PATTERNS . restartGuard ,
313341 `const hasDesktopRestartCapability =
314342 !!desktopBridge &&
315343 typeof desktopBridge.restartBackend === 'function' &&
0 commit comments