Skip to content

Commit 7691366

Browse files
committed
ping-viewer-next-frontend: App: Auto connect single device or open Device Management
1 parent 6b3e4c0 commit 7691366

File tree

1 file changed

+39
-0
lines changed
  • ping-viewer-next-frontend/src

1 file changed

+39
-0
lines changed

ping-viewer-next-frontend/src/App.vue

+39
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@
187187
</template>
188188

189189
<script setup>
190+
import { watchOnce } from '@vueuse/core';
190191
import { computed, nextTick, onMounted, onUnmounted, provide, reactive, ref, watch } from 'vue';
191192
import { useRoute } from 'vue-router';
192193
import { useDisplay, useTheme } from 'vuetify';
@@ -722,6 +723,44 @@ const toggleMenu = () => {
722723
isMenuOpen.value = !isMenuOpen.value;
723724
};
724725
726+
watchOnce(serverUrl, (newUrl) => {
727+
if (newUrl) {
728+
const autoSelectSingleDevice = async () => {
729+
try {
730+
const response = await fetch(`${newUrl}/device_manager/request`, {
731+
method: 'POST',
732+
headers: {
733+
'Content-Type': 'application/json',
734+
},
735+
body: JSON.stringify({
736+
command: 'List',
737+
module: 'DeviceManager',
738+
}),
739+
});
740+
741+
if (!response.ok) throw new Error('Failed to fetch devices');
742+
743+
const data = await response.json();
744+
const availableDevices =
745+
data.DeviceInfo?.filter((device) =>
746+
['ContinuousMode', 'Running', 'Available'].includes(device.status)
747+
) || [];
748+
749+
if (availableDevices.length === 1) {
750+
selectDevice(availableDevices[0]);
751+
} else {
752+
isConnectionMenuOpen.value = true;
753+
}
754+
} catch (error) {
755+
console.error('Error auto-selecting device:', error);
756+
isConnectionMenuOpen.value = true;
757+
}
758+
};
759+
760+
autoSelectSingleDevice();
761+
}
762+
});
763+
725764
onMounted(() => {
726765
loadSettings();
727766
initializeYawConnection();

0 commit comments

Comments
 (0)