feat: Add torch client identity, early connection and auto-request
- Named clients persisted in localStorage, editable from dropdown - Auto-request: clients can auto-receive torch when no holder exists - Early torch init in App.vue (fires before WebMCP, awaited later) - Deferred torch connection in toolRegistry for race condition safety - TorchButton rewritten as dropdown with name editor, toggle, client list - Server broadcasts client names, supports update-name message - MCP tool handlers display client names
This commit is contained in:
@@ -3,6 +3,7 @@ import { ref, computed } from 'vue'
|
||||
|
||||
export interface TorchClient {
|
||||
id: string
|
||||
name: string
|
||||
userAgent: string
|
||||
hostname: string
|
||||
url: string
|
||||
@@ -17,6 +18,8 @@ export const useTorchStore = defineStore('torch', () => {
|
||||
const torchHolderId = ref<string | null>(null)
|
||||
const clients = ref<TorchClient[]>([])
|
||||
const isRequesting = ref(false)
|
||||
const clientName = ref(localStorage.getItem('torch-client-name') || '')
|
||||
const autoRequest = ref(localStorage.getItem('torch-auto-request') === 'true')
|
||||
|
||||
// Computed
|
||||
const isConnected = computed(() => clientId.value !== null)
|
||||
@@ -44,12 +47,23 @@ export const useTorchStore = defineStore('torch', () => {
|
||||
isRequesting.value = value
|
||||
}
|
||||
|
||||
function setClientName(name: string) {
|
||||
clientName.value = name
|
||||
localStorage.setItem('torch-client-name', name)
|
||||
}
|
||||
|
||||
function setAutoRequest(val: boolean) {
|
||||
autoRequest.value = val
|
||||
localStorage.setItem('torch-auto-request', String(val))
|
||||
}
|
||||
|
||||
function reset() {
|
||||
clientId.value = null
|
||||
hasTorch.value = false
|
||||
torchHolderId.value = null
|
||||
clients.value = []
|
||||
isRequesting.value = false
|
||||
// Do NOT reset clientName/autoRequest — persist across sessions
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -59,6 +73,8 @@ export const useTorchStore = defineStore('torch', () => {
|
||||
torchHolderId,
|
||||
clients,
|
||||
isRequesting,
|
||||
clientName,
|
||||
autoRequest,
|
||||
// Computed
|
||||
isConnected,
|
||||
torchHolder,
|
||||
@@ -67,6 +83,8 @@ export const useTorchStore = defineStore('torch', () => {
|
||||
setTorchState,
|
||||
setClients,
|
||||
setRequesting,
|
||||
setClientName,
|
||||
setAutoRequest,
|
||||
reset
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user