UPD: Rename nanodevices API to nanoSerialApi
This commit is contained in:
@@ -6,7 +6,7 @@ import Navbar from '@renderer/components/navbar/Navbar.vue'
|
||||
import { useStore } from '@renderer/store'
|
||||
import { useMessageHandlers } from '@renderer/device'
|
||||
|
||||
const { electronAPI, nanoDevicesAPI } = window
|
||||
const { electronApi, nanoSerialApi } = window
|
||||
const store = useStore()
|
||||
|
||||
const menuActions = {
|
||||
@@ -15,7 +15,7 @@ const menuActions = {
|
||||
skin: () => store.switchPreviewDeviceModel()
|
||||
}
|
||||
|
||||
electronAPI.onMenu((key) => {
|
||||
electronApi.onMenu((key) => {
|
||||
console.log('menu', key)
|
||||
if (menuActions[key]) {
|
||||
menuActions[key]()
|
||||
@@ -26,20 +26,18 @@ store.fetchProfiles() // TODO remove me!
|
||||
|
||||
// handle device events
|
||||
const handlers = useMessageHandlers(store)
|
||||
nanoDevicesAPI.on_event('device-attached', (evt, deviceid, data) => store.device_attached(deviceid))
|
||||
nanoDevicesAPI.on_event('device-detached', (evt, deviceid, data) => store.device_detached(deviceid))
|
||||
nanoDevicesAPI.on_event('device-error', (evt, deviceid, data) => {
|
||||
nanoSerialApi.on_event('device-attached', (evt, deviceid, data) => store.device_attached(deviceid))
|
||||
nanoSerialApi.on_event('device-detached', (evt, deviceid, data) => store.device_detached(deviceid))
|
||||
nanoSerialApi.on_event('device-error', (evt, deviceid, data) => {
|
||||
/* TODO handle connection errors */
|
||||
})
|
||||
nanoDevicesAPI.on_event('connected', (evt, deviceid, data) => store.device_connected(deviceid))
|
||||
nanoDevicesAPI.on_event('disconnected', (evt, deviceid, data) =>
|
||||
store.device_disconnected(deviceid)
|
||||
)
|
||||
nanoDevicesAPI.on_event('update', (evt, deviceid, data) => {
|
||||
nanoSerialApi.on_event('connected', (evt, deviceid, data) => store.device_connected(deviceid))
|
||||
nanoSerialApi.on_event('disconnected', (evt, deviceid, data) => store.device_disconnected(deviceid))
|
||||
nanoSerialApi.on_event('update', (evt, deviceid, data) => {
|
||||
handlers.handle_message(data)
|
||||
})
|
||||
// get list of the currently attached devices
|
||||
nanoDevicesAPI.list_devices().then((devs) => store.init_devices(devs))
|
||||
nanoSerialApi.list_devices().then((devs) => store.init_devices(devs))
|
||||
</script>
|
||||
<template>
|
||||
<main class="flex h-screen w-screen select-none flex-col">
|
||||
|
||||
@@ -86,32 +86,32 @@
|
||||
</MenubarMenu>
|
||||
<MenubarButton
|
||||
class="app-titlebar-button"
|
||||
@click="electronAPI.openExternal('https://discord.gg/jgRd77YN5T')"
|
||||
@click="electronApi.openExternal('https://discord.gg/jgRd77YN5T')"
|
||||
>
|
||||
Community
|
||||
</MenubarButton>
|
||||
<MenubarMenu>
|
||||
<MenubarTrigger class="app-titlebar-button">Help</MenubarTrigger>
|
||||
<MenubarContent>
|
||||
<MenubarItem @click="electronAPI.openExternal('https://github.com/katbinaris/zeroone')"
|
||||
<MenubarItem @click="electronApi.openExternal('https://github.com/katbinaris/zeroone')"
|
||||
>Software Source</MenubarItem
|
||||
>
|
||||
<MenubarItem
|
||||
@click="electronAPI.openExternal('https://github.com/katbinaris/NanoD_RatchetH1')"
|
||||
@click="electronApi.openExternal('https://github.com/katbinaris/NanoD_RatchetH1')"
|
||||
>Firmware Source</MenubarItem
|
||||
>
|
||||
<MenubarItem
|
||||
@click="electronAPI.openExternal('https://github.com/katbinaris/Nano_D_PlusPlus')"
|
||||
@click="electronApi.openExternal('https://github.com/katbinaris/Nano_D_PlusPlus')"
|
||||
>Hardware Source</MenubarItem
|
||||
>
|
||||
<MenubarSeparator />
|
||||
<MenubarItem
|
||||
@click="electronAPI.openExternal('https://github.com/katbinaris/zeroone/issues/new')"
|
||||
@click="electronApi.openExternal('https://github.com/katbinaris/zeroone/issues/new')"
|
||||
>Report Software Issue</MenubarItem
|
||||
>
|
||||
<MenubarItem
|
||||
@click="
|
||||
electronAPI.openExternal('https://github.com/katbinaris/NanoD_RatchetH1/issues/new')
|
||||
electronApi.openExternal('https://github.com/katbinaris/NanoD_RatchetH1/issues/new')
|
||||
"
|
||||
>Report Device Issue</MenubarItem
|
||||
>
|
||||
@@ -120,13 +120,13 @@
|
||||
<p>Software Version: </p>
|
||||
<p>v0.1</p>
|
||||
</MenubarItem>
|
||||
<MenubarItem @click="electronAPI.openExternal('https://discord.gg/jgRd77YN5T')"
|
||||
<MenubarItem @click="electronApi.openExternal('https://discord.gg/jgRd77YN5T')"
|
||||
>Contact Support</MenubarItem
|
||||
>
|
||||
<template v-if="electronAPI.isDevelopment">
|
||||
<template v-if="electronApi.isDevelopment">
|
||||
<MenubarSeparator />
|
||||
<MenubarItem @click="electronAPI.openDevTools">Developer Tools</MenubarItem>
|
||||
<MenubarItem @click="electronAPI.reload">Reload</MenubarItem>
|
||||
<MenubarItem @click="electronApi.openDevTools">Developer Tools</MenubarItem>
|
||||
<MenubarItem @click="electronApi.reload">Reload</MenubarItem>
|
||||
</template>
|
||||
</MenubarContent>
|
||||
</MenubarMenu>
|
||||
@@ -145,7 +145,7 @@
|
||||
: 'border-2'
|
||||
"
|
||||
class="app-titlebar-button"
|
||||
@click="nanoDevicesAPI.save(store.connectedId)"
|
||||
@click="nanoSerialApi.save(store.connectedId)"
|
||||
>
|
||||
Save
|
||||
</MenubarButton>
|
||||
@@ -162,21 +162,21 @@
|
||||
<button
|
||||
v-if="minimizable"
|
||||
class="app-titlebar-button flex grow items-center justify-center px-2 hover:text-white"
|
||||
@click="electronAPI.minimizeWindow"
|
||||
@click="electronApi.minimizeWindow"
|
||||
>
|
||||
<Minus class="size-5" />
|
||||
</button>
|
||||
<button
|
||||
v-if="maximizable"
|
||||
class="app-titlebar-button flex grow items-center justify-center px-2 hover:text-white"
|
||||
@click="electronAPI.toggleMaximizeWindow"
|
||||
@click="electronApi.toggleMaximizeWindow"
|
||||
>
|
||||
<Copy v-if="isMaximized" class="size-4" />
|
||||
<Square v-else class="mr-0.5 size-3.5" />
|
||||
</button>
|
||||
<button
|
||||
class="app-titlebar-button flex grow items-center justify-center px-2 hover:text-white"
|
||||
@click="electronAPI.closeWindow"
|
||||
@click="electronApi.closeWindow"
|
||||
>
|
||||
<X class="mr-0.5 size-5" />
|
||||
</button>
|
||||
@@ -209,9 +209,9 @@ const showDisconnectButton = ref(false)
|
||||
|
||||
const isMaximized = ref(false)
|
||||
|
||||
const { electronAPI, nanoDevicesAPI } = window
|
||||
const { electronApi, nanoSerialApi } = window
|
||||
|
||||
const isMacOS = electronAPI.platform === 'darwin'
|
||||
const isMacOS = electronApi.platform === 'darwin'
|
||||
const zoomFactor = ref(1)
|
||||
|
||||
const numberOfChanges = ref(27)
|
||||
@@ -225,12 +225,12 @@ onMounted(() => {
|
||||
window.addEventListener('resize', () => {
|
||||
zoomFactor.value = window.outerWidth / window.innerWidth
|
||||
})
|
||||
electronAPI.onMaximized((maximized) => {
|
||||
electronApi.onMaximized((maximized) => {
|
||||
console.log(maximized)
|
||||
isMaximized.value = true
|
||||
})
|
||||
|
||||
electronAPI.onUnmaximized(() => {
|
||||
electronApi.onUnmaximized(() => {
|
||||
isMaximized.value = false
|
||||
})
|
||||
})
|
||||
|
||||
@@ -21,7 +21,7 @@ app.use(pinia)
|
||||
app.use(i18n)
|
||||
|
||||
// TODO remove this
|
||||
window.nanoDevicesAPI.on_event('*', (eventid, deviceid, ...data) => {
|
||||
window.nanoSerialApi.on_event('*', (eventid, deviceid, ...data) => {
|
||||
console.log('Event on window ', eventid, deviceid, data)
|
||||
})
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import mockData from '@renderer/data/nanoConfig.json'
|
||||
|
||||
// const ajv = new Ajv() // see below
|
||||
|
||||
const { nanoDevicesAPI } = window
|
||||
const { nanoSerialApi } = window
|
||||
|
||||
// TODO: Define Profile type
|
||||
|
||||
@@ -216,13 +216,13 @@ export const useStore = defineStore('main', {
|
||||
// this.selectedProfile.keys[this.selectedKey].default = color
|
||||
const props = {}
|
||||
props[`button${this.selectedKey.toUpperCase()}Idle`] = color.rgbNumber()
|
||||
nanoDevicesAPI.send(this.connectedId, { p: { name: 'Default Profile', ...props } })
|
||||
nanoSerialApi.send(this.connectedId, { p: { name: 'Default Profile', ...props } })
|
||||
},
|
||||
setKeyPressedColor(color) {
|
||||
// this.selectedProfile.keys[this.selectedKey].pressed = color
|
||||
const props = {}
|
||||
props[`button${this.selectedKey.toUpperCase()}Press`] = color.rgbNumber()
|
||||
nanoDevicesAPI.send(this.connectedId, { p: { name: 'Default Profile', ...props } })
|
||||
nanoSerialApi.send(this.connectedId, { p: { name: 'Default Profile', ...props } })
|
||||
},
|
||||
|
||||
// devices, device attachment, connection, and disconnection
|
||||
@@ -233,7 +233,7 @@ export const useStore = defineStore('main', {
|
||||
// TODO auto-connect to the device
|
||||
const deviceid = Object.keys(this.devices)[0]
|
||||
console.log('Auto-connecting to device ', deviceid)
|
||||
window.nanoDevicesAPI.connect(deviceid)
|
||||
window.nanoSerialApi.connect(deviceid)
|
||||
}
|
||||
},
|
||||
update_devices(deviceid, attached) {
|
||||
@@ -249,7 +249,7 @@ export const useStore = defineStore('main', {
|
||||
if (Object.keys(this.devices).length == 1) {
|
||||
// TODO auto-connect to the device
|
||||
console.log('Auto-connecting to device ', deviceid)
|
||||
window.nanoDevicesAPI.connect(deviceid)
|
||||
window.nanoSerialApi.connect(deviceid)
|
||||
}
|
||||
},
|
||||
device_detached(deviceid) {
|
||||
@@ -265,10 +265,10 @@ export const useStore = defineStore('main', {
|
||||
this.connected = true
|
||||
this.connectedId = deviceid
|
||||
// TODO load profiles from device
|
||||
// nanoDevicesAPI.send(deviceid, { profiles: "#all" }) // request profiles
|
||||
// nanoSerialApi.send(deviceid, { profiles: "#all" }) // request profiles
|
||||
// "Default Profile", for now, is the only profile after the device
|
||||
// starts up, so it is also the current (eg. 'selected') profile
|
||||
// nanoDevicesAPI.send(deviceid, { p: "Default Profile" }) // request Default Profile
|
||||
// nanoSerialApi.send(deviceid, { p: "Default Profile" }) // request Default Profile
|
||||
|
||||
// TODO maybe you want to request all the profiles right now?
|
||||
// or only on demand?
|
||||
|
||||
Reference in New Issue
Block a user