@@ -9,14 +9,42 @@ import os from "os";
99const __filename = fileURLToPath ( import . meta. url ) ;
1010const __dirname = dirname ( __filename ) ;
1111
12+ const METRIC_URL_FOR_STAGE = {
13+ "dev" : "https://dev.phcode.dev/desktop-metrics.html" ,
14+ "stage" : "https://staging.phcode.dev/desktop-metrics.html" ,
15+ "production" : "https://phcode.dev/desktop-metrics.html"
16+ } ;
17+
18+ function _patchTauriConfigWithMetricsHTML ( tauriConf , metricsHTMLPageURL ) {
19+ const window = tauriConf . tauri . windows [ 1 ] ;
20+ if ( ! window . label === "healthData" ) {
21+ throw new Error ( "Expected tauriConf.json- tauri.windows[1].label to be 'healthData'" ) ;
22+ }
23+ window . url = metricsHTMLPageURL ;
24+ const metricsPageURL = new URL ( metricsHTMLPageURL )
25+ const dangerousRemoteDomainIpcAccess = tauriConf . tauri . security . dangerousRemoteDomainIpcAccess ;
26+ for ( let ipc of dangerousRemoteDomainIpcAccess ) {
27+ if ( ipc . windows . includes ( "healthData" ) ) {
28+ ipc . scheme = "https" ;
29+ ipc . domain = metricsPageURL . host ;
30+ }
31+ }
32+ }
33+
1234async function createDistReleaseConfig ( ) {
1335 const platform = getPlatformDetails ( ) . platform ;
1436 const tauriConfigPath = ( platform === "win" ) ? `${ __dirname } \\..\\src-tauri\\tauri.conf.json`
1537 : `${ __dirname } /../src-tauri/tauri.conf.json` ;
38+ const phoenixConfigPath = ( platform === "win" ) ? `${ __dirname } \\...\\..\\phoenix\\dist\\config.json`
39+ : `${ __dirname } /../../phoenix/dist/config.json` ;
1640 const tauriLocalConfigPath = ( platform === "win" ) ? `${ __dirname } \\..\\src-tauri\\tauri-local.conf.json`
1741 : `${ __dirname } /../src-tauri/tauri-local.conf.json` ;
18- console . log ( "Reading config file: " , tauriConfigPath ) ;
42+ console . log ( "Reading Tauri config file: " , tauriConfigPath ) ;
1943 let configJson = JSON . parse ( fs . readFileSync ( tauriConfigPath ) ) ;
44+ console . log ( "Reading Phoenix config file: " , phoenixConfigPath ) ;
45+ let phoenixConfigJson = JSON . parse ( fs . readFileSync ( phoenixConfigPath ) ) ;
46+ const phoenixStageInDist = phoenixConfigJson . config . environment ;
47+ console . log ( "Phoenix stage in dist folder is: " , phoenixStageInDist ) ;
2048 console . log ( chalk . cyan ( "\n!Only creating executables. Creating msi, appimage and dmg installers are disabled in this build. If you want to create an installer, use: npm run tauri build manually after setting distDir in tauri conf!\n" ) ) ;
2149 configJson . tauri . bundle . active = false ;
2250 configJson . build . distDir = '../../phoenix/dist/' ;
@@ -26,8 +54,14 @@ async function createDistReleaseConfig() {
2654 } else {
2755 configJson . tauri . windows [ 0 ] . url = `phtauri://localhost/v${ phoenixVersion } /` ;
2856 }
57+ const metricsURLToUse = METRIC_URL_FOR_STAGE [ phoenixStageInDist ] ;
58+ if ( ! metricsURLToUse ) {
59+ throw new Error ( "Unknown Phoenix stage(config.environment) in file " + phoenixConfigPath ) ;
60+ }
61+ _patchTauriConfigWithMetricsHTML ( configJson , metricsURLToUse ) ;
2962 console . log ( "Window Boot url is: " , configJson . tauri . windows [ 0 ] . url ) ;
3063 console . log ( "Writing new local config json " , tauriLocalConfigPath ) ;
64+ console . log ( "Window Metrics url " , configJson . tauri . windows [ 1 ] . url ) ;
3165 fs . writeFileSync ( tauriLocalConfigPath , JSON . stringify ( configJson , null , 4 ) ) ;
3266}
3367
0 commit comments