mirror of
https://github.com/jahruz67/wisp-open.git
synced 2026-08-08 18:14:08 +00:00
4 lines
7.0 KiB
JavaScript
4 lines
7.0 KiB
JavaScript
(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))l(n);new MutationObserver(n=>{for(const i of n)if(i.type==="childList")for(const r of i.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&l(r)}).observe(document,{childList:!0,subtree:!0});function o(n){const i={};return n.integrity&&(i.integrity=n.integrity),n.referrerpolicy&&(i.referrerPolicy=n.referrerpolicy),n.crossorigin==="use-credentials"?i.credentials="include":n.crossorigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function l(n){if(n.ep)return;n.ep=!0;const i=o(n);fetch(n.href,i)}})();let u=!1;window.toggleApiKey=function(){const e=document.getElementById("apiKey"),t=document.getElementById("eyeBtn");u=!u,e.type=u?"text":"password",t.textContent=u?"\u{1F648}":"\u{1F441}\uFE0F"};window.recordShortcut=function(){const e=document.getElementById("recordBtn"),t=document.getElementById("shortcutInput");e.textContent="Recording...",e.disabled=!0,t.value="";let o="";const l=s=>{s.preventDefault(),s.stopPropagation();const d=[];s.ctrlKey&&d.push("ctrl"),s.altKey&&d.push("alt"),s.shiftKey&&d.push("shift"),(s.metaKey||s.key==="Meta"||s.key==="OS")&&d.push("win");let a=s.key.toLowerCase();a==="control"&&(a="ctrl"),a==="alt"&&(a="alt"),a==="shift"&&(a="shift"),(a==="meta"||a==="os")&&(a="win"),a===" "&&(a="space");const p=new Set(d);p.add(a);const y=Array.from(p).filter(f=>f!==a);y.push(a),o=y.join("+"),t.value=o,["ctrl","alt","shift","win"].includes(a)||i()},n=s=>{s.preventDefault(),s.stopPropagation(),o&&(o.split("+").every(a=>["ctrl","alt","shift","win"].includes(a))&&o.includes("+")?setTimeout(i,100):!s.ctrlKey&&!s.altKey&&!s.shiftKey&&!s.metaKey&&i())},i=()=>{if(!o){e.textContent="Record",e.disabled=!1,r();return}window.go.main.App.SaveSettings({shortcut:o}).then(()=>{e.textContent="Record",e.disabled=!1,r()})},r=()=>{window.removeEventListener("keydown",l,!0),window.removeEventListener("keyup",n,!0)};window.addEventListener("keydown",l,!0),window.addEventListener("keyup",n,!0)};async function w(){try{const e=await window.go.main.App.GetSettings();document.getElementById("apiKey").value=e.api_key||"",document.getElementById("shortcutInput").value=e.shortcut||"alt+z",document.getElementById("whisperModel").value=e.whisper_model||"whisper-large-v3-turbo",document.getElementById("aiModel").value=e.ai_model||"llama-3.3-70b-versatile",document.getElementById("aiPrompt").value=e.ai_prompt||"",document.getElementById("language").value=e.language||"en",document.getElementById("startupToggle").checked=e.startup||!1;const t=e.history||[],o=document.getElementById("historyList");t.length>0&&(o.innerHTML="",[...t].reverse().forEach(l=>{const n=document.createElement("div");n.className="history-item";const i=document.createElement("span");i.className="history-time",i.textContent=new Date(l.timestamp).toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"});const r=document.createElement("div");r.textContent=l.text,n.appendChild(i),n.appendChild(r),o.appendChild(n)}))}catch(e){console.error("Failed to load settings:",e)}}async function g(){try{const e=await window.go.main.App.GetMicrophones(),t=document.getElementById("micDevice");e.forEach(o=>{if(o.index!==-1){const l=document.createElement("option");l.value=o.index,l.textContent=o.name,t.appendChild(l)}})}catch(e){console.error("Failed to load mics:",e)}}window.saveApiKey=async function(){const e=document.getElementById("apiKey").value.trim();await window.go.main.App.SaveSettings({api_key:e}),c()};function c(e="Settings Saved!"){const t=document.getElementById("saveStatus");t.textContent=e,t.classList.add("show"),setTimeout(()=>t.classList.remove("show"),2e3)}window.saveWhisperModel=async function(){await window.go.main.App.SaveSettings({whisper_model:document.getElementById("whisperModel").value}),c()};window.saveAiModel=async function(){await window.go.main.App.SaveSettings({ai_model:document.getElementById("aiModel").value}),c()};window.saveLanguage=async function(){await window.go.main.App.SaveSettings({language:document.getElementById("language").value}),c("Language Saved!")};window.saveMicDevice=async function(){const e=document.getElementById("micDevice").value;await window.go.main.App.SaveSettings({microphone_device:e==="default"?null:parseInt(e)}),c()};window.savePrompt=async function(){await window.go.main.App.SaveSettings({ai_prompt:document.getElementById("aiPrompt").value.trim()}),c("Prompt Saved!")};window.toggleStartup=async function(){await window.go.main.App.ToggleStartup(document.getElementById("startupToggle").checked)};window.clearHistory=async function(){confirm("Clear all history?")&&(await window.go.main.App.ClearHistory(),document.getElementById("historyList").innerHTML='<div style="text-align: center; color: var(--text-muted); padding: 20px;">No history yet.</div>')};async function h(){try{const e=await window.go.main.App.CheckOnline(),t=document.getElementById("connectionStatus");if(e)t.innerHTML="\u{1F7E2} Online - Cloud transcription available",t.style.background="rgba(34, 197, 94, 0.1)",t.style.color="#22c55e";else{t.innerHTML="\u{1F534} Offline - Install local Whisper for transcription",t.style.background="rgba(239, 68, 68, 0.1)",t.style.color="#ef4444";const o=document.getElementById("aiModel"),l=document.getElementById("whisperModel");for(let n of o.options)n.value!=="None"&&!n.value.startsWith("local-")&&(n.disabled=!0,n.text.includes("(offline)")||(n.text+=" (offline)"))}}catch(e){console.error("Connection check failed:",e)}}async function m(){try{const e=await window.go.main.App.GetWhisperInfo(),t=document.getElementById("whisperModel"),o=t.querySelector('option[value^="local-"]');if(o&&o.remove(),e.installed){document.getElementById("whisperNotInstalled").style.display="none",document.getElementById("whisperInstalled").style.display="block",document.getElementById("installedModel").textContent=e.model+" model";const l=document.createElement("option");l.value="local-"+e.model,l.textContent="\u{1F5A5}\uFE0F Local - "+e.model+" (offline)",l.style.fontWeight="bold",t.insertBefore(l,t.firstChild)}else document.getElementById("whisperNotInstalled").style.display="block",document.getElementById("whisperInstalled").style.display="none"}catch(e){console.error("Whisper status check failed:",e)}}window.installWhisper=async function(){const e=document.getElementById("whisperModelSelect").value,t=document.getElementById("installBtn");t.disabled=!0,t.textContent="Starting installation...";try{const o=await window.go.main.App.InstallWhisper(e);alert(o+`
|
|
|
|
A terminal window will open showing the installation progress. This may take several minutes depending on your internet speed.`),setTimeout(m,5e3)}catch(o){alert("Installation failed: "+o)}t.disabled=!1,t.textContent="\u{1F680} Install Offline Whisper"};window.uninstallWhisper=async function(){if(!!confirm("Are you sure you want to uninstall offline Whisper? This will delete the downloaded model."))try{const e=await window.go.main.App.UninstallWhisper();alert(e),m()}catch(e){alert("Uninstall failed: "+e)}};w();g();h();m();
|