Skip to content

Commit c9e3797

Browse files
TibixDevLevev
andcommitted
chore: Implement additional improvements to the USB passthrough feature and UI
Co-authored-by: Levev <levvevv@gmail.com>
1 parent 98081d6 commit c9e3797

4 files changed

Lines changed: 30 additions & 19 deletions

File tree

src/renderer/App.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ import { isInstalled } from './lib/install';
133133
import { Winboat } from './lib/winboat';
134134
import { openAnchorLink } from './utils/openLink';
135135
import { WinboatConfig } from './lib/config';
136+
import { USBManager } from './lib/usbmanager';
136137
const { BrowserWindow }: typeof import('@electron/remote') = require('@electron/remote')
137138
const os: typeof import('os') = require('os')
138139
const path: typeof import('path') = require('path')
@@ -152,13 +153,15 @@ const rerenderCounter = ref(0); // TODO: Hack for non-reactive data
152153
153154
onMounted(async () => {
154155
console.log("WinBoat app path:", path.join(remote.app.getAppPath(), "..", ".."));
156+
157+
new USBManager(); // Instantiate singleton class
155158
const winboatInstalled = await isInstalled();
156159
if (!winboatInstalled) {
157160
console.log("Not installed, redirecting to setup...")
158161
$router.push('/setup');
159162
} else {
160-
winboat = new Winboat();
161-
wbConfig = new WinboatConfig();
163+
winboat = new Winboat(); // Instantiate singleton class
164+
wbConfig = new WinboatConfig(); // Instantiate singleton class
162165
$router.push('/home');
163166
}
164167

src/renderer/lib/usbmanager.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,6 @@ export class USBManager {
387387
}
388388
}
389389

390-
new USBManager();
391-
392390
/**
393391
* Reads the Linux USB device database from the specified file path and returns a JSON representation.
394392
* @param filePath Path to the usb.ids file

src/renderer/lib/winboat.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,6 @@ export class Winboat {
198198
this.#containerInterval = setInterval(async () => {
199199
const _containerStatus = await this.getContainerStatus();
200200

201-
// TODO: Remove if statement once this feature gets rolled out.
202-
if (this.#wbConfig?.config.experimentalFeatures && !this.#qmpInterval) {
203-
this.createQMPInterval();
204-
}
205-
206201
if (_containerStatus !== this.containerStatus.value) {
207202
this.containerStatus.value = _containerStatus;
208203
logger.info(`Winboat Container state changed to ${_containerStatus}`);
@@ -671,4 +666,11 @@ export class Winboat {
671666
// Done!
672667
this.isUpdatingGuestServer.value = false;
673668
}
669+
670+
/**
671+
* Whether or not the Winboat singleton has a QMP interval active
672+
*/
673+
get hasQMPInterval() {
674+
return this.#qmpInterval !== null;
675+
}
674676
}

src/renderer/views/Config.vue

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
<TransitionGroup name="devices" tag="x-box" class="flex-col gap-2 mt-4">
163163
<x-card
164164
class="flex justify-between items-center px-2 py-0 m-0 bg-white/5"
165-
v-for="device, k of usbManager.ptDevices.value"
165+
v-for="device of usbManager.ptDevices.value"
166166
:key="`${device.vendorId}-${device.productId}`"
167167
:class="{ 'bg-white/[calc(0.05*0.75)] [&_*:not(div):not(span)]:opacity-75': !usbManager.isPTDeviceConnected(device) }"
168168
>
@@ -200,7 +200,8 @@
200200
</TransitionGroup>
201201
<x-button
202202
v-if="availableDevices.length > 0"
203-
class="mt-4 !bg-gradient-to-tl from-blue-400/20 shadow-md shadow-blue-950/20 to-transparent hover:from-blue-400/30 transition"
203+
class="!bg-gradient-to-tl from-blue-400/20 shadow-md shadow-blue-950/20 to-transparent hover:from-blue-400/30 transition"
204+
:class="{ 'mt-4': usbManager.ptDevices.value.length }"
204205
@click="refreshAvailableDevices()"
205206
>
206207
<x-icon href="#add"></x-icon>
@@ -355,19 +356,17 @@
355356
</template>
356357

357358
<script setup lang="ts">
358-
import { computed, getCurrentInstance, nextTick, onMounted, ref, watch } from 'vue';
359-
import { Winboat } from '../lib/winboat';
360-
import type { ComposeConfig, USBDevice } from '../../types';
359+
import { computed, onMounted, ref } from 'vue';
360+
import { ContainerStatus, Winboat } from '../lib/winboat';
361+
import type { ComposeConfig } from '../../types';
361362
import { getSpecs } from '../lib/specs';
362363
import { Icon } from '@iconify/vue';
363364
import { WinboatConfig } from '../lib/config';
364365
import { USBManager, type PTSerializableDeviceInfo } from '../lib/usbmanager';
365-
import { type Device, type Interface } from "usb";
366+
import { type Device } from "usb";
366367
import {
367368
RDP_PORT,
368369
PORT_MAX,
369-
USB_CLASS_IMAGING,
370-
USB_INTERFACE_MTP,
371370
USB_VID_BLACKLIST
372371
} from '../lib/constants';
373372
const { app }: typeof import('@electron/remote') = require('@electron/remote');
@@ -605,9 +604,18 @@ async function toggleExperimentalFeatures() {
605604
rerenderExperimental.value++;
606605
$emit("rerender");
607606
608-
// Remove all passthrough USB devices since USB is still experimental
609-
if (wbConfig.config.experimentalFeatures) {
607+
// Remove all passthrough USB devices if we're disabling experimental features
608+
// since USB passthrough is an experimental feature
609+
if (!wbConfig.config.experimentalFeatures) {
610610
await usbManager.removeAllPassthroughDevicesAndConfig();
611+
// Create the QMP interval if experimental features are enabled
612+
// This would get created by default since we're changing the compose and re-deploying,
613+
// but a scenario could also occur where the user is re-enabling experimental features
614+
// after the compose changes, which then would cause a bug
615+
// TODO: Remove after USB passthrough is no longer experimental
616+
} else if (winboat.containerStatus.value == ContainerStatus.Running && !winboat.hasQMPInterval) {
617+
console.log("Creating QMP interval because experimental features were turned on");
618+
winboat.createQMPInterval();
611619
}
612620
}
613621

0 commit comments

Comments
 (0)