From 944e3a39c5529b13b7ce345add3e46f0832c661b Mon Sep 17 00:00:00 2001
From: lights0123
Date: Sun, 27 Sep 2020 15:54:28 -0400
Subject: [PATCH] Final touches
---
.github/workflows/ci.yml | 4 +-
.../workflows/{publish.yml => release.yml} | 2 +-
src-tauri/src/main.rs | 40 +++++++++----------
src/components/devices.ts | 3 +-
src/views/Home.vue | 20 ++++++++--
5 files changed, 41 insertions(+), 28 deletions(-)
rename .github/workflows/{publish.yml => release.yml} (97%)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 3ac4736..e20dadc 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -3,7 +3,7 @@ on:
push:
branches-ignore:
- 'dependabot/**'
- - publish
+ - release
pull_request:
jobs:
@@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- platform: [macos-latest, ubuntu-18.04, windows-latest]
+ platform: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
diff --git a/.github/workflows/publish.yml b/.github/workflows/release.yml
similarity index 97%
rename from .github/workflows/publish.yml
rename to .github/workflows/release.yml
index fa62c02..5a0506f 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/release.yml
@@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- platform: [macos-latest, ubuntu-18.04, windows-latest]
+ platform: [macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 03f84e7..06b21b6 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -1,7 +1,7 @@
-// #![cfg_attr(
-// all(not(debug_assertions), target_os = "windows"),
-// windows_subsystem = "windows"
-// )]
+#![cfg_attr(
+ all(not(debug_assertions), target_os = "windows"),
+ windows_subsystem = "windows"
+)]
use hashbrown::HashMap;
use std::fs::File;
@@ -88,22 +88,22 @@ impl Hotplug for DeviceMon {
}
fn device_left(&mut self, device: rusb::Device) {
- // if let Some((dev, _)) = DEVICES
- // .write()
- // .unwrap()
- // .remove_entry(&(device.bus_number(), device.address()))
- // {
- // if let Err(msg) = tauri::event::emit(
- // &mut self.handle,
- // "removeDevice",
- // Some(DevId {
- // bus_number: dev.0,
- // address: dev.1,
- // }),
- // ) {
- // eprintln!("{}", msg);
- // };
- // }
+ if let Some((dev, _)) = DEVICES
+ .write()
+ .unwrap()
+ .remove_entry(&(device.bus_number(), device.address()))
+ {
+ if let Err(msg) = tauri::event::emit(
+ &mut self.handle,
+ "removeDevice",
+ Some(DevId {
+ bus_number: dev.0,
+ address: dev.1,
+ }),
+ ) {
+ eprintln!("{}", msg);
+ };
+ }
}
}
diff --git a/src/components/devices.ts b/src/components/devices.ts
index 1bc8726..d7bdbc9 100644
--- a/src/components/devices.ts
+++ b/src/components/devices.ts
@@ -119,9 +119,10 @@ let queueId = 0;
class Devices extends Vue {
devices: Record = {};
enumerating = false;
+ hasEnumerated = false;
created() {
- this.enumerate().catch(console.error);
+ this.enumerate().then(() => this.hasEnumerated = true, console.error);
listen('addDevice', dev => {
const payload = dev.payload as Device & DevId;
const str = devToString(payload);
diff --git a/src/views/Home.vue b/src/views/Home.vue
index acbc950..2cc6a0f 100644
--- a/src/views/Home.vue
+++ b/src/views/Home.vue
@@ -12,7 +12,7 @@
@@ -39,6 +39,10 @@ import CalcInfo from '@/components/CalcInfo.vue';
import FileBrowser from '@/components/FileBrowser.vue';
import DeviceSelect from "@/components/DeviceSelect.vue";
+function sleep(ms: number) {
+ return new Promise(resolve => setTimeout(resolve, ms));
+}
+
@Component({
components: {
DeviceSelect,
@@ -50,9 +54,17 @@ export default class Home extends Vue {
selectedCalculator: string | null = null;
showHidden = false;
+ @Watch('$devices.hasEnumerated')
+ onEnumerated() {
+ const first = Object.keys(this.$devices.devices)[0];
+ if (first) this.selectedCalculator = first;
+ }
+
@Watch('$devices.devices')
- onDeviceChange() {
+ async onDeviceChange() {
if (!this.selectedCalculator) {
+ await sleep(1000);
+ if (this.selectedCalculator) return;
const first = Object.keys(this.$devices.devices)[0];
if (first) this.selectedCalculator = first;
} else if (!Object.keys(this.$devices.devices).includes(this.selectedCalculator)) {
@@ -67,7 +79,7 @@ export default class Home extends Vue {
if (dev && !this.$devices.devices[dev].info && !this.$devices.devices[dev].needsDrivers) {
try {
await this.$devices.open(dev);
- }catch(e) {
+ } catch (e) {
console.error(e);
this.selectedCalculator = null;
}
@@ -83,7 +95,7 @@ export default class Home extends Vue {
}
installDrivers() {
- open('https://zadig.akeo.ie/');
+ open('https://lights0123.com/n-link/#windows');
}
}