(function () { 'use strict'; var invoke = window.__TAURI__.core.invoke; var listen = window.__TAURI__.event.listen; // ── Rust → JS ────────────────────────────── listen('pet://state', function (e) { if (window.cfcPetAPI) window.cfcPetAPI.notifyState(e.payload); }); listen('pet://bubble', function (e) { if (window.cfcPetAPI) window.cfcPetAPI.showBubble(e.payload.text, e.payload.durationMs); }); listen('pet://config', function (e) { if (window.cfcPetAPI) window.cfcPetAPI.loadConfig(e.payload); }); listen('pet://custom-image', function (e) { if (window.cfcPetAPI) window.cfcPetAPI.setCustomImage(e.payload && e.payload.url); }); // 启动时应用已保存的自定义形象 try { invoke('get_settings').then(function (s) { if (s && s.customMascotUrl && window.cfcPetAPI) { window.cfcPetAPI.setCustomImage(s.customMascotUrl); } }).catch(function () {}); } catch (_) { /* noop */ } // ── JS → Rust(替换 chrome.webview.hostObjects.sync.cfcHost)── window.cfcHost = { onInteract: function (action, dataJson) { try { invoke('on_interact', { action: action, data: dataJson }); } catch (err) { console.log('[interaction]', action, dataJson); } }, onDragStart: function () { try { invoke('drag_start'); } catch (e) { /* noop */ } }, onDragEnd: function () { try { invoke('drag_end'); } catch (e) { /* noop */ } } }; })();