init: initial commit

This commit is contained in:
Blizzard
2026-04-01 14:09:33 +08:00
commit aef2e152dc
66 changed files with 6540 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<title>AI Expert Sidebar — 智能客服助手</title>
<meta name="description" content="AI Expert Sidebar:轻量级桌面客服辅助工具,知识库搜索 + AI 话术润色"/>
</head>
<body>
<div id="root"></div>
<script src="./src/main.tsx" type="module"></script>
</body>
</html>
+2287
View File
File diff suppressed because it is too large Load Diff
+25
View File
@@ -0,0 +1,25 @@
{
"name": "frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.6",
"@vitejs/plugin-react": "^2.0.1",
"autoprefixer": "^10.4.27",
"postcss": "^8.5.8",
"tailwindcss": "^3.4.19",
"typescript": "^4.6.4",
"vite": "^3.0.7"
}
}
+1
View File
@@ -0,0 +1 @@
603a1d85b868dec3cb564be2820cbd39
+6
View File
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
+59
View File
@@ -0,0 +1,59 @@
#app {
height: 100vh;
text-align: center;
}
#logo {
display: block;
width: 50%;
height: 50%;
margin: auto;
padding: 10% 0 0;
background-position: center;
background-repeat: no-repeat;
background-size: 100% 100%;
background-origin: content-box;
}
.result {
height: 20px;
line-height: 20px;
margin: 1.5rem auto;
}
.input-box .btn {
width: 60px;
height: 30px;
line-height: 30px;
border-radius: 3px;
border: none;
margin: 0 0 0 20px;
padding: 0 8px;
cursor: pointer;
}
.input-box .btn:hover {
background-image: linear-gradient(to top, #cfd9df 0%, #e2ebf0 100%);
color: #333333;
}
.input-box .input {
border: none;
border-radius: 3px;
outline: none;
height: 30px;
line-height: 30px;
padding: 0 10px;
background-color: rgba(240, 240, 240, 1);
-webkit-font-smoothing: antialiased;
}
.input-box .input:hover {
border: none;
background-color: rgba(255, 255, 255, 1);
}
.input-box .input:focus {
border: none;
background-color: rgba(255, 255, 255, 1);
}
+116
View File
@@ -0,0 +1,116 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { AskDeepSeek, GetActiveLibrary, GetDBStatus, StopGeneration } from 'wailsjs/go/main/App';
import { EventsOn } from 'wailsjs/runtime/runtime';
import TitleBar from './components/TitleBar';
import LibraryBar from './components/LibraryBar';
import SearchInput from './components/SearchInput';
import ResultCard from './components/ResultCard';
import AIPanel from './components/AIPanel';
import SettingsModal from './components/SettingsModal';
import { useSearch, type SearchResult } from './hooks/useSearch';
export default function App() {
const [dbReady, setDbReady] = useState(false);
const [activeLib, setActiveLib] = useState('');
const [showSettings, setShowSettings] = useState(false);
const [aiText, setAiText] = useState('');
const [aiLoading, setAiLoading] = useState(false);
const [aiError, setAiError] = useState<string | null>(null);
const [aiTarget, setAiTarget] = useState<SearchResult | null>(null);
const [isFallback, setIsFallback] = useState(false);
const aiTextRef = useRef('');
const { query, setQuery, results, loading, error } = useSearch();
useEffect(() => {
const check = async () => {
try { setDbReady(await GetDBStatus()); } catch { setDbReady(false); }
};
const loadLib = async () => { setActiveLib(await GetActiveLibrary()); };
check(); loadLib();
const id = setInterval(check, 5000);
return () => clearInterval(id);
}, []);
useEffect(() => {
const offChunk = EventsOn('ai:chunk', (c: string) => { aiTextRef.current += c; setAiText(aiTextRef.current); });
const offDone = EventsOn('ai:done', () => setAiLoading(false));
const offFallback = EventsOn('ai:fallback', (raw: string) => { setIsFallback(true); aiTextRef.current = raw; setAiText(raw); setAiLoading(false); });
const offErr = EventsOn('ai:error', (m: string) => { setAiError(m); setAiLoading(false); });
return () => { offChunk(); offDone(); offFallback(); offErr(); };
}, []);
const handleAsk = useCallback(async (result: SearchResult) => {
setAiTarget(result); setAiText(''); setAiError(null); setIsFallback(false);
setAiLoading(true); aiTextRef.current = '';
try { await AskDeepSeek(result.question, result.answer); }
catch { setAiError('DeepSeek 连接失败'); setAiLoading(false); }
}, []);
const handleStop = useCallback(async () => { await StopGeneration(); }, []);
const handleCopyAI = useCallback(async (text: string) => {
try { await navigator.clipboard.writeText(text); }
catch {
const el = document.createElement('textarea'); el.value = text;
document.body.appendChild(el); el.select(); document.execCommand('copy');
document.body.removeChild(el);
}
}, []);
const closeAI = useCallback(() => {
handleStop(); setAiTarget(null); setAiText(''); setAiError(null); setIsFallback(false);
}, [handleStop]);
return (
<div className="sidebar-root">
<div className="orb orb-purple" /><div className="orb orb-blue" />
<div className="relative z-10 flex flex-col h-full">
<TitleBar dbReady={dbReady} onSettings={() => setShowSettings(true)} />
<LibraryBar activeName={activeLib} onSwitch={name => { setActiveLib(name); setQuery(''); }} />
<SearchInput value={query} onChange={setQuery} loading={loading} />
{error && (
<div className="mx-4 mb-2 px-3 py-2 rounded-lg bg-red-500/10 border border-red-500/25 text-red-400 text-[11px] flex items-center gap-2">
<span></span><span>{error}</span>
</div>
)}
<div className="flex-1 overflow-y-auto results-scroll px-4 pb-2 flex flex-col gap-2">
{!loading && results.length === 0 && query.trim() && (
<div className="flex flex-col items-center justify-center h-36 gap-3">
<span className="text-3xl">🔍</span>
<p className="text-[12px] text-white/30"></p>
<button id="btn-ask-direct" onClick={() => handleAsk({ id: 0, question: query, answer: '', category: '', score: 0, is_fallback: false })}
className="flex items-center gap-2 px-4 py-2 rounded-xl bg-accent/20 text-accent-light
border border-accent/30 hover:bg-accent/35 transition-all text-[12px] font-medium">
DeepSeek
</button>
</div>
)}
{!query.trim() && !loading && (
<div className="flex flex-col items-center justify-center h-32 text-white/25">
<span className="text-3xl mb-2">💬</span>
<p className="text-[12px]"></p>
</div>
)}
{!loading && results.length > 0 && results[0].is_fallback && (
<div className="px-3 py-2 rounded-lg bg-white/5 border border-white/8 text-white/35 text-[10px] flex items-center gap-2">
<span>💡</span><span></span>
</div>
)}
{results.map(r => <ResultCard key={r.id} result={r} onPolish={handleAsk} />)}
</div>
{aiTarget && (
<AIPanel text={aiText} loading={aiLoading} error={aiError}
isFallback={isFallback} question={aiTarget.question}
onCopy={handleCopyAI} onStop={handleStop} onClose={closeAI} />
)}
</div>
{showSettings && <SettingsModal onClose={() => setShowSettings(false)} />}
</div>
);
}
+93
View File
@@ -0,0 +1,93 @@
Copyright 2016 The Nunito Project Authors (contact@sansoxygen.com),
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

+136
View File
@@ -0,0 +1,136 @@
import { useState } from 'react';
interface AIPanelProps {
text: string;
loading: boolean;
error: string | null;
isFallback: boolean;
question: string;
onCopy: (text: string) => void;
onStop: () => void;
onClose: () => void;
}
export default function AIPanel({
text, loading, error, isFallback, question, onCopy, onStop, onClose,
}: AIPanelProps) {
const [copied, setCopied] = useState(false);
const handleCopy = () => {
onCopy(text);
setCopied(true);
setTimeout(() => setCopied(false), 1000);
};
return (
<div className="flex-shrink-0 px-4 pb-4 animate-fade-in">
{/* Header */}
<div className="flex items-center justify-between mb-2">
<div className="flex items-center gap-1.5">
<span className="text-sm"></span>
<span className="text-[12px] font-semibold text-accent-light">
DeepSeek RAG
</span>
{/* Animated loading dots */}
{loading && (
<div className="flex gap-1 ml-1">
{[0, 1, 2].map(i => (
<span
key={i}
className="w-1 h-1 rounded-full bg-accent-light"
style={{ animation: `pulseDot 1.4s ease-in-out ${i * 0.2}s infinite` }}
/>
))}
</div>
)}
{/* Fallback badge */}
{isFallback && !loading && (
<span className="text-[9px] px-1.5 py-0.5 rounded-full bg-amber-500/20 text-amber-400 border border-amber-500/30 ml-1">
</span>
)}
</div>
<div className="flex items-center gap-1">
{/* Stop button — only visible while streaming */}
{loading && (
<button
id="btn-ai-stop"
onClick={onStop}
title="停止生成"
className="flex items-center gap-1 text-[10px] px-2 py-1 rounded-md
bg-red-500/15 text-red-400 border border-red-500/25
hover:bg-red-500/25 transition-all"
>
<span></span>
</button>
)}
<button
id="btn-ai-close"
onClick={onClose}
className="text-white/30 hover:text-white/70 text-xs transition-colors ml-1"
>
</button>
</div>
</div>
{/* Question context */}
{question && (
<p className="text-[10px] text-white/35 mb-2 line-clamp-1">
{question}
</p>
)}
{/* Fallback notice */}
{isFallback && (
<div className="mb-2 px-2 py-1.5 rounded-lg bg-amber-500/10 border border-amber-500/20
text-amber-400 text-[10px] flex items-center gap-1.5">
<span></span>
<span>DeepSeek </span>
</div>
)}
{/* Error state */}
{error && !isFallback ? (
<div className="ai-panel border-red-500/30 bg-red-500/5">
<p className="text-red-400 text-[12px] font-medium mb-1"> AI </p>
<p className="text-white/50 text-[11px]">{error}</p>
<p className="text-white/30 text-[11px] mt-2">使</p>
</div>
) : (
/* Content panel with typewriter effect */
<div className={`ai-panel ${isFallback ? 'border-amber-500/20 bg-amber-500/5' : ''}`}>
{loading && !text ? (
<p className="text-white/30 text-[12px] animate-pulse">
DeepSeek
</p>
) : (
<p className="text-[13px] leading-relaxed whitespace-pre-wrap">
{text}
{/* Blinking cursor while streaming */}
{loading && (
<span className="inline-block w-0.5 h-3.5 bg-accent ml-0.5 align-middle"
style={{ animation: 'pulseDot 0.8s ease-in-out infinite' }} />
)}
</p>
)}
</div>
)}
{/* Copy button */}
{text && !error && (
<button
id="btn-ai-copy"
onClick={handleCopy}
className="mt-2 w-full text-[11px] py-2 rounded-lg bg-accent/20 text-accent-light
border border-accent/30 hover:bg-accent/35 transition-all font-medium"
>
{copied ? '✓ 已复制' : '📋 复制此话术'}
</button>
)}
</div>
);
}
+124
View File
@@ -0,0 +1,124 @@
import { useEffect, useRef, useState } from 'react';
import { CreateLibrary, DeleteLibrary, ImportCSV, ListLibraries, SwitchLibrary } from 'wailsjs/go/main/App';
import type { handler } from 'wailsjs/go/models';
interface LibraryBarProps {
activeName: string;
onSwitch: (name: string) => void;
}
export default function LibraryBar({ activeName, onSwitch }: LibraryBarProps) {
const [open, setOpen] = useState(false);
const [libs, setLibs] = useState<handler.LibraryInfo[]>([]);
const [creating, setCreating] = useState(false);
const [newName, setNewName] = useState('');
const [importing, setImporting] = useState(false);
const [msg, setMsg] = useState('');
const ref = useRef<HTMLDivElement>(null);
const load = async () => { setLibs(await ListLibraries()); };
useEffect(() => {
if (open) load();
}, [open]);
// Close on outside click
useEffect(() => {
const handler = (e: MouseEvent) => {
if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
};
document.addEventListener('mousedown', handler);
return () => document.removeEventListener('mousedown', handler);
}, []);
const handleSwitch = async (name: string) => {
await SwitchLibrary(name);
onSwitch(name);
setOpen(false);
};
const handleCreate = async () => {
if (!newName.trim()) return;
const err = await CreateLibrary(newName.trim(), '');
if (!err) { onSwitch(newName.trim()); setNewName(''); setCreating(false); load(); }
else setMsg(err);
};
const handleImport = async () => {
setImporting(true); setMsg('');
const result = await ImportCSV();
setImporting(false);
if (result.error && result.error !== '已取消') setMsg(result.error);
else if (result.imported > 0) { setMsg(`✓ 导入了 ${result.imported} 条(跳过 ${result.skipped} 条)`); load(); }
setTimeout(() => setMsg(''), 4000);
};
return (
<div ref={ref} className="relative px-4 pb-2">
{/* Button row */}
<div className="flex items-center gap-2">
<button onClick={() => setOpen(o => !o)}
className="flex-1 flex items-center gap-2 px-3 py-1.5 rounded-xl
bg-white/5 hover:bg-white/10 border border-white/8 transition-all text-left">
<span className="text-sm">📚</span>
<span className="text-[12px] text-white/80 truncate flex-1">{activeName || '选择知识库'}</span>
<span className="text-[10px] text-white/30">{open ? '▲' : '▾'}</span>
</button>
<button onClick={handleImport} disabled={importing} title="导入 CSV"
className="px-2.5 py-1.5 rounded-xl bg-accent/15 text-accent-light border border-accent/25
hover:bg-accent/25 transition-all text-[11px] font-medium disabled:opacity-50">
{importing ? '…' : '📥 导入'}
</button>
</div>
{msg && <p className={`text-[10px] mt-1 ${msg.startsWith('✓') ? 'text-green-400' : 'text-red-400'}`}>{msg}</p>}
{/* Dropdown */}
{open && (
<div className="absolute left-4 right-4 top-full mt-1 z-40
bg-[rgba(12,10,24,0.98)] border border-white/10 rounded-xl
shadow-2xl overflow-hidden animate-fade-in">
<div className="max-h-48 overflow-y-auto results-scroll">
{libs.map(lib => (
<div key={lib.id}
className={`flex items-center gap-2 px-3 py-2.5 cursor-pointer transition-colors
${lib.is_active ? 'bg-accent/15 border-l-2 border-accent' : 'hover:bg-white/5'}`}
onClick={() => handleSwitch(lib.name)}>
<span className="text-sm">{lib.is_active ? '✅' : '📁'}</span>
<div className="flex-1 min-w-0">
<p className="text-[12px] text-white/85 truncate">{lib.name}</p>
<p className="text-[10px] text-white/35">{lib.entry_count} </p>
</div>
{!lib.is_active && (
<button onClick={e => { e.stopPropagation(); DeleteLibrary(lib.name); load(); }}
className="text-white/20 hover:text-red-400 text-xs transition-colors"></button>
)}
</div>
))}
</div>
{/* Create new */}
<div className="border-t border-white/8 p-2">
{creating ? (
<div className="flex gap-2">
<input autoFocus className="flex-1 search-input text-[11px]" placeholder="知识库名称"
value={newName} onChange={e => setNewName(e.target.value)}
onKeyDown={e => e.key === 'Enter' && handleCreate()}
style={{ paddingLeft: '10px', paddingRight: '10px' }} />
<button onClick={handleCreate}
className="px-3 py-1.5 rounded-lg bg-accent text-white text-[11px]"></button>
<button onClick={() => setCreating(false)} className="text-white/30 text-xs"></button>
</div>
) : (
<button onClick={() => setCreating(true)}
className="w-full flex items-center gap-2 px-2 py-1.5 rounded-lg
text-[11px] text-white/50 hover:text-white/70 hover:bg-white/5 transition-all">
<span>+</span>
</button>
)}
</div>
</div>
)}
</div>
);
}
+95
View File
@@ -0,0 +1,95 @@
import { useState } from 'react';
import type { SearchResult } from '../hooks/useSearch';
interface ResultCardProps {
result: SearchResult;
onPolish: (result: SearchResult) => void;
}
const CATEGORY_COLORS: Record<string, string> = {
'通用': 'bg-indigo-500/20 text-indigo-300',
'退款': 'bg-red-500/20 text-red-300',
'物流': 'bg-amber-500/20 text-amber-300',
'产品': 'bg-emerald-500/20 text-emerald-300',
'促销': 'bg-pink-500/20 text-pink-300',
};
export default function ResultCard({ result, onPolish }: ResultCardProps) {
const [copied, setCopied] = useState(false);
const handleCopy = async () => {
try {
await navigator.clipboard.writeText(result.answer);
} catch {
// Wails fallback — plain execCommand
const el = document.createElement('textarea');
el.value = result.answer;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
setCopied(true);
setTimeout(() => setCopied(false), 1000);
};
const catColor = CATEGORY_COLORS[result.category] ?? 'bg-white/10 text-white/50';
return (
<div className={`result-card group relative ${result.is_fallback ? 'opacity-70' : ''}`} onClick={handleCopy}>
{/* Category badge + match indicator */}
<div className="flex items-center justify-between mb-2">
<span className={`text-[10px] font-medium px-2 py-0.5 rounded-full ${catColor}`}>
{result.category}
</span>
{result.is_fallback ? (
<span className="text-[10px] text-white/30 flex items-center gap-1">
🔥
</span>
) : result.score === 2 ? (
<span className="text-[10px] text-accent-light flex items-center gap-1">
</span>
) : null}
</div>
{/* Question */}
<p className="text-[12px] text-white/50 mb-1.5 line-clamp-1">
Q: {result.question}
</p>
{/* Answer */}
<p className="text-[13px] text-white/90 leading-relaxed line-clamp-3">
{result.answer}
</p>
{/* Hover action bar */}
<div className="flex items-center gap-2 mt-3 opacity-0 group-hover:opacity-100 transition-opacity">
<button
id={`btn-copy-${result.id}`}
onClick={e => { e.stopPropagation(); handleCopy(); }}
className="flex-1 text-[11px] py-1.5 rounded-lg bg-accent/20 text-accent-light border border-accent/30
hover:bg-accent/35 transition-all font-medium"
>
{copied ? '✓ 已复制' : '📋 复制'}
</button>
<button
id={`btn-polish-${result.id}`}
onClick={e => { e.stopPropagation(); onPolish(result); }}
className="flex-1 text-[11px] py-1.5 rounded-lg bg-white/5 text-white/60 border border-white/10
hover:bg-accent/15 hover:text-accent-light hover:border-accent/30 transition-all font-medium"
>
AI
</button>
</div>
{/* Copy toast */}
{copied && (
<div className="copy-toast absolute top-2 right-2 text-[10px] bg-green-500/20 text-green-400
border border-green-500/30 px-2 py-1 rounded-md pointer-events-none">
</div>
)}
</div>
);
}
+53
View File
@@ -0,0 +1,53 @@
import { useRef } from 'react';
interface SearchInputProps {
value: string;
onChange: (v: string) => void;
loading: boolean;
}
export default function SearchInput({ value, onChange, loading }: SearchInputProps) {
const inputRef = useRef<HTMLInputElement>(null);
return (
<div className="px-4 pt-4 pb-2 flex-shrink-0">
<div className="relative">
{/* Icon / spinner */}
<div className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 flex items-center justify-center">
{loading ? (
<svg className="animate-spin w-4 h-4 text-accent" viewBox="0 0 24 24" fill="none">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4"/>
<path className="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"/>
</svg>
) : (
<svg className="w-4 h-4 text-white/30" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
<circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/>
</svg>
)}
</div>
<input
ref={inputRef}
id="search-input"
className="search-input"
type="text"
placeholder="输入关键词搜索知识库…"
value={value}
onChange={e => onChange(e.target.value)}
style={{ userSelect: 'text' }}
/>
{/* Clear button */}
{value && (
<button
onClick={() => { onChange(''); inputRef.current?.focus(); }}
className="absolute right-3 top-1/2 -translate-y-1/2 text-white/30 hover:text-white/70 transition-colors text-xs"
>
</button>
)}
</div>
</div>
);
}
+138
View File
@@ -0,0 +1,138 @@
import { useEffect, useState } from 'react';
import { GetProviders, GetSettings, SaveSettings } from 'wailsjs/go/main/App';
import type { handler, service } from 'wailsjs/go/models';
interface SettingsModalProps {
onClose: () => void;
}
const EMPTY: service.SettingsDTO = {
ai_provider: 'deepseek', base_url: '', api_key: '',
model: 'deepseek-chat', system_prompt: '', max_tokens: 1024, use_public_key: true,
};
export default function SettingsModal({ onClose }: SettingsModalProps) {
const [form, setForm] = useState<service.SettingsDTO>(EMPTY);
const [providers, setProviders] = useState<handler.ProviderPreset[]>([]);
const [saving, setSaving] = useState(false);
const [msg, setMsg] = useState('');
useEffect(() => {
Promise.all([GetSettings(), GetProviders()]).then(([s, p]) => {
if (s) setForm(s);
setProviders(p);
});
}, []);
const set = (k: keyof service.SettingsDTO, v: unknown) =>
setForm(f => ({ ...f, [k]: v }));
const handleProviderChange = (providerId: string) => {
const preset = providers.find(p => p.id === providerId);
set('ai_provider', providerId);
if (preset?.base_url) set('base_url', preset.base_url);
if (preset?.default_model) set('model', preset.default_model);
};
const handleSave = async () => {
setSaving(true); setMsg('');
const err = await SaveSettings(form);
setMsg(err || '✓ 已保存');
setSaving(false);
if (!err) setTimeout(onClose, 800);
};
const inp = 'search-input text-[12px]';
const lbl = 'text-[10px] text-white/45 mb-1';
return (
<div className="fixed inset-0 z-50 flex items-end pb-2 px-2">
<div className="w-full bg-[rgba(14,12,28,0.97)] border border-white/10 rounded-2xl
shadow-2xl overflow-hidden animate-slide-in">
{/* Header */}
<div className="flex items-center justify-between px-4 py-3 border-b border-white/8">
<span className="text-[13px] font-semibold text-white"> AI </span>
<button onClick={onClose} className="text-white/30 hover:text-white/70 text-xs"></button>
</div>
<div className="px-4 py-3 flex flex-col gap-3 overflow-y-auto max-h-[480px] results-scroll">
{/* Public key toggle */}
<label className="flex items-center justify-between cursor-pointer">
<span className="text-[12px] text-white/70">使线 Key</span>
<div onClick={() => set('use_public_key', !form.use_public_key)}
className={`w-10 h-5 rounded-full transition-colors relative ${form.use_public_key ? 'bg-accent' : 'bg-white/15'}`}>
<div className={`absolute top-0.5 w-4 h-4 rounded-full bg-white shadow transition-transform
${form.use_public_key ? 'translate-x-5' : 'translate-x-0.5'}`} />
</div>
</label>
{!form.use_public_key && (<>
{/* Provider */}
<div>
<p className={lbl}>AI </p>
<select value={form.ai_provider} onChange={e => handleProviderChange(e.target.value)}
className={inp + ' w-full bg-white/6 border border-white/12 rounded-xl px-3 py-2'}>
{providers.map(p => <option key={p.id} value={p.id}>{p.label}</option>)}
</select>
</div>
{/* Base URL (shown for custom) */}
{form.ai_provider === 'custom' && (
<div>
<p className={lbl}>API (Base URL)</p>
<input className={inp} placeholder="https://your-api/v1/chat/completions"
value={form.base_url} onChange={e => set('base_url', e.target.value)}
style={{ paddingLeft: '14px' }} />
</div>
)}
{/* API Key */}
<div>
<p className={lbl}>API Key</p>
<input className={inp} type="password" placeholder="sk-..."
value={form.api_key} onChange={e => set('api_key', e.target.value)}
style={{ paddingLeft: '14px' }} />
</div>
{/* Model */}
<div>
<p className={lbl}></p>
<input className={inp} placeholder="deepseek-chat"
value={form.model} onChange={e => set('model', e.target.value)}
style={{ paddingLeft: '14px' }} />
</div>
{/* Max tokens */}
<div>
<p className={lbl}>Max Tokens: {form.max_tokens}</p>
<input type="range" min={256} max={4096} step={128}
value={form.max_tokens} onChange={e => set('max_tokens', Number(e.target.value))}
className="w-full accent-accent" />
</div>
</>)}
{/* System prompt (always visible) */}
<div>
<p className={lbl}>使 RAG </p>
<textarea value={form.system_prompt} onChange={e => set('system_prompt', e.target.value)}
rows={3} placeholder="你是一位专业客服顾问…"
className="w-full bg-white/6 border border-white/12 rounded-xl px-3 py-2
text-[12px] text-white/80 resize-none focus:outline-none
focus:border-accent/50 focus:shadow-[0_0_0_3px_rgba(124,110,247,0.2)]"
style={{ userSelect: 'text' }} />
</div>
</div>
{/* Footer */}
<div className="px-4 pb-3 flex items-center gap-2">
{msg && <span className={`text-[11px] flex-1 ${msg.startsWith('✓') ? 'text-green-400' : 'text-red-400'}`}>{msg}</span>}
<button onClick={handleSave} disabled={saving}
className="ml-auto px-5 py-2 rounded-xl bg-accent text-white text-[12px] font-semibold
hover:bg-accent-light transition-all disabled:opacity-50">
{saving ? '保存中…' : '保存'}
</button>
</div>
</div>
</div>
);
}
+61
View File
@@ -0,0 +1,61 @@
import { useState } from 'react';
import { ToggleTopmost } from 'wailsjs/go/main/App';
import { Quit, WindowMinimise } from 'wailsjs/runtime/runtime';
interface TitleBarProps {
dbReady: boolean;
onSettings: () => void;
}
export default function TitleBar({ dbReady, onSettings }: TitleBarProps) {
const [pinned, setPinned] = useState(true);
const handlePin = async () => {
const next = !pinned;
setPinned(next);
await ToggleTopmost(next);
};
return (
<div className="drag-region flex items-center justify-between px-4 py-3 flex-shrink-0 border-b border-white/5">
{/* Logo */}
<div className="flex items-center gap-2 select-none pointer-events-none">
<div className="w-7 h-7 rounded-lg bg-gradient-to-br from-accent to-accent-dark flex items-center justify-center shadow-lg">
<span className="text-white text-xs">🤖</span>
</div>
<div>
<p className="text-[12px] font-semibold text-white leading-tight">AI Expert Sidebar</p>
<div className="flex items-center gap-1">
<span className={`w-1.5 h-1.5 rounded-full ${dbReady ? 'bg-green-400' : 'bg-amber-400'}`}
style={{ boxShadow: dbReady ? '0 0 5px #4ade80' : '0 0 5px #fbbf24' }} />
<span className="text-[9px] text-white/35">{dbReady ? '本地 SQLite' : '初始化…'}</span>
</div>
</div>
</div>
{/* Controls */}
<div className="flex items-center gap-1" style={{ '--wails-draggable': 'no-drag' } as React.CSSProperties}>
<button id="btn-settings" onClick={onSettings} title="AI 设置"
className="w-7 h-7 rounded-md flex items-center justify-center text-sm text-white/40
hover:bg-white/10 hover:text-white/70 transition-all">
</button>
<button id="btn-pin" onClick={handlePin} title={pinned ? '取消置顶' : '置顶'}
className={`w-7 h-7 rounded-md flex items-center justify-center text-sm transition-all
${pinned ? 'bg-accent/30 text-accent-light border border-accent/40'
: 'text-white/40 hover:bg-white/10'}`}>
📌
</button>
<button id="btn-min" onClick={() => WindowMinimise()} title="最小化"
className="w-7 h-7 rounded-md flex items-center justify-center text-xs text-white/40 hover:bg-white/10 transition-all">
</button>
<button id="btn-quit" onClick={() => Quit()} title="退出"
className="w-7 h-7 rounded-md flex items-center justify-center text-xs text-white/40
hover:bg-red-500/20 hover:text-red-400 transition-all">
</button>
</div>
</div>
);
}
+47
View File
@@ -0,0 +1,47 @@
import { useEffect, useRef, useState, useCallback } from 'react';
import { SearchExpert } from 'wailsjs/go/main/App';
export interface SearchResult {
id: number;
question: string;
answer: string;
category: string;
score: number;
is_fallback: boolean;
}
export function useSearch(debounceMs = 300) {
const [query, setQuery] = useState('');
const [results, setResults] = useState<SearchResult[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const timerRef = useRef<ReturnType<typeof setTimeout>>();
const doSearch = useCallback(async (q: string) => {
if (!q.trim()) {
setResults([]);
setError(null);
return;
}
setLoading(true);
setError(null);
try {
const res = await SearchExpert(q) as SearchResult[] | null;
setResults(res ?? []);
} catch (e) {
console.error('[useSearch]', e);
setError('数据库连接失败,已进入本地基础库模式');
setResults([]);
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
clearTimeout(timerRef.current);
timerRef.current = setTimeout(() => doSearch(query), debounceMs);
return () => clearTimeout(timerRef.current);
}, [query, debounceMs, doSearch]);
return { query, setQuery, results, loading, error };
}
+138
View File
@@ -0,0 +1,138 @@
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
@tailwind base;
@tailwind components;
@tailwind utilities;
/* ── Global Reset ────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body, #root {
height: 100%;
margin: 0;
padding: 0;
font-family: 'Inter', system-ui, sans-serif;
-webkit-font-smoothing: antialiased;
}
body {
background: transparent;
color: #e8e5ff;
overflow: hidden;
user-select: none;
}
/* ── Glassmorphism Variables ─────────────────────────── */
:root {
--glass-bg: rgba(14, 12, 28, 0.88);
--glass-border: rgba(124, 110, 247, 0.25);
--glass-blur: 20px;
--accent: #7c6ef7;
--accent-light: #a599f9;
--accent-glow: rgba(124,110,247,0.3);
--danger: #ff5c7c;
--success: #4ade80;
--text-primary: #e8e5ff;
--text-muted: rgba(232,229,255,0.5);
--radius: 16px;
}
/* ── Root Container ──────────────────────────────────── */
.sidebar-root {
width: 350px;
height: 700px;
background: var(--glass-bg);
backdrop-filter: blur(var(--glass-blur)) saturate(180%);
-webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
border: 1px solid var(--glass-border);
border-radius: var(--radius);
display: flex;
flex-direction: column;
overflow: hidden;
position: relative;
}
/* ── Drag Region ─────────────────────────────────────── */
.drag-region {
--wails-draggable: drag;
cursor: grab;
}
.drag-region:active { cursor: grabbing; }
/* ── Scrollbar ───────────────────────────────────────── */
.results-scroll::-webkit-scrollbar { width: 4px; }
.results-scroll::-webkit-scrollbar-track { background: transparent; }
.results-scroll::-webkit-scrollbar-thumb {
background: var(--glass-border);
border-radius: 4px;
}
/* ── Card ────────────────────────────────────────────── */
.result-card {
background: rgba(255,255,255,0.04);
border: 1px solid rgba(255,255,255,0.08);
border-radius: 12px;
padding: 14px;
transition: all 0.2s ease;
cursor: pointer;
animation: slideIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
.result-card:hover {
background: rgba(124,110,247,0.12);
border-color: rgba(124,110,247,0.4);
transform: translateY(-1px);
box-shadow: 0 4px 20px var(--accent-glow);
}
.result-card:active { transform: translateY(0); }
/* ── Copy Toast ──────────────────────────────────────── */
.copy-toast {
animation: fadeIn 0.15s ease, fadeOut 0.15s ease 0.85s forwards;
}
@keyframes fadeOut { to { opacity: 0; transform: translateY(-4px); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } }
@keyframes slideIn { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:translateY(0); } }
/* ── Input ───────────────────────────────────────────── */
.search-input {
background: rgba(255,255,255,0.06);
border: 1px solid rgba(255,255,255,0.12);
border-radius: 10px;
color: var(--text-primary);
outline: none;
width: 100%;
padding: 10px 14px 10px 38px;
font-size: 14px;
transition: border-color 0.2s, box-shadow 0.2s;
}
.search-input:focus {
border-color: var(--accent);
box-shadow: 0 0 0 3px var(--accent-glow);
}
.search-input::placeholder { color: var(--text-muted); }
/* ── AI Panel ────────────────────────────────────────── */
.ai-panel {
background: rgba(124,110,247,0.07);
border: 1px solid rgba(124,110,247,0.2);
border-radius: 12px;
padding: 14px;
font-size: 13px;
line-height: 1.7;
color: var(--text-primary);
min-height: 80px;
white-space: pre-wrap;
word-break: break-word;
}
/* ── Gradient Orbs ───────────────────────────────────── */
.orb {
position: absolute;
border-radius: 50%;
filter: blur(60px);
pointer-events: none;
opacity: 0.18;
z-index: 0;
}
.orb-purple { width:200px; height:200px; background:#7c6ef7; top:-60px; right:-60px; }
.orb-blue { width:160px; height:160px; background:#38bdf8; bottom:-40px; left:-40px; }
+10
View File
@@ -0,0 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import './index.css'
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
+26
View File
@@ -0,0 +1,26 @@
html {
background-color: rgba(27, 38, 54, 1);
text-align: center;
color: white;
}
body {
margin: 0;
color: white;
font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
"Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
}
@font-face {
font-family: "Nunito";
font-style: normal;
font-weight: 400;
src: local(""),
url("assets/fonts/nunito-v16-latin-regular.woff2") format("woff2");
}
#app {
height: 100vh;
text-align: center;
}
+1
View File
@@ -0,0 +1 @@
/// <reference types="vite/client" />
+35
View File
@@ -0,0 +1,35 @@
/** @type {import('tailwindcss').Config} */
export default {
content: ["./index.html", "./src/**/*.{ts,tsx}"],
theme: {
extend: {
fontFamily: {
sans: ["Inter", "system-ui", "sans-serif"],
},
colors: {
accent: {
DEFAULT: "#7c6ef7",
light: "#a599f9",
dark: "#5b4de0",
},
surface: {
DEFAULT: "rgba(18, 16, 32, 0.92)",
card: "rgba(255,255,255,0.05)",
hover: "rgba(255,255,255,0.09)",
},
},
animation: {
"fade-in": "fadeIn 0.25s ease",
"slide-in": "slideIn 0.3s cubic-bezier(0.34,1.56,0.64,1)",
"pulse-dot": "pulseDot 1.4s ease-in-out infinite",
"typewriter":"typewriter 0.04s steps(1) forwards",
},
keyframes: {
fadeIn: { from: { opacity: 0 }, to: { opacity: 1 } },
slideIn: { from: { opacity: 0, transform: "translateY(10px)" }, to: { opacity: 1, transform: "translateY(0)" } },
pulseDot: { "0%,100%": { opacity: 0.3 }, "50%": { opacity: 1 } },
},
},
},
plugins: [],
};
+37
View File
@@ -0,0 +1,37 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"baseUrl": ".",
"paths": {
"../wailsjs/*": ["wailsjs/*"],
"../../wailsjs/*": ["wailsjs/*"]
},
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src",
"wailsjs"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}
+11
View File
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
},
"include": [
"vite.config.ts"
]
}
+14
View File
@@ -0,0 +1,14 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
// Allow "wailsjs/..." absolute imports to resolve to ../wailsjs/
'wailsjs': path.resolve(__dirname, 'wailsjs'),
},
},
})
+32
View File
@@ -0,0 +1,32 @@
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
import {handler} from '../models';
import {service} from '../models';
export function AskDeepSeek(arg1:string,arg2:string):Promise<string>;
export function CreateLibrary(arg1:string,arg2:string):Promise<string>;
export function DeleteLibrary(arg1:string):Promise<string>;
export function GetActiveLibrary():Promise<string>;
export function GetDBStatus():Promise<boolean>;
export function GetProviders():Promise<Array<handler.ProviderPreset>>;
export function GetSettings():Promise<service.SettingsDTO>;
export function ImportCSV():Promise<service.ImportResult>;
export function ListLibraries():Promise<Array<handler.LibraryInfo>>;
export function SaveSettings(arg1:service.SettingsDTO):Promise<string>;
export function SearchExpert(arg1:string):Promise<any>;
export function StopGeneration():Promise<void>;
export function SwitchLibrary(arg1:string):Promise<string>;
export function ToggleTopmost(arg1:boolean):Promise<void>;
+59
View File
@@ -0,0 +1,59 @@
// @ts-check
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
// This file is automatically generated. DO NOT EDIT
export function AskDeepSeek(arg1, arg2) {
return window['go']['main']['App']['AskDeepSeek'](arg1, arg2);
}
export function CreateLibrary(arg1, arg2) {
return window['go']['main']['App']['CreateLibrary'](arg1, arg2);
}
export function DeleteLibrary(arg1) {
return window['go']['main']['App']['DeleteLibrary'](arg1);
}
export function GetActiveLibrary() {
return window['go']['main']['App']['GetActiveLibrary']();
}
export function GetDBStatus() {
return window['go']['main']['App']['GetDBStatus']();
}
export function GetProviders() {
return window['go']['main']['App']['GetProviders']();
}
export function GetSettings() {
return window['go']['main']['App']['GetSettings']();
}
export function ImportCSV() {
return window['go']['main']['App']['ImportCSV']();
}
export function ListLibraries() {
return window['go']['main']['App']['ListLibraries']();
}
export function SaveSettings(arg1) {
return window['go']['main']['App']['SaveSettings'](arg1);
}
export function SearchExpert(arg1) {
return window['go']['main']['App']['SearchExpert'](arg1);
}
export function StopGeneration() {
return window['go']['main']['App']['StopGeneration']();
}
export function SwitchLibrary(arg1) {
return window['go']['main']['App']['SwitchLibrary'](arg1);
}
export function ToggleTopmost(arg1) {
return window['go']['main']['App']['ToggleTopmost'](arg1);
}
+88
View File
@@ -0,0 +1,88 @@
export namespace handler {
export class LibraryInfo {
id: number;
name: string;
description: string;
entry_count: number;
is_active: boolean;
static createFrom(source: any = {}) {
return new LibraryInfo(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.id = source["id"];
this.name = source["name"];
this.description = source["description"];
this.entry_count = source["entry_count"];
this.is_active = source["is_active"];
}
}
export class ProviderPreset {
id: string;
label: string;
base_url: string;
default_model: string;
static createFrom(source: any = {}) {
return new ProviderPreset(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.id = source["id"];
this.label = source["label"];
this.base_url = source["base_url"];
this.default_model = source["default_model"];
}
}
}
export namespace service {
export class ImportResult {
imported: number;
skipped: number;
error?: string;
static createFrom(source: any = {}) {
return new ImportResult(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.imported = source["imported"];
this.skipped = source["skipped"];
this.error = source["error"];
}
}
export class SettingsDTO {
ai_provider: string;
base_url: string;
api_key: string;
model: string;
system_prompt: string;
max_tokens: number;
use_public_key: boolean;
static createFrom(source: any = {}) {
return new SettingsDTO(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
this.ai_provider = source["ai_provider"];
this.base_url = source["base_url"];
this.api_key = source["api_key"];
this.model = source["model"];
this.system_prompt = source["system_prompt"];
this.max_tokens = source["max_tokens"];
this.use_public_key = source["use_public_key"];
}
}
}
+24
View File
@@ -0,0 +1,24 @@
{
"name": "@wailsapp/runtime",
"version": "2.0.0",
"description": "Wails Javascript runtime library",
"main": "runtime.js",
"types": "runtime.d.ts",
"scripts": {
},
"repository": {
"type": "git",
"url": "git+https://github.com/wailsapp/wails.git"
},
"keywords": [
"Wails",
"Javascript",
"Go"
],
"author": "Lea Anthony <lea.anthony@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/wailsapp/wails/issues"
},
"homepage": "https://github.com/wailsapp/wails#readme"
}
+330
View File
@@ -0,0 +1,330 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
export interface Position {
x: number;
y: number;
}
export interface Size {
w: number;
h: number;
}
export interface Screen {
isCurrent: boolean;
isPrimary: boolean;
width : number
height : number
}
// Environment information such as platform, buildtype, ...
export interface EnvironmentInfo {
buildType: string;
platform: string;
arch: string;
}
// [EventsEmit](https://wails.io/docs/reference/runtime/events#eventsemit)
// emits the given event. Optional data may be passed with the event.
// This will trigger any event listeners.
export function EventsEmit(eventName: string, ...data: any): void;
// [EventsOn](https://wails.io/docs/reference/runtime/events#eventson) sets up a listener for the given event name.
export function EventsOn(eventName: string, callback: (...data: any) => void): () => void;
// [EventsOnMultiple](https://wails.io/docs/reference/runtime/events#eventsonmultiple)
// sets up a listener for the given event name, but will only trigger a given number times.
export function EventsOnMultiple(eventName: string, callback: (...data: any) => void, maxCallbacks: number): () => void;
// [EventsOnce](https://wails.io/docs/reference/runtime/events#eventsonce)
// sets up a listener for the given event name, but will only trigger once.
export function EventsOnce(eventName: string, callback: (...data: any) => void): () => void;
// [EventsOff](https://wails.io/docs/reference/runtime/events#eventsoff)
// unregisters the listener for the given event name.
export function EventsOff(eventName: string, ...additionalEventNames: string[]): void;
// [EventsOffAll](https://wails.io/docs/reference/runtime/events#eventsoffall)
// unregisters all listeners.
export function EventsOffAll(): void;
// [LogPrint](https://wails.io/docs/reference/runtime/log#logprint)
// logs the given message as a raw message
export function LogPrint(message: string): void;
// [LogTrace](https://wails.io/docs/reference/runtime/log#logtrace)
// logs the given message at the `trace` log level.
export function LogTrace(message: string): void;
// [LogDebug](https://wails.io/docs/reference/runtime/log#logdebug)
// logs the given message at the `debug` log level.
export function LogDebug(message: string): void;
// [LogError](https://wails.io/docs/reference/runtime/log#logerror)
// logs the given message at the `error` log level.
export function LogError(message: string): void;
// [LogFatal](https://wails.io/docs/reference/runtime/log#logfatal)
// logs the given message at the `fatal` log level.
// The application will quit after calling this method.
export function LogFatal(message: string): void;
// [LogInfo](https://wails.io/docs/reference/runtime/log#loginfo)
// logs the given message at the `info` log level.
export function LogInfo(message: string): void;
// [LogWarning](https://wails.io/docs/reference/runtime/log#logwarning)
// logs the given message at the `warning` log level.
export function LogWarning(message: string): void;
// [WindowReload](https://wails.io/docs/reference/runtime/window#windowreload)
// Forces a reload by the main application as well as connected browsers.
export function WindowReload(): void;
// [WindowReloadApp](https://wails.io/docs/reference/runtime/window#windowreloadapp)
// Reloads the application frontend.
export function WindowReloadApp(): void;
// [WindowSetAlwaysOnTop](https://wails.io/docs/reference/runtime/window#windowsetalwaysontop)
// Sets the window AlwaysOnTop or not on top.
export function WindowSetAlwaysOnTop(b: boolean): void;
// [WindowSetSystemDefaultTheme](https://wails.io/docs/next/reference/runtime/window#windowsetsystemdefaulttheme)
// *Windows only*
// Sets window theme to system default (dark/light).
export function WindowSetSystemDefaultTheme(): void;
// [WindowSetLightTheme](https://wails.io/docs/next/reference/runtime/window#windowsetlighttheme)
// *Windows only*
// Sets window to light theme.
export function WindowSetLightTheme(): void;
// [WindowSetDarkTheme](https://wails.io/docs/next/reference/runtime/window#windowsetdarktheme)
// *Windows only*
// Sets window to dark theme.
export function WindowSetDarkTheme(): void;
// [WindowCenter](https://wails.io/docs/reference/runtime/window#windowcenter)
// Centers the window on the monitor the window is currently on.
export function WindowCenter(): void;
// [WindowSetTitle](https://wails.io/docs/reference/runtime/window#windowsettitle)
// Sets the text in the window title bar.
export function WindowSetTitle(title: string): void;
// [WindowFullscreen](https://wails.io/docs/reference/runtime/window#windowfullscreen)
// Makes the window full screen.
export function WindowFullscreen(): void;
// [WindowUnfullscreen](https://wails.io/docs/reference/runtime/window#windowunfullscreen)
// Restores the previous window dimensions and position prior to full screen.
export function WindowUnfullscreen(): void;
// [WindowIsFullscreen](https://wails.io/docs/reference/runtime/window#windowisfullscreen)
// Returns the state of the window, i.e. whether the window is in full screen mode or not.
export function WindowIsFullscreen(): Promise<boolean>;
// [WindowSetSize](https://wails.io/docs/reference/runtime/window#windowsetsize)
// Sets the width and height of the window.
export function WindowSetSize(width: number, height: number): void;
// [WindowGetSize](https://wails.io/docs/reference/runtime/window#windowgetsize)
// Gets the width and height of the window.
export function WindowGetSize(): Promise<Size>;
// [WindowSetMaxSize](https://wails.io/docs/reference/runtime/window#windowsetmaxsize)
// Sets the maximum window size. Will resize the window if the window is currently larger than the given dimensions.
// Setting a size of 0,0 will disable this constraint.
export function WindowSetMaxSize(width: number, height: number): void;
// [WindowSetMinSize](https://wails.io/docs/reference/runtime/window#windowsetminsize)
// Sets the minimum window size. Will resize the window if the window is currently smaller than the given dimensions.
// Setting a size of 0,0 will disable this constraint.
export function WindowSetMinSize(width: number, height: number): void;
// [WindowSetPosition](https://wails.io/docs/reference/runtime/window#windowsetposition)
// Sets the window position relative to the monitor the window is currently on.
export function WindowSetPosition(x: number, y: number): void;
// [WindowGetPosition](https://wails.io/docs/reference/runtime/window#windowgetposition)
// Gets the window position relative to the monitor the window is currently on.
export function WindowGetPosition(): Promise<Position>;
// [WindowHide](https://wails.io/docs/reference/runtime/window#windowhide)
// Hides the window.
export function WindowHide(): void;
// [WindowShow](https://wails.io/docs/reference/runtime/window#windowshow)
// Shows the window, if it is currently hidden.
export function WindowShow(): void;
// [WindowMaximise](https://wails.io/docs/reference/runtime/window#windowmaximise)
// Maximises the window to fill the screen.
export function WindowMaximise(): void;
// [WindowToggleMaximise](https://wails.io/docs/reference/runtime/window#windowtogglemaximise)
// Toggles between Maximised and UnMaximised.
export function WindowToggleMaximise(): void;
// [WindowUnmaximise](https://wails.io/docs/reference/runtime/window#windowunmaximise)
// Restores the window to the dimensions and position prior to maximising.
export function WindowUnmaximise(): void;
// [WindowIsMaximised](https://wails.io/docs/reference/runtime/window#windowismaximised)
// Returns the state of the window, i.e. whether the window is maximised or not.
export function WindowIsMaximised(): Promise<boolean>;
// [WindowMinimise](https://wails.io/docs/reference/runtime/window#windowminimise)
// Minimises the window.
export function WindowMinimise(): void;
// [WindowUnminimise](https://wails.io/docs/reference/runtime/window#windowunminimise)
// Restores the window to the dimensions and position prior to minimising.
export function WindowUnminimise(): void;
// [WindowIsMinimised](https://wails.io/docs/reference/runtime/window#windowisminimised)
// Returns the state of the window, i.e. whether the window is minimised or not.
export function WindowIsMinimised(): Promise<boolean>;
// [WindowIsNormal](https://wails.io/docs/reference/runtime/window#windowisnormal)
// Returns the state of the window, i.e. whether the window is normal or not.
export function WindowIsNormal(): Promise<boolean>;
// [WindowSetBackgroundColour](https://wails.io/docs/reference/runtime/window#windowsetbackgroundcolour)
// Sets the background colour of the window to the given RGBA colour definition. This colour will show through for all transparent pixels.
export function WindowSetBackgroundColour(R: number, G: number, B: number, A: number): void;
// [ScreenGetAll](https://wails.io/docs/reference/runtime/window#screengetall)
// Gets the all screens. Call this anew each time you want to refresh data from the underlying windowing system.
export function ScreenGetAll(): Promise<Screen[]>;
// [BrowserOpenURL](https://wails.io/docs/reference/runtime/browser#browseropenurl)
// Opens the given URL in the system browser.
export function BrowserOpenURL(url: string): void;
// [Environment](https://wails.io/docs/reference/runtime/intro#environment)
// Returns information about the environment
export function Environment(): Promise<EnvironmentInfo>;
// [Quit](https://wails.io/docs/reference/runtime/intro#quit)
// Quits the application.
export function Quit(): void;
// [Hide](https://wails.io/docs/reference/runtime/intro#hide)
// Hides the application.
export function Hide(): void;
// [Show](https://wails.io/docs/reference/runtime/intro#show)
// Shows the application.
export function Show(): void;
// [ClipboardGetText](https://wails.io/docs/reference/runtime/clipboard#clipboardgettext)
// Returns the current text stored on clipboard
export function ClipboardGetText(): Promise<string>;
// [ClipboardSetText](https://wails.io/docs/reference/runtime/clipboard#clipboardsettext)
// Sets a text on the clipboard
export function ClipboardSetText(text: string): Promise<boolean>;
// [OnFileDrop](https://wails.io/docs/reference/runtime/draganddrop#onfiledrop)
// OnFileDrop listens to drag and drop events and calls the callback with the coordinates of the drop and an array of path strings.
export function OnFileDrop(callback: (x: number, y: number ,paths: string[]) => void, useDropTarget: boolean) :void
// [OnFileDropOff](https://wails.io/docs/reference/runtime/draganddrop#dragandddropoff)
// OnFileDropOff removes the drag and drop listeners and handlers.
export function OnFileDropOff() :void
// Check if the file path resolver is available
export function CanResolveFilePaths(): boolean;
// Resolves file paths for an array of files
export function ResolveFilePaths(files: File[]): void
// Notification types
export interface NotificationOptions {
id: string;
title: string;
subtitle?: string; // macOS and Linux only
body?: string;
categoryId?: string;
data?: { [key: string]: any };
}
export interface NotificationAction {
id?: string;
title?: string;
destructive?: boolean; // macOS-specific
}
export interface NotificationCategory {
id?: string;
actions?: NotificationAction[];
hasReplyField?: boolean;
replyPlaceholder?: string;
replyButtonTitle?: string;
}
// [InitializeNotifications](https://wails.io/docs/reference/runtime/notification#initializenotifications)
// Initializes the notification service for the application.
// This must be called before sending any notifications.
export function InitializeNotifications(): Promise<void>;
// [CleanupNotifications](https://wails.io/docs/reference/runtime/notification#cleanupnotifications)
// Cleans up notification resources and releases any held connections.
export function CleanupNotifications(): Promise<void>;
// [IsNotificationAvailable](https://wails.io/docs/reference/runtime/notification#isnotificationavailable)
// Checks if notifications are available on the current platform.
export function IsNotificationAvailable(): Promise<boolean>;
// [RequestNotificationAuthorization](https://wails.io/docs/reference/runtime/notification#requestnotificationauthorization)
// Requests notification authorization from the user (macOS only).
export function RequestNotificationAuthorization(): Promise<boolean>;
// [CheckNotificationAuthorization](https://wails.io/docs/reference/runtime/notification#checknotificationauthorization)
// Checks the current notification authorization status (macOS only).
export function CheckNotificationAuthorization(): Promise<boolean>;
// [SendNotification](https://wails.io/docs/reference/runtime/notification#sendnotification)
// Sends a basic notification with the given options.
export function SendNotification(options: NotificationOptions): Promise<void>;
// [SendNotificationWithActions](https://wails.io/docs/reference/runtime/notification#sendnotificationwithactions)
// Sends a notification with action buttons. Requires a registered category.
export function SendNotificationWithActions(options: NotificationOptions): Promise<void>;
// [RegisterNotificationCategory](https://wails.io/docs/reference/runtime/notification#registernotificationcategory)
// Registers a notification category that can be used with SendNotificationWithActions.
export function RegisterNotificationCategory(category: NotificationCategory): Promise<void>;
// [RemoveNotificationCategory](https://wails.io/docs/reference/runtime/notification#removenotificationcategory)
// Removes a previously registered notification category.
export function RemoveNotificationCategory(categoryId: string): Promise<void>;
// [RemoveAllPendingNotifications](https://wails.io/docs/reference/runtime/notification#removeallpendingnotifications)
// Removes all pending notifications from the notification center.
export function RemoveAllPendingNotifications(): Promise<void>;
// [RemovePendingNotification](https://wails.io/docs/reference/runtime/notification#removependingnotification)
// Removes a specific pending notification by its identifier.
export function RemovePendingNotification(identifier: string): Promise<void>;
// [RemoveAllDeliveredNotifications](https://wails.io/docs/reference/runtime/notification#removealldeliverednotifications)
// Removes all delivered notifications from the notification center.
export function RemoveAllDeliveredNotifications(): Promise<void>;
// [RemoveDeliveredNotification](https://wails.io/docs/reference/runtime/notification#removedeliverednotification)
// Removes a specific delivered notification by its identifier.
export function RemoveDeliveredNotification(identifier: string): Promise<void>;
// [RemoveNotification](https://wails.io/docs/reference/runtime/notification#removenotification)
// Removes a notification by its identifier (cross-platform convenience function).
export function RemoveNotification(identifier: string): Promise<void>;
+298
View File
@@ -0,0 +1,298 @@
/*
_ __ _ __
| | / /___ _(_) /____
| | /| / / __ `/ / / ___/
| |/ |/ / /_/ / / (__ )
|__/|__/\__,_/_/_/____/
The electron alternative for Go
(c) Lea Anthony 2019-present
*/
export function LogPrint(message) {
window.runtime.LogPrint(message);
}
export function LogTrace(message) {
window.runtime.LogTrace(message);
}
export function LogDebug(message) {
window.runtime.LogDebug(message);
}
export function LogInfo(message) {
window.runtime.LogInfo(message);
}
export function LogWarning(message) {
window.runtime.LogWarning(message);
}
export function LogError(message) {
window.runtime.LogError(message);
}
export function LogFatal(message) {
window.runtime.LogFatal(message);
}
export function EventsOnMultiple(eventName, callback, maxCallbacks) {
return window.runtime.EventsOnMultiple(eventName, callback, maxCallbacks);
}
export function EventsOn(eventName, callback) {
return EventsOnMultiple(eventName, callback, -1);
}
export function EventsOff(eventName, ...additionalEventNames) {
return window.runtime.EventsOff(eventName, ...additionalEventNames);
}
export function EventsOffAll() {
return window.runtime.EventsOffAll();
}
export function EventsOnce(eventName, callback) {
return EventsOnMultiple(eventName, callback, 1);
}
export function EventsEmit(eventName) {
let args = [eventName].slice.call(arguments);
return window.runtime.EventsEmit.apply(null, args);
}
export function WindowReload() {
window.runtime.WindowReload();
}
export function WindowReloadApp() {
window.runtime.WindowReloadApp();
}
export function WindowSetAlwaysOnTop(b) {
window.runtime.WindowSetAlwaysOnTop(b);
}
export function WindowSetSystemDefaultTheme() {
window.runtime.WindowSetSystemDefaultTheme();
}
export function WindowSetLightTheme() {
window.runtime.WindowSetLightTheme();
}
export function WindowSetDarkTheme() {
window.runtime.WindowSetDarkTheme();
}
export function WindowCenter() {
window.runtime.WindowCenter();
}
export function WindowSetTitle(title) {
window.runtime.WindowSetTitle(title);
}
export function WindowFullscreen() {
window.runtime.WindowFullscreen();
}
export function WindowUnfullscreen() {
window.runtime.WindowUnfullscreen();
}
export function WindowIsFullscreen() {
return window.runtime.WindowIsFullscreen();
}
export function WindowGetSize() {
return window.runtime.WindowGetSize();
}
export function WindowSetSize(width, height) {
window.runtime.WindowSetSize(width, height);
}
export function WindowSetMaxSize(width, height) {
window.runtime.WindowSetMaxSize(width, height);
}
export function WindowSetMinSize(width, height) {
window.runtime.WindowSetMinSize(width, height);
}
export function WindowSetPosition(x, y) {
window.runtime.WindowSetPosition(x, y);
}
export function WindowGetPosition() {
return window.runtime.WindowGetPosition();
}
export function WindowHide() {
window.runtime.WindowHide();
}
export function WindowShow() {
window.runtime.WindowShow();
}
export function WindowMaximise() {
window.runtime.WindowMaximise();
}
export function WindowToggleMaximise() {
window.runtime.WindowToggleMaximise();
}
export function WindowUnmaximise() {
window.runtime.WindowUnmaximise();
}
export function WindowIsMaximised() {
return window.runtime.WindowIsMaximised();
}
export function WindowMinimise() {
window.runtime.WindowMinimise();
}
export function WindowUnminimise() {
window.runtime.WindowUnminimise();
}
export function WindowSetBackgroundColour(R, G, B, A) {
window.runtime.WindowSetBackgroundColour(R, G, B, A);
}
export function ScreenGetAll() {
return window.runtime.ScreenGetAll();
}
export function WindowIsMinimised() {
return window.runtime.WindowIsMinimised();
}
export function WindowIsNormal() {
return window.runtime.WindowIsNormal();
}
export function BrowserOpenURL(url) {
window.runtime.BrowserOpenURL(url);
}
export function Environment() {
return window.runtime.Environment();
}
export function Quit() {
window.runtime.Quit();
}
export function Hide() {
window.runtime.Hide();
}
export function Show() {
window.runtime.Show();
}
export function ClipboardGetText() {
return window.runtime.ClipboardGetText();
}
export function ClipboardSetText(text) {
return window.runtime.ClipboardSetText(text);
}
/**
* Callback for OnFileDrop returns a slice of file path strings when a drop is finished.
*
* @export
* @callback OnFileDropCallback
* @param {number} x - x coordinate of the drop
* @param {number} y - y coordinate of the drop
* @param {string[]} paths - A list of file paths.
*/
/**
* OnFileDrop listens to drag and drop events and calls the callback with the coordinates of the drop and an array of path strings.
*
* @export
* @param {OnFileDropCallback} callback - Callback for OnFileDrop returns a slice of file path strings when a drop is finished.
* @param {boolean} [useDropTarget=true] - Only call the callback when the drop finished on an element that has the drop target style. (--wails-drop-target)
*/
export function OnFileDrop(callback, useDropTarget) {
return window.runtime.OnFileDrop(callback, useDropTarget);
}
/**
* OnFileDropOff removes the drag and drop listeners and handlers.
*/
export function OnFileDropOff() {
return window.runtime.OnFileDropOff();
}
export function CanResolveFilePaths() {
return window.runtime.CanResolveFilePaths();
}
export function ResolveFilePaths(files) {
return window.runtime.ResolveFilePaths(files);
}
export function InitializeNotifications() {
return window.runtime.InitializeNotifications();
}
export function CleanupNotifications() {
return window.runtime.CleanupNotifications();
}
export function IsNotificationAvailable() {
return window.runtime.IsNotificationAvailable();
}
export function RequestNotificationAuthorization() {
return window.runtime.RequestNotificationAuthorization();
}
export function CheckNotificationAuthorization() {
return window.runtime.CheckNotificationAuthorization();
}
export function SendNotification(options) {
return window.runtime.SendNotification(options);
}
export function SendNotificationWithActions(options) {
return window.runtime.SendNotificationWithActions(options);
}
export function RegisterNotificationCategory(category) {
return window.runtime.RegisterNotificationCategory(category);
}
export function RemoveNotificationCategory(categoryId) {
return window.runtime.RemoveNotificationCategory(categoryId);
}
export function RemoveAllPendingNotifications() {
return window.runtime.RemoveAllPendingNotifications();
}
export function RemovePendingNotification(identifier) {
return window.runtime.RemovePendingNotification(identifier);
}
export function RemoveAllDeliveredNotifications() {
return window.runtime.RemoveAllDeliveredNotifications();
}
export function RemoveDeliveredNotification(identifier) {
return window.runtime.RemoveDeliveredNotification(identifier);
}
export function RemoveNotification(identifier) {
return window.runtime.RemoveNotification(identifier);
}