| 55 | window.transformCallback = transformCallback; |
| 56 | |
| 57 | async function init() { |
| 58 | if (__TAURI_METADATA__.__currentWindow.label === 'tray') { |
| 59 | document.getElementsByTagName('html')[0].style['font-size'] = '70%'; |
| 60 | } |
| 61 | |
| 62 | async function platform() { |
| 63 | return invoke('platform', { |
| 64 | __tauriModule: 'Os', |
| 65 | message: { cmd: 'platform' } |
| 66 | }); |
| 67 | } |
| 68 | |
| 69 | if (__TAURI_METADATA__.__currentWindow.label !== 'tray') { |
| 70 | const _platform = await platform(); |
| 71 | const chatConf = await invoke('get_app_conf') || {}; |
| 72 | if (/darwin/.test(_platform) && !chatConf.titlebar) { |
| 73 | const topStyleDom = document.createElement("style"); |
| 74 | topStyleDom.innerHTML = `#chatgpt-app-window-top{position:fixed;top:0;z-index:999999999;width:100%;height:24px;background:transparent;cursor:grab;cursor:-webkit-grab;user-select:none;-webkit-user-select:none;}#chatgpt-app-window-top:active {cursor:grabbing;cursor:-webkit-grabbing;}`; |
| 75 | document.head.appendChild(topStyleDom); |
| 76 | const topDom = document.createElement("div"); |
| 77 | topDom.id = "chatgpt-app-window-top"; |
| 78 | document.body.appendChild(topDom); |
| 79 | |
| 80 | if (window.location.host === 'chat.openai.com') { |
| 81 | const nav = document.body.querySelector('nav'); |
| 82 | if (nav) { |
| 83 | const currentPaddingTop = parseInt(window.getComputedStyle(document.querySelector('nav'), null).getPropertyValue('padding-top').replace('px', ''), 10); |
| 84 | const navStyleDom = document.createElement("style"); |
| 85 | navStyleDom.innerHTML = `nav{padding-top:${currentPaddingTop + topDom.clientHeight}px !important}`; |
| 86 | document.head.appendChild(navStyleDom); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | topDom.addEventListener("mousedown", () => invoke("drag_window")); |
| 91 | topDom.addEventListener("touchstart", () => invoke("drag_window")); |
| 92 | topDom.addEventListener("dblclick", () => invoke("fullscreen")); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | document.addEventListener("click", (e) => { |
| 97 | const origin = e.target.closest("a"); |
| 98 | if (!origin || !origin.target) return; |
| 99 | if (origin && origin.href && origin.target !== '_self') { |
| 100 | invoke('open_link', { url: origin.href }); |
| 101 | } |
| 102 | }); |
| 103 | |
| 104 | // Fix Chinese input method "Enter" on Safari |
| 105 | document.addEventListener("keydown", (e) => { |
| 106 | if(e.keyCode == 229) e.stopPropagation(); |
| 107 | }, true) |
| 108 | |
| 109 | if (window.location.host === 'chat.openai.com') { |
| 110 | window.__sync_prompts = async function() { |
| 111 | await invoke('sync_prompts', { time: Date.now() }); |
| 112 | } |
| 113 | } |
| 114 | |