Skip to content

Commit

Permalink
Merge branch 'handling_refactor' of https://github.com/SutekhVRC/Vibe…
Browse files Browse the repository at this point in the history
…Check into handling_refactor
  • Loading branch information
SutekhVRC committed Dec 10, 2023
2 parents f5f65ba + 7a84c86 commit 2345593
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 5,309 deletions.
5,220 changes: 0 additions & 5,220 deletions package-lock.json

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"format:check": "prettier --check --end-of-line=auto \"./src/**/*.{cjs,js,jsx,ts,tsx,html,css,json}\""
},
"dependencies": {
"@heroicons/react": "^2.0.18",
"@radix-ui/react-collapsible": "^1.0.3",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-slider": "^1.1.2",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/bindings/FeVCToy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import type { FeVCToyAnatomy } from "./FeVCToyAnatomy";
import type { FeVCToyFeature } from "./FeVCToyFeature";
import type { ToyPower } from "./ToyPower";

export interface FeVCToy { toy_id: number | null, toy_name: string, toy_anatomy: FeVCToyAnatomy, battery_level: ToyPower, toy_connected: boolean, features: Array<FeVCToyFeature>, listening: boolean, osc_data: boolean, sub_id: number, }
export interface FeVCToy { toy_id: number | null, toy_name: string, toy_anatomy: FeVCToyAnatomy, toy_power: ToyPower, toy_connected: boolean, features: Array<FeVCToyFeature>, listening: boolean, osc_data: boolean, sub_id: number, }
2 changes: 1 addition & 1 deletion src-tauri/src/frontend/frontend_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct FeVCToy {
pub toy_id: Option<u32>,
pub toy_name: String,
pub toy_anatomy: FeVCToyAnatomy,
pub battery_level: ToyPower,
pub toy_power: ToyPower,
pub toy_connected: bool,
pub features: Vec<FeVCToyFeature>,
pub listening: bool,
Expand Down
16 changes: 6 additions & 10 deletions src-tauri/src/osc/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ pub fn recv_osc_cmd(sock: &UdpSocket) -> Option<OscMessage> {
* Toy update loop every 1 sec maybe 5
* How to do parameter structure
* /avatar/parameters/toy_name
* INT SIGS:
* 0 - 100: toy.battery_level
* -1: connected
* -2: disconnected
*
* ATM this only sends a battery life OSC address/value.
*/
Expand Down Expand Up @@ -219,19 +215,19 @@ pub async fn toy_refresh(
sock.connect(remote).await.unwrap();
for (.., mut toy) in toys {
// Can use this to differ between toys with batteries and toys without!
let battery_level = if toy.device_handle.has_battery_level() {
let toy_power = if toy.device_handle.has_battery_level() {
match toy.device_handle.battery_level().await {
Ok(battery_lvl) => ToyPower::Battery(battery_lvl),
Err(_e) => {
warn!("Device battery_level error: {:?}", _e);
warn!("Device battery_level() error: {:?}", _e);
ToyPower::Pending
}
}
} else {
ToyPower::NoBattery
};

toy.battery_level = battery_level.clone();
toy.toy_power = toy_power.clone();

let _ = app_handle.emit_all(
"fe_toy_event",
Expand All @@ -240,7 +236,7 @@ pub async fn toy_refresh(
toy_id: Some(toy.toy_id),
toy_name: toy.toy_name.clone(),
toy_anatomy: toy.config.as_ref().unwrap().anatomy.to_fe(),
battery_level: battery_level.clone(),
toy_power: toy_power.clone(),
toy_connected: toy.toy_connected,
features: toy.parsed_toy_features.features.to_frontend(),
listening: toy.listening,
Expand All @@ -262,7 +258,7 @@ pub async fn toy_refresh(
.to_lowercase(),
toy.sub_id
),
args: vec![OscType::Float(battery_level.to_float() as f32)],
args: vec![OscType::Float(toy_power.to_float() as f32)],
}))
.unwrap();

Expand All @@ -272,7 +268,7 @@ pub async fn toy_refresh(
} else {
info!(
"Sent battery_level: {} to {}",
battery_level.to_float() as f32,
toy_power.to_float() as f32,
toy.toy_name
);
}
Expand Down
10 changes: 5 additions & 5 deletions src-tauri/src/toy_handling/handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ pub async fn client_event_handler(
Delay::new(Duration::from_secs(3)).await;

// Can use this to differ between toys with batteries and toys without!
let battery_level = if dev.has_battery_level() {
let toy_power = if dev.has_battery_level() {
match dev.battery_level().await {
Ok(battery_lvl) => ToyPower::Battery(battery_lvl),
Err(_e) => {
warn!("Device battery_level error: {:?}", _e);
warn!("Device battery_level() error: {:?}", _e);
ToyPower::Pending
}
}
Expand Down Expand Up @@ -116,7 +116,7 @@ pub async fn client_event_handler(
let mut toy = VCToy {
toy_id: dev.index(),
toy_name: dev.name().clone(),
battery_level: battery_level.clone(),
toy_power: toy_power.clone(),
toy_connected: dev.connected(),
toy_features: dev.message_attributes().clone(),
parsed_toy_features: VCToyFeatures::new(),
Expand Down Expand Up @@ -168,7 +168,7 @@ pub async fn client_event_handler(
toy_id: Some(toy.toy_id),
toy_name: toy.toy_name.clone(),
toy_anatomy: toy.config.as_ref().unwrap().anatomy.to_fe(),
battery_level,
toy_power,
toy_connected: toy.toy_connected,
features: toy.parsed_toy_features.features.to_frontend(),
listening: toy.listening,
Expand All @@ -184,7 +184,7 @@ pub async fn client_event_handler(
let _ = Notification::new(identifier.clone())
.title("Toy Connected")
.body(
format!("{} ({})", toy.toy_name, toy.battery_level.to_string())
format!("{} ({})", toy.toy_name, toy.toy_power.to_string())
.as_str(),
)
.show();
Expand Down
33 changes: 1 addition & 32 deletions src-tauri/src/toy_handling/toy_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ impl ToyManager {
}

pub fn sync_frontend(&mut self, refresh_toys: bool) -> Vec<FeVCToy> {
/*
let _res = self.app_handle.emit_all("fe_toy_event",
FeToyEvent::OfflineSyncAll({
offline_fetoy_vec
}),
);*/

if refresh_toys {
info!("Clearing toy manager configs map and repopulating from disk..");
self.configs.clear();
Expand Down Expand Up @@ -120,7 +113,7 @@ impl ToyManager {
toy_id: None,
toy_name: config.toy_name.clone(),
toy_anatomy: config.anatomy.to_fe(),
battery_level: super::ToyPower::Offline,
toy_power: super::ToyPower::Offline,
toy_connected: false,
features: config.features.features.to_frontend(),
listening: false,
Expand All @@ -131,28 +124,4 @@ impl ToyManager {

offline_toy_vec
}

/*
fn fetoy_vec_from_online_toys(&self) -> Vec<FeVCToy> {
let mut online_toy_vec = Vec::new();
self.online_toys.iter().for_each(|(_toy_id, online_toy)| {
online_toy_vec.push(
FeVCToy {
toy_id: Some(online_toy.toy_id),
toy_name: online_toy.toy_name.clone(),
toy_anatomy: online_toy.config.as_ref().unwrap().anatomy.to_fe(),
battery_level: online_toy.battery_level,
toy_connected: online_toy.toy_connected,
features: online_toy.param_feature_map.to_fe(),
listening: online_toy.listening,
osc_data: online_toy.osc_data,
sub_id: online_toy.sub_id,
});
});
online_toy_vec
}
*/
}
2 changes: 1 addition & 1 deletion src-tauri/src/toy_handling/toyops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use super::ToyPower;
pub struct VCToy {
pub toy_id: u32,
pub toy_name: String,
pub battery_level: ToyPower,
pub toy_power: ToyPower,
pub toy_connected: bool,
pub toy_features: ClientDeviceMessageAttributes,
pub parsed_toy_features: VCToyFeatures,
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/vcore/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ pub fn native_alter_toy(
toy_id: Some(alter_clone.toy_id),
toy_name: alter_clone.toy_name,
toy_anatomy: alter_clone.config.as_ref().unwrap().anatomy.to_fe(),
battery_level: alter_clone.battery_level,
toy_power: alter_clone.toy_power,
toy_connected: alter_clone.toy_connected,
features: alter_clone.parsed_toy_features.features.to_frontend(),
listening: alter_clone.listening,
Expand Down
4 changes: 2 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Cog6ToothIcon } from "@heroicons/react/24/solid";
import { AnimatePresence } from "framer-motion";
import { Settings } from "lucide-react";
import { useState } from "react";
import { FeVCToy } from "../src-tauri/bindings/FeVCToy";
import "./App.css";
Expand Down Expand Up @@ -155,7 +155,7 @@ export default function App() {
</div>
<div className="flex justify-around items-center">
<UpdatePing canUpdate={canUpdate}>
<Cog6ToothIcon
<Settings
className={cn(
selection?.type == "Config" && "rotate-45",
"h-10 cursor-pointer transform duration-300 ease-in-out",
Expand Down
39 changes: 26 additions & 13 deletions src/components/BatteryIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
import {
Battery0Icon,
Battery100Icon,
Battery50Icon,
BoltSlashIcon,
} from "@heroicons/react/24/solid";
BatteryFull,
BatteryLow,
BatteryMedium,
BatteryWarning,
Hourglass,
Plug,
WifiOff,
} from "lucide-react";
import { CSSProperties } from "react";
import { ToyPower } from "src-tauri/bindings/ToyPower";
import Tooltip from "../layout/Tooltip";
import { percent } from "../utils";

export default function Batteryicon({ battery }: { battery: number | null }) {
export default function Batteryicon({ toyPower }: { toyPower: ToyPower }) {
let tooltipText = "";
let iconComponent: JSX.Element;
let iconStyle: CSSProperties = {};

if (battery == null) {
if (toyPower == "NoBattery") {
tooltipText = "No battery";
iconComponent = <BoltSlashIcon className="h-6" />;
iconComponent = <Plug className="h-6" />;
} else if (toyPower == "Offline") {
tooltipText = "Offline";
iconComponent = <WifiOff className="h-6" />;
} else if (toyPower == "Pending") {
tooltipText = "Pending";
iconComponent = <Hourglass className="h-6" />;
} else {
const battery = toyPower.Battery;
tooltipText = percent.format(battery);
iconStyle = { color: `hsl(${battery * 120}, 75%, 50%)` };
if (battery <= 0.15) {
iconComponent = <Battery0Icon className="h-8" />;
} else if (battery <= 0.5) {
iconComponent = <Battery50Icon className="h-8" />;
if (battery <= 0.1) {
iconComponent = <BatteryWarning className="h-8" />;
} else if (battery <= 0.4) {
iconComponent = <BatteryLow className="h-8" />;
} else if (battery <= 0.7) {
iconComponent = <BatteryMedium className="h-8" />;
} else {
iconComponent = <Battery100Icon className="h-8" />;
iconComponent = <BatteryFull className="h-8" />;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/FourPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArrowsRightLeftIcon } from "@heroicons/react/24/solid";
import { ArrowRightLeft } from "lucide-react";
import { ReactNode } from "react";
import { TooltipLabel } from "../layout/Tooltip";

Expand Down Expand Up @@ -27,7 +27,7 @@ export default function FourPanel({
{flipped ? (
<div className="flex items-center gap-2">
{label}
<ArrowsRightLeftIcon className="h-4" />
<ArrowRightLeft className="h-4" />
</div>
) : (
label
Expand Down
6 changes: 3 additions & 3 deletions src/features/FeatureForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button } from "@/components/ui/button";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Select } from "@/layout/Select";
import { PlusIcon, XMarkIcon } from "@heroicons/react/24/solid";
import { Plus, X } from "lucide-react";
import { ChangeEvent, useEffect, useState } from "react";
import { FeProcessingMode } from "src-tauri/bindings/FeProcessingMode";
import { FeToyParameter } from "src-tauri/bindings/FeToyParameter";
Expand Down Expand Up @@ -187,7 +187,7 @@ export default function FeatureForm({
className="flex justify-center"
onClick={() => removeParam(param.parameter)}
>
<XMarkIcon className="h-5" />
<X className="h-5" />
</button>
</>
);
Expand All @@ -196,7 +196,7 @@ export default function FeatureForm({
</div>
<div className="flex flex-col justify-center">
<Button onClick={() => addParam()}>
<PlusIcon className="h-6" />
<Plus className="h-6" />
</Button>
</div>
</div>
Expand Down
16 changes: 6 additions & 10 deletions src/features/Toy.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect, useState } from "react";
import { ToyPower } from "src-tauri/bindings/ToyPower";
import { FeVCToy } from "../../src-tauri/bindings/FeVCToy";
import lovenseLogo from "../assets/Lovense.png";
import lovenseConnectLogo from "../assets/Lovense_Connect.png";
Expand All @@ -19,13 +20,8 @@ export default function Toy({ toy }: { toy: FeVCToy }) {
return (
<div className="w-full h-full">
<div className="text-4xl flex justify-between items-center px-6">
<div className="flex items-end gap-2">
<div>{nameInfo.shortName}</div>
{!toy.toy_connected && (
<div className="text-sm text-zinc-400">offline</div>
)}
</div>
<ToyInfo nameInfo={nameInfo} battery={toy.battery_level} />
<div>{nameInfo.shortName}</div>
<ToyInfo nameInfo={nameInfo} toyPower={toy.toy_power} />
</div>
<div className="m-4 overflow-hidden h-full">
<ToySettings toy={toy} />
Expand Down Expand Up @@ -90,10 +86,10 @@ function NameInfo(toy: FeVCToy): NameInfo {

function ToyInfo({
nameInfo,
battery,
toyPower,
}: {
nameInfo: NameInfo;
battery: number | null;
toyPower: ToyPower;
}) {
return (
<div className="flex gap-x-4 items-center">
Expand All @@ -102,7 +98,7 @@ function ToyInfo({
<img className="max-h-6 rounded-lg cursor-help" src={nameInfo.logo} />
</Tooltip>
)}
<BatteryIcon battery={battery} />
<BatteryIcon toyPower={toyPower} />
</div>
);
}
4 changes: 2 additions & 2 deletions src/features/ToySettings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClipboardIcon } from "@heroicons/react/24/solid";
import { ClipboardCopy } from "lucide-react";
import type { FeVCToy } from "../../src-tauri/bindings/FeVCToy";
import { FeVCToyAnatomy } from "../../src-tauri/bindings/FeVCToyAnatomy";
import FourPanel from "../components/FourPanel";
Expand Down Expand Up @@ -37,7 +37,7 @@ export default function ToySettings({ toy }: { toy: FeVCToy }) {
/>
{toy.toy_connected && (
<Tooltip text="Copy osc data address to clipboard">
<ClipboardIcon
<ClipboardCopy
onClick={handleCopy}
className="h-4 cursor-pointer"
/>
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,6 @@
resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.1.6.tgz#22958c042e10b67463997bd6ea7115fe28cbcaf9"
integrity sha512-OfX7E2oUDYxtBvsuS4e/jSn4Q9Qb6DzgeYtsAdkPZ47znpoNsMgZw0+tVijiv3uGNR6dgNlty6r9rzIzHjtd/A==

"@heroicons/react@^2.0.18":
version "2.0.18"
resolved "https://registry.yarnpkg.com/@heroicons/react/-/react-2.0.18.tgz#f80301907c243df03c7e9fd76c0286e95361f7c1"
integrity sha512-7TyMjRrZZMBPa+/5Y8lN0iyvUU/01PeMGX2+RE7cQWpEUIcb4QotzUObFkJDejj/HUH4qjP/eQ0gzzKs2f+6Yw==

"@humanwhocodes/config-array@^0.11.13":
version "0.11.13"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.13.tgz#075dc9684f40a531d9b26b0822153c1e832ee297"
Expand Down

0 comments on commit 2345593

Please sign in to comment.