mirror of
https://github.com/Macrame-App/Macrame
synced 2025-12-29 15:29:26 +00:00
WIP: Update to device components
This commit is contained in:
parent
3b38372b4b
commit
6872269266
8 changed files with 203 additions and 56 deletions
|
|
@ -34,7 +34,9 @@
|
|||
|
||||
.panel__content {
|
||||
@apply grid
|
||||
h-full
|
||||
pt-4 sm:pt-0
|
||||
pl-0 sm:pl-4;
|
||||
pl-0 sm:pl-4
|
||||
overflow-auto;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,8 +25,9 @@ defineProps({
|
|||
@reference "@/assets/main.css";
|
||||
|
||||
.alert {
|
||||
@apply flex
|
||||
items-center
|
||||
@apply grid
|
||||
grid-cols-[1rem_1fr]
|
||||
items-start
|
||||
gap-4
|
||||
p-4
|
||||
border
|
||||
|
|
@ -36,7 +37,7 @@ defineProps({
|
|||
backdrop-blur-md;
|
||||
|
||||
&.alert__info {
|
||||
@apply text-sky-400 bg-sky-400/10;
|
||||
@apply text-sky-100 bg-sky-400/40;
|
||||
}
|
||||
|
||||
&.alert__success {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,17 @@
|
|||
Navigate to <em class="font-semibold">http://localhost:6970/devices</em> on your pc to
|
||||
authorize.
|
||||
</p>
|
||||
<template v-if="server.link == 'checking'">
|
||||
<div class="grid grid-cols-[2rem_1fr] gap-2">
|
||||
<IconReload class="animate-spin" />
|
||||
Checking server for link...
|
||||
</div>
|
||||
</template>
|
||||
<template v-if="server.link === false">
|
||||
<ButtonComp variant="subtle" @click="pingLink()" class="w-fit">
|
||||
<IconReload />Check for server link
|
||||
</ButtonComp>
|
||||
</template>
|
||||
</div>
|
||||
</AlertComp>
|
||||
|
||||
|
|
@ -37,22 +48,37 @@
|
|||
Disconnect
|
||||
</ButtonComp>
|
||||
</div>
|
||||
<DialogComp ref="linkPinDialog">
|
||||
<template #content>
|
||||
<div class="grid gap-4">
|
||||
<h3>Enter server link pin:</h3>
|
||||
<input class="input" type="number" v-model="server.linkPin" />
|
||||
<ButtonComp variant="primary" @click="getDeviceKey()">Enter</ButtonComp>
|
||||
</div>
|
||||
</template>
|
||||
</DialogComp>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { IconKey, IconPlugConnectedX, IconServer } from '@tabler/icons-vue'
|
||||
import { IconKey, IconPlugConnectedX, IconReload, IconServer } from '@tabler/icons-vue'
|
||||
import AlertComp from '../base/AlertComp.vue'
|
||||
import ButtonComp from '../base/ButtonComp.vue'
|
||||
import { onMounted, reactive } from 'vue'
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { useDeviceStore } from '@/stores/device'
|
||||
import { deviceType, deviceModel, deviceVendor } from '@basitcodeenv/vue3-device-detect'
|
||||
import DialogComp from '../base/DialogComp.vue'
|
||||
|
||||
const device = useDeviceStore()
|
||||
|
||||
const linkPinDialog = ref()
|
||||
|
||||
const server = reactive({
|
||||
host: '',
|
||||
status: false,
|
||||
access: false,
|
||||
link: false,
|
||||
linkPin: '',
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
|
|
@ -62,20 +88,29 @@ onMounted(async () => {
|
|||
if (Object.keys(state.server).length) server.status = state.server.status
|
||||
})
|
||||
|
||||
const status = await device.checkServerAccess()
|
||||
const status = await device.remoteCheckServerAccess()
|
||||
server.status = status
|
||||
})
|
||||
|
||||
function requestAccess() {
|
||||
const request = device.requestServerAccess()
|
||||
let deviceName = `${deviceVendor() ? deviceVendor() : 'Unknown'} ${deviceVendor() ? deviceModel() : deviceType()}`
|
||||
|
||||
request
|
||||
.then((data) => {
|
||||
console.log('1', data)
|
||||
})
|
||||
.then((data) => {
|
||||
console.log('2', data)
|
||||
})
|
||||
device.remoteRequestServerAccess(deviceName, deviceType()).then((data) => {
|
||||
if (data.data) pingLink()
|
||||
})
|
||||
}
|
||||
|
||||
function pingLink() {
|
||||
server.link = 'checking'
|
||||
device.remotePingLink((link) => {
|
||||
server.link = true
|
||||
linkPinDialog.value.toggleDialog(true)
|
||||
console.log(link, 'opendialog')
|
||||
})
|
||||
}
|
||||
|
||||
function getDeviceKey() {
|
||||
device.remoteHandshake(server.linkPin)
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
|||
|
|
@ -8,60 +8,97 @@
|
|||
</AlertComp>
|
||||
|
||||
<div class="mcrm-block block__light flex flex-wrap items-start">
|
||||
<!-- {{ remote.devices }} -->
|
||||
<div
|
||||
class="mcrm-block block__dark block-size__sm w-64 grid !gap-4 content-start"
|
||||
v-for="(device, id) in remote.devices"
|
||||
:key="id"
|
||||
>
|
||||
<div class="grid gap-2">
|
||||
<h5 class="grid grid-cols-[auto_1fr] gap-2">
|
||||
<IconDeviceUnknown v-if="device.settings.type == 'unknown'" />
|
||||
<IconDeviceMobile v-if="device.settings.type == 'phone'" />
|
||||
<IconDeviceTablet v-if="device.settings.type == 'tablet'" />
|
||||
<span class="w-full truncate">
|
||||
{{ device.settings.name }}
|
||||
</span>
|
||||
</h5>
|
||||
<em>{{ id }}</em>
|
||||
<!-- {{ Object.keys(remote.devices).length }} -->
|
||||
<template v-if="Object.keys(remote.devices).length > 0">
|
||||
<div
|
||||
class="mcrm-block block__dark block-size__sm w-64 grid !gap-4 content-start"
|
||||
v-for="(remoteDevice, id) in remote.devices"
|
||||
:key="id"
|
||||
>
|
||||
<div class="grid gap-2">
|
||||
<h5 class="grid grid-cols-[auto_1fr] gap-2">
|
||||
<IconDeviceUnknown v-if="remoteDevice.settings.type == 'unknown'" />
|
||||
<IconDeviceMobile v-if="remoteDevice.settings.type == 'mobile'" />
|
||||
<IconDeviceTablet v-if="remoteDevice.settings.type == 'tablet'" />
|
||||
<IconDeviceDesktop v-if="remoteDevice.settings.type == 'desktop'" />
|
||||
<span class="w-full truncate">
|
||||
{{ remoteDevice.settings.name }}
|
||||
</span>
|
||||
</h5>
|
||||
<em>{{ id }}</em>
|
||||
</div>
|
||||
<template v-if="remoteDevice.key">
|
||||
<AlertComp type="success">Linked</AlertComp>
|
||||
<ButtonComp variant="danger"> <IconLinkOff />Unlink device </ButtonComp>
|
||||
</template>
|
||||
<template v-else>
|
||||
<AlertComp type="warning">Not linked</AlertComp>
|
||||
<ButtonComp variant="primary" @click="startLink(id)">
|
||||
<IconLink />Link device
|
||||
</ButtonComp>
|
||||
</template>
|
||||
</div>
|
||||
<template v-if="device.key">
|
||||
<AlertComp type="success">Registered</AlertComp>
|
||||
<ButtonComp variant="danger"> <IconDevicesMinus />Unregister device </ButtonComp>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="grid w-full gap-4">
|
||||
<em class="text-slate-300">No remote devices</em>
|
||||
<div class="flex justify-end">
|
||||
<ButtonComp variant="primary" @click="device.serverGetRemotes()">
|
||||
<IconReload />Check for access requests
|
||||
</ButtonComp>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<DialogComp ref="pinDialog">
|
||||
<template #content>
|
||||
<div class="grid gap-4">
|
||||
<h3>Pin code</h3>
|
||||
<span class="text-4xl font-mono tracking-wide">{{ remote.pinlink }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<AlertComp type="warning">Not registered</AlertComp>
|
||||
<ButtonComp variant="primary"> <IconDevicesPlus />Register device </ButtonComp>
|
||||
</template>
|
||||
</div>
|
||||
</DialogComp>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted, reactive } from 'vue'
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import AlertComp from '../base/AlertComp.vue'
|
||||
import { useDeviceStore } from '@/stores/device'
|
||||
import {
|
||||
IconDeviceDesktop,
|
||||
IconDeviceMobile,
|
||||
IconDevicesMinus,
|
||||
IconDevicesPlus,
|
||||
IconDeviceTablet,
|
||||
IconDeviceUnknown,
|
||||
IconLink,
|
||||
IconLinkOff,
|
||||
IconReload,
|
||||
} from '@tabler/icons-vue'
|
||||
import ButtonComp from '../base/ButtonComp.vue'
|
||||
import DialogComp from '../base/DialogComp.vue'
|
||||
|
||||
const device = useDeviceStore()
|
||||
|
||||
const remote = reactive({ devices: [] })
|
||||
const pinDialog = ref()
|
||||
|
||||
const remote = reactive({ devices: [], pinlink: '' })
|
||||
|
||||
onMounted(() => {
|
||||
device.getRemoteDevices()
|
||||
device.serverGetRemotes()
|
||||
|
||||
device.$subscribe((mutation, state) => {
|
||||
if (Object.keys(state.remote).length) remote.devices = device.remote
|
||||
})
|
||||
})
|
||||
|
||||
async function startLink(deviceUuid) {
|
||||
const pin = await device.serverStartLink(deviceUuid)
|
||||
|
||||
remote.pinlink = pin
|
||||
pinDialog.value.toggleDialog(true)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import axios from 'axios'
|
||||
import { appUrl } from '@/services/ApiService'
|
||||
import { appUrl, encrypt } from '@/services/ApiService'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
export const useDeviceStore = defineStore('device', () => {
|
||||
|
|
@ -15,6 +15,7 @@ export const useDeviceStore = defineStore('device', () => {
|
|||
status: false,
|
||||
})
|
||||
|
||||
// Current device
|
||||
const uuid = () => {
|
||||
if (!current.value.uuid && localStorage.getItem('deviceId')) {
|
||||
current.value.uuid = localStorage.getItem('deviceId')
|
||||
|
|
@ -30,32 +31,65 @@ export const useDeviceStore = defineStore('device', () => {
|
|||
return uuid
|
||||
}
|
||||
|
||||
const getRemoteDevices = async () => {
|
||||
// remote.value = { penis: 'penis' }
|
||||
// return
|
||||
axios.post(appUrl() + '/device/list').then((data) => {
|
||||
// Server application
|
||||
const serverGetRemotes = async (remoteUuid) => {
|
||||
axios.post(appUrl() + '/device/list', { uuid: remoteUuid }).then((data) => {
|
||||
if (data.data.devices) remote.value = data.data.devices
|
||||
})
|
||||
}
|
||||
|
||||
const checkServerAccess = async () => {
|
||||
const serverStartLink = async (deviceUuid) => {
|
||||
const request = await axios.post(appUrl() + '/device/link/start', { uuid: deviceUuid })
|
||||
return request.data
|
||||
}
|
||||
|
||||
// Remote application
|
||||
const remoteCheckServerAccess = async () => {
|
||||
const check = await axios.post(appUrl() + '/device/access/check', { uuid: uuid() })
|
||||
server.value.access = check.data
|
||||
return check.data
|
||||
}
|
||||
|
||||
const requestServerAccess = async () => {
|
||||
const request = await axios.post(appUrl() + '/device/access/request', { uuid: uuid() })
|
||||
const remoteRequestServerAccess = async (deviceName, deviceType) => {
|
||||
const request = await axios.post(appUrl() + '/device/access/request', {
|
||||
uuid: uuid(),
|
||||
name: deviceName,
|
||||
type: deviceType,
|
||||
})
|
||||
return request
|
||||
}
|
||||
const remotePingLink = async (cb) => {
|
||||
// const linkRequest = await axios.post(appUrl() + '/device/link/ping', { uuid: deviceUuid })
|
||||
// if (linkRequest.data)
|
||||
const pingInterval = setInterval(() => {
|
||||
axios.post(appUrl() + '/device/link/ping', { uuid: uuid() }).then((data) => {
|
||||
if (data.data) {
|
||||
clearInterval(pingInterval)
|
||||
cb(data.data)
|
||||
}
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
const remoteHandshake = async (pin) => {
|
||||
// send encrypt(uuid + pin)
|
||||
// then decrypt data with pin = key
|
||||
|
||||
axios.post(appUrl() + '/device/handshake', { shake: pin }).then((data) => {
|
||||
console.log(data)
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
remote,
|
||||
server,
|
||||
uuid,
|
||||
setDeviceId,
|
||||
getRemoteDevices,
|
||||
checkServerAccess,
|
||||
requestServerAccess,
|
||||
serverGetRemotes,
|
||||
serverStartLink,
|
||||
remoteCheckServerAccess,
|
||||
remoteRequestServerAccess,
|
||||
remotePingLink,
|
||||
remoteHandshake,
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@
|
|||
<h1 class="panel__title">
|
||||
Devices <span class="text-sm">{{ isLocal() ? 'remote' : 'servers' }}</span>
|
||||
</h1>
|
||||
<div class="panel__content">
|
||||
<ServerView v-if="!isLocal()" />
|
||||
<RemoteView v-else />
|
||||
<div class="panel__content grid sm:grid-cols-2 gap-8">
|
||||
<ServerView />
|
||||
<RemoteView />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue