Add new hotkey functionalitys

This commit is contained in:
kwaroran
2025-03-21 10:28:10 +09:00
parent 46b50c6d56
commit 9fd188f235
5 changed files with 123 additions and 26 deletions

View File

@@ -0,0 +1,29 @@
<script lang="ts">
import { BotIcon, PackageIcon, Sailboat, UserIcon } from "lucide-svelte";
import { QuickSettings } from "src/ts/stores.svelte";
import BotSettings from "../Setting/Pages/BotSettings.svelte";
import OtherBotSettings from "../Setting/Pages/OtherBotSettings.svelte";
import ModuleSettings from "../Setting/Pages/Module/ModuleSettings.svelte";
</script>
<div class="flex mb-2 gap-2">
<button class={QuickSettings.index === 0 ? 'text-textcolor ' : 'text-textcolor2'} onclick={() => {QuickSettings.index = 0}}>
<BotIcon />
</button>
<button class={QuickSettings.index === 1 ? 'text-textcolor ' : 'text-textcolor2'} onclick={() => {QuickSettings.index = 1}}>
<Sailboat />
</button>
<button class={QuickSettings.index === 2 ? 'text-textcolor ' : 'text-textcolor2'} onclick={() => {QuickSettings.index = 2}}>
<PackageIcon />
</button>
</div>
<div class="py-6 px-4 flex flex-col text-textcolor overflow-y-auto relative rs-setting-cont-5">
{#if QuickSettings.index === 0}
<BotSettings />
{:else if QuickSettings.index === 1}
<OtherBotSettings />
{:else if QuickSettings.index === 2}
<ModuleSettings />
{/if}
</div>

View File

@@ -8,7 +8,10 @@
sideBarClosing,
sideBarStore,
OpenRealmStore,
PlaygroundStore
PlaygroundStore,
QuickSettings
} from "../../ts/stores.svelte";
import { setDatabase, type folder } from "../../ts/storage/database.svelte";
import { DBState } from 'src/ts/stores.svelte';
@@ -45,6 +48,7 @@
import { ConnectionIsHost, ConnectionOpenStore, RoomIdStore } from "src/ts/sync/multiuser";
import { sideBarSize } from "src/ts/gui/guisize";
import DevTool from "./DevTool.svelte";
import QuickSettingsGui from "../Others/QuickSettingsGUI.svelte";
let sideBarMode = $state(0);
let editMode = $state(false);
let menuMode = $state(0);
@@ -751,7 +755,9 @@
</button>
{/if}
</div>
{#if devTool}
{#if QuickSettings.open}
<QuickSettingsGui />
{:else if devTool}
<DevTool />
{:else if $botMakerMode}
<CharConfig />

View File

@@ -119,16 +119,6 @@ export const defaultHotkeys: Hotkey[] = [
ctrl: true,
action: 'previewRequest'
},
{
key: 'i',
ctrl: true,
action: 'import'
},
{
key: 'x',
ctrl: true,
action: 'export'
},
{
key: 'w',
ctrl: true,

View File

@@ -1,10 +1,12 @@
import { get } from "svelte/store"
import { alertSelect, alertToast, doingAlert } from "./alert"
import { alertMd, alertSelect, alertToast, alertWait, doingAlert } from "./alert"
import { changeToPreset as changeToPreset2, getDatabase } from "./storage/database.svelte"
import { alertStore, MobileGUIStack, MobileSideBar, openPersonaList, openPresetList, SafeModeStore, selectedCharID, settingsOpen } from "./stores.svelte"
import { alertStore, MobileGUIStack, MobileSideBar, openPersonaList, openPresetList, OpenRealmStore, PlaygroundStore, QuickSettings, SafeModeStore, selectedCharID, settingsOpen } from "./stores.svelte"
import { language } from "src/lang"
import { updateTextThemeAndCSS } from "./gui/colorscheme"
import { defaultHotkeys } from "./defaulthotkeys"
import { doingChat, previewBody, sendChat } from "./process/index.svelte"
import { getRequestLog } from "./globalApi.svelte"
export function initHotkey(){
document.addEventListener('keydown', (ev) => {
@@ -111,6 +113,67 @@ export function initHotkey(){
updateTextThemeAndCSS()
break
}
case 'prevChar':{
const sorted = database.characters.map((v, i) => {
return {name: v.name, i}
}).sort((a, b) => a.name.localeCompare(b.name))
const currentIndex = sorted.findIndex(v => v.i === get(selectedCharID))
if(currentIndex === 0){
return
}
if(currentIndex >= sorted.length - 1){
return
}
selectedCharID.set(sorted[currentIndex - 1].i)
PlaygroundStore.set(0)
OpenRealmStore.set(false)
break
}
case 'nextChar':{
const sorted = database.characters.map((v, i) => {
return {name: v.name, i}
}).sort((a, b) => a.name.localeCompare(b.name))
const currentIndex = sorted.findIndex(v => v.i === get(selectedCharID))
if(currentIndex === 0){
return
}
if(currentIndex >= sorted.length - 1){
return
}
selectedCharID.set(sorted[currentIndex + 1].i)
PlaygroundStore.set(0)
OpenRealmStore.set(false)
break
}
case 'quickMenu':{
quickMenu()
break
}
case 'previewRequest':{
if(get(doingChat) && get(selectedCharID) !== -1){
return false
}
alertWait("Loading...")
sendChat(-1, {
previewPrompt: true
})
let md = ''
md += '### Prompt\n'
md += '```json\n' + JSON.stringify(JSON.parse(previewBody), null, 2).replaceAll('```', '\\`\\`\\`') + '\n```\n'
doingChat.set(false)
alertMd(md)
break
}
case 'toggleLog':{
alertMd(getRequestLog())
break
}
case 'quickSettings':{
QuickSettings.open = !QuickSettings.open
QuickSettings.index = 0
break
}
default:{
hotKeyRanThisTime = false
}
@@ -221,18 +284,7 @@ export function initHotkey(){
if(doingAlert()){
return
}
const selStr = await alertSelect([
language.presets,
language.persona,
language.cancel
])
const sel = parseInt(selStr)
if(sel === 0){
openPresetList.set(!get(openPresetList))
}
if(sel === 1){
openPersonaList.set(!get(openPersonaList))
}
quickMenu()
}
if(touchs === 1){
touchStartTime = Date.now()
@@ -243,6 +295,21 @@ export function initHotkey(){
})
}
async function quickMenu(){
const selStr = await alertSelect([
language.presets,
language.persona,
language.cancel
])
const sel = parseInt(selStr)
if(sel === 0){
openPresetList.set(!get(openPresetList))
}
if(sel === 1){
openPersonaList.set(!get(openPersonaList))
}
}
function clickQuery(query:string){
let ele = document.querySelector(query) as HTMLElement
console.log(ele)

View File

@@ -98,6 +98,11 @@ export const LoadingStatusState = $state({
text: '',
})
export const QuickSettings = $state({
open: false,
index: 0
})
export const disableHighlight = writable(true)
ReloadGUIPointer.subscribe(() => {