Skip to content

Commit dde26f4

Browse files
committed
chore: add hidden window that handles health data due to phtauri custom protocol
1 parent 39ac6f5 commit dde26f4

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

src-build/createDistReleaseConfig.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,42 @@ import os from "os";
99
const __filename = fileURLToPath(import.meta.url);
1010
const __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+
1234
async 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

src-tauri/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src-tauri/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ mod utilities;
3232
mod boot_config;
3333

3434
mod platform;
35+
use tauri_plugin_window_state::StateFlags;
3536

3637
#[derive(Clone, serde::Serialize)]
3738
struct Payload {
@@ -277,7 +278,7 @@ fn main() {
277278
Ok(response)
278279
})
279280
.plugin(tauri_plugin_fs_extra::init())
280-
.plugin(tauri_plugin_window_state::Builder::default().build())
281+
.plugin(tauri_plugin_window_state::Builder::default().with_state_flags(StateFlags::all() & !StateFlags::VISIBLE).build())
281282
.plugin(tauri_plugin_single_instance::init(|app, argv, cwd| {
282283
println!("{}, {argv:?}, {cwd}", app.package_info().name);
283284

src-tauri/tauri.conf.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,14 @@
364364
"extn-29",
365365
"extn-30"
366366
]
367+
},
368+
{
369+
"scheme": "http",
370+
"domain": "localhost:8000",
371+
"enableTauriAPI": true,
372+
"windows": [
373+
"healthData"
374+
]
367375
}
368376
]
369377
},
@@ -389,6 +397,12 @@
389397
"minWidth": 800,
390398
"acceptFirstMouse": true,
391399
"fileDropEnabled": false
400+
},
401+
{
402+
"label": "healthData",
403+
"title": "Health data window",
404+
"url": "http://localhost:8000/src/desktop-metrics.html",
405+
"visible": false
392406
}
393407
]
394408
}

0 commit comments

Comments
 (0)