mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
feat(desktop): build & inject preview-agent script into child webview
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
029c2a3f8f
commit
d3e7a35e7a
@ -5,7 +5,8 @@
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"build": "bun run build:preview-agent && tsc -b && vite build",
|
||||
"build:preview-agent": "bun run ./scripts/build-preview-agent.ts",
|
||||
"build:sidecars": "bun run ./scripts/build-sidecars.ts",
|
||||
"build:macos-arm64": "bash ./scripts/build-macos-arm64.sh",
|
||||
"build:windows-x64": "powershell -ExecutionPolicy Bypass -File ./scripts/build-windows-x64.ps1",
|
||||
|
||||
3
desktop/scripts/build-preview-agent.ts
Normal file
3
desktop/scripts/build-preview-agent.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { $ } from 'bun'
|
||||
await $`bun build ./src/preview-agent/index.ts --outfile=./src-tauri/resources/preview-agent.js --format=iife --minify`
|
||||
console.log('preview-agent.js built')
|
||||
1
desktop/src-tauri/resources/preview-agent.js
Normal file
1
desktop/src-tauri/resources/preview-agent.js
Normal file
@ -0,0 +1 @@
|
||||
(()=>{(()=>{window.__PREVIEW_AGENT__=!0})();})();
|
||||
@ -3,8 +3,7 @@ use tauri::{AppHandle, LogicalPosition, LogicalSize, Manager, Runtime, WebviewBu
|
||||
|
||||
const PREVIEW_LABEL: &str = "preview";
|
||||
|
||||
/// M1 placeholder init script; replaced by the real preview-agent bundle in a later milestone.
|
||||
const PREVIEW_INIT_SCRIPT: &str = "window.__PREVIEW_AGENT_READY__ = true;";
|
||||
const PREVIEW_INIT_SCRIPT: &str = include_str!("../resources/preview-agent.js");
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct PreviewState(Mutex<PreviewInner>);
|
||||
@ -63,7 +62,7 @@ pub async fn preview_open<R: Runtime>(
|
||||
.get_window(crate::MAIN_WINDOW_LABEL)
|
||||
.ok_or_else(|| "main window not found".to_string())?;
|
||||
let builder = WebviewBuilder::new(PREVIEW_LABEL, WebviewUrl::External(target))
|
||||
.initialization_script(PREVIEW_INIT_SCRIPT);
|
||||
.initialization_script_for_all_frames(PREVIEW_INIT_SCRIPT);
|
||||
main.add_child(
|
||||
builder,
|
||||
LogicalPosition::new(bounds.x, bounds.y),
|
||||
|
||||
5
desktop/src/preview-agent/index.ts
Normal file
5
desktop/src/preview-agent/index.ts
Normal file
@ -0,0 +1,5 @@
|
||||
// 注入到被预览页面的 IIFE 入口(M3 逐步填实)
|
||||
;(() => {
|
||||
// 标记注入成功,供宿主探测
|
||||
;(window as unknown as { __PREVIEW_AGENT__?: boolean }).__PREVIEW_AGENT__ = true
|
||||
})()
|
||||
Loading…
x
Reference in New Issue
Block a user