diff --git a/src/renderer/src/components/profile/ProfileButton.vue b/src/renderer/src/components/profile/ProfileButton.vue index c5b4ab5..6bb3029 100644 --- a/src/renderer/src/components/profile/ProfileButton.vue +++ b/src/renderer/src/components/profile/ProfileButton.vue @@ -13,10 +13,7 @@ :class="{ 'bg-zinc-300': selected }" @submit.prevent=" () => { - // store.renameProfile(profile.id, nameInput) - console.log('Renaming profile to:', nameInput) - console.log('NOT IMPLEMENTED YET!') - // TODO: Implement deviceStore.renameProfile + $emit('rename', { profile: profile.name, name: nameInput }) editing = false } " @@ -140,7 +137,7 @@ import { Check, Copy, PenLine, Trash2, X, GripHorizontal } from 'lucide-vue-next import ScrambleText from '@renderer/components/common/ScrambleText.vue' import { nextTick, ref } from 'vue' -defineEmits(['select', 'duplicate', 'delete']) +defineEmits(['select', 'rename', 'duplicate', 'delete']) const nameSubmitButton = ref(null) diff --git a/src/renderer/src/components/profile/ProfileManager.vue b/src/renderer/src/components/profile/ProfileManager.vue index 3acb6ae..f186901 100644 --- a/src/renderer/src/components/profile/ProfileManager.vue +++ b/src/renderer/src/components/profile/ProfileManager.vue @@ -109,10 +109,18 @@ :selected="deviceStore.currentProfileName === dragProfile.element.name" @select=" () => { - console.log('Select profile not implemented!') + deviceStore.selectProfile(dragProfile.element.name) showProfileConfig = true } " + @rename=" + (event) => { + deviceStore.renameProfile(event.profile, event.name) + if (deviceStore.currentProfileName === event.profile) { + deviceStore.selectProfile(event.name) + } + } + " @duplicate="console.log('Duplicate profile not implemented!')" @delete="console.log('Delete profile not implemented!')" /> diff --git a/src/renderer/src/deviceStore.ts b/src/renderer/src/deviceStore.ts index 3a99541..476451d 100644 --- a/src/renderer/src/deviceStore.ts +++ b/src/renderer/src/deviceStore.ts @@ -86,6 +86,12 @@ export const useDeviceStore = defineStore('device', { this.attachedDeviceIds.push(deviceId) } }, + selectProfile(profileName: string, updateDevice: boolean = true) { + this.currentProfileName = profileName + if (updateDevice) { + nanoIpc.send(this.currentDeviceId!, JSON.stringify({ current: profileName })) + } + }, addProfile(profile: Profile, updateDevice: boolean = true) { if (!this.profileNames.includes(profile.name)) { this.profileNames.push(profile.name) @@ -103,6 +109,21 @@ export const useDeviceStore = defineStore('device', { ) } }, + renameProfile(oldName: string, newName: string, updateDevice: boolean = true) { + if (this.profileNames.includes(newName)) { + console.error('Profile name already exists:', newName) + } + const profile = this.profiles.find((p) => p.name === oldName) + if (profile) { + profile.name = newName + if (updateDevice) { + nanoIpc.send( + this.currentDeviceId!, + JSON.stringify({ profile: oldName, updates: { name: newName } }) + ) + } + } + }, detachDevice(deviceId: string) { const index = this.attachedDeviceIds.indexOf(deviceId) if (index !== -1) { @@ -207,7 +228,12 @@ export const initializeDevices = () => { nanoIpc.listAttachedDevices().then((deviceIds) => { deviceStore.setAttachedDeviceIds(deviceIds) if (!deviceStore.connected && deviceIds.length > 0) { - nanoIpc.connect(deviceIds[0]) + nanoIpc.connect(deviceIds[0]).catch((e) => { + console.error(e) + console.log('Serial port might still be open, requesting profiles...') + deviceStore.connectDevice(deviceIds[0], false) + nanoIpc.send(deviceIds[0], JSON.stringify({ profiles: '#all' })) + }) } }) }