refactor: restructure project layout

- Move main process to electron/main/
- Move preload to electron/preload/
- Add shared types in electron/shared/
- Split redis-service into modular redis/ directory
- Flatten renderer to src/ (remove src/renderer/ nesting)
- Update electron.vite.config.ts paths
- Update tsconfig paths
- Output to electron-dist/
This commit is contained in:
2026-07-04 21:12:50 +08:00
parent bb885c6d6d
commit bdcf4fe299
59 changed files with 654 additions and 624 deletions
+177
View File
@@ -0,0 +1,177 @@
<script setup lang="ts">
// src/renderer/src/components/CliView.vue
import { ref, nextTick, watch } from 'vue'
import { useConnectionStore } from '@renderer/stores/connection'
const connStore = useConnectionStore()
const input = ref('')
const history = ref<{ cmd: string; result: string; error?: boolean }[]>([])
const historyIndex = ref(-1)
const outputRef = ref<HTMLDivElement>()
async function execute() {
if (!connStore.activeId || !input.value.trim()) return
const cmd = input.value.trim()
input.value = ''
historyIndex.value = -1
const parts = cmd.split(/\s+/)
const command = parts[0].toUpperCase()
const args = parts.slice(1)
try {
const result = await window.electronAPI.redis.execute(connStore.activeId, command, args)
let formatted = ''
if (result === null) {
formatted = '(nil)'
} else if (typeof result === 'number') {
formatted = `(integer) ${result}`
} else if (Array.isArray(result)) {
if (result.length === 0) {
formatted = '(empty array)'
} else {
formatted = result.map((item: any, i: number) => {
if (item === null) return `${i + 1}) (nil)`
if (typeof item === 'number') return `${i + 1}) (integer) ${item}`
return `${i + 1}) "${item}"`
}).join('\n')
}
} else if (typeof result === 'object') {
formatted = JSON.stringify(result, null, 2)
} else {
formatted = String(result)
}
history.value.push({ cmd, result: formatted })
} catch (err: any) {
history.value.push({ cmd, result: `ERROR: ${err.message}`, error: true })
}
await nextTick()
if (outputRef.value) {
outputRef.value.scrollTop = outputRef.value.scrollHeight
}
}
function onKeydown(e: KeyboardEvent) {
if (e.key === 'Enter') {
e.preventDefault()
execute()
} else if (e.key === 'ArrowUp') {
e.preventDefault()
if (historyIndex.value < history.value.length - 1) {
historyIndex.value++
input.value = history.value[history.value.length - 1 - historyIndex.value].cmd
}
} else if (e.key === 'ArrowDown') {
e.preventDefault()
if (historyIndex.value > 0) {
historyIndex.value--
input.value = history.value[history.value.length - 1 - historyIndex.value].cmd
} else {
historyIndex.value = -1
input.value = ''
}
}
}
</script>
<template>
<div class="cli-view">
<div class="cli-output" ref="outputRef">
<div v-for="(item, index) in history" :key="index" class="cli-entry">
<div class="cli-cmd">
<span class="prompt">&gt;</span>
<span>{{ item.cmd }}</span>
</div>
<pre class="cli-result" :class="{ error: item.error }">{{ item.result }}</pre>
</div>
<div v-if="history.length === 0" class="cli-welcome">
Redis CLI - type commands below
</div>
</div>
<div class="cli-input-bar">
<span class="prompt">&gt;</span>
<input
v-model="input"
class="cli-input"
placeholder="Enter Redis command..."
@keydown="onKeydown"
autofocus
/>
</div>
</div>
</template>
<style scoped>
.cli-view {
height: 100%;
display: flex;
flex-direction: column;
background: var(--bg-primary);
}
.cli-output {
flex: 1;
overflow-y: auto;
padding: 12px;
font-family: 'Cascadia Code', 'Fira Code', monospace;
font-size: 13px;
}
.cli-welcome {
color: var(--text-muted);
padding: 20px 0;
}
.cli-entry {
margin-bottom: 12px;
}
.cli-cmd {
color: var(--accent-light);
}
.prompt {
color: var(--color-green);
margin-right: 6px;
}
.cli-result {
color: var(--text-secondary);
margin: 4px 0 0 18px;
white-space: pre-wrap;
word-break: break-all;
font-size: 12px;
}
.cli-result.error {
color: var(--color-red);
}
.cli-input-bar {
padding: 10px 12px;
border-top: 1px solid var(--border-color);
display: flex;
align-items: center;
flex-shrink: 0;
}
.cli-input {
flex: 1;
background: transparent;
border: none;
outline: none;
color: var(--text-primary);
font-family: 'Cascadia Code', 'Fira Code', monospace;
font-size: 13px;
margin-left: 6px;
}
.cli-input::placeholder {
color: var(--text-muted);
}
</style>