Skip to content

Commit

Permalink
Merge branch 'develop' into release/1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphiiko committed Jun 19, 2024
2 parents d360273 + c924a5e commit 24ce922
Show file tree
Hide file tree
Showing 106 changed files with 914 additions and 590 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Automation for disabling the sleep mode when you've been upright for long enough after laying down.
- Automation for automatically disabling the sleep mode when a (certain) VRChat user joins or leaves your world.
- Automation trigger for the shutdown sequence to run when you've been left alone in your VRChat world instance for a certain amount of time.
- Ukranian language support (Community contribution by [senkodev](https://x.com/senkodev) and [Fanyatsu](https://fanyat.su/))
- Ukrainian language support (Community contribution by [senkodev](https://x.com/senkodev) and [Fanyatsu](https://fanyat.su/))
- Additional configuration options for the sleep detector (controller presence, sleeping pose)
- Options for forcing the power state of base stations (Right click the power button).
- Support for base stations that don't report their status. (Newer lighthouses sold through Valve, likely manufactured by HTC)
- Optional fix to delay initializing OyasumiVR with OpenVR.
- OVRToolkit as a notification provider
- Support for string parameters in OSC scripts (Community contribution by [Fanyatsu](https://fanyat.su/))
- Support for sending multiple parameters in OSC scripts (Community contribution by [Fanyatsu](https://fanyat.su/))

### Changed

Expand Down
4 changes: 1 addition & 3 deletions src-core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ fn configure_command_handlers() -> impl Fn(tauri::Invoke) {
os::commands::set_hardware_mic_activivation_threshold,
os::commands::is_vrchat_active,
os::commands::activate_memory_watcher,
osc::commands::osc_send_bool,
osc::commands::osc_send_float,
osc::commands::osc_send_int,
osc::commands::osc_send_command,
osc::commands::osc_valid_addr,
osc::commands::start_osc_server,
osc::commands::stop_osc_server,
Expand Down
60 changes: 38 additions & 22 deletions src-core/src/osc/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ use super::{OSC_RECEIVE_SOCKET, OSC_SEND_SOCKET};
use log::{debug, error, info};
use oyasumivr_oscquery::OSCMethod;
use rosc::{encoder, OscMessage, OscPacket, OscType};
use serde::{Deserialize, Serialize};
use std::{
net::{SocketAddrV4, UdpSocket},
str::FromStr,
};
use tokio::sync::Mutex;
use tokio_util::sync::CancellationToken;

#[derive(Serialize, Deserialize, Debug)]
pub enum SupportedOscType {
INT,
FLOAT,
BOOLEAN,
STRING,
}

lazy_static! {
static ref CANCELLATION_TOKEN: Mutex<Option<CancellationToken>> = Default::default();
}
Expand Down Expand Up @@ -112,32 +121,39 @@ pub async fn set_osc_method_value(address: String, value: String) {

#[tauri::command]
#[oyasumivr_macros::command_profiling]
pub async fn osc_send_int(addr: String, osc_addr: String, data: i32) -> Result<bool, String> {
pub async fn osc_send_command(
addr: String,
osc_addr: String,
types: Vec<SupportedOscType>,
values: Vec<String>,
) -> Result<bool, String> {
debug!(
"[Core] Sending OSC command (address={}, type={}, value={})",
osc_addr, "int", data
"[Core] Sending OSC command (address={}, types={:?}, values={:?})",
osc_addr, types, values
);
osc_send(addr, osc_addr, vec![OscType::Int(data)]).await
}

#[tauri::command]
#[oyasumivr_macros::command_profiling]
pub async fn osc_send_float(addr: String, osc_addr: String, data: f32) -> Result<bool, String> {
debug!(
"[Core] Sending OSC command (address={}, type={}, value={})",
osc_addr, "float", data
);
osc_send(addr, osc_addr, vec![OscType::Float(data)]).await
}
let mut data = Vec::new();

#[tauri::command]
#[oyasumivr_macros::command_profiling]
pub async fn osc_send_bool(addr: String, osc_addr: String, data: bool) -> Result<bool, String> {
debug!(
"[Core] Sending OSC command (address={}, type={}, value={})",
osc_addr, "bool", data
);
osc_send(addr, osc_addr, vec![OscType::Bool(data)]).await
for (osc_type, value) in types.into_iter().zip(values.into_iter()) {
let osc_value = match osc_type {
SupportedOscType::INT => value
.parse::<i32>()
.map(OscType::Int)
.map_err(|_| String::from("INVALID_INT_VALUE"))?,
SupportedOscType::FLOAT => value
.parse::<f32>()
.map(OscType::Float)
.map_err(|_| String::from("INVALID_FLOAT_VALUE"))?,
SupportedOscType::BOOLEAN => value
.parse::<bool>()
.map(OscType::Bool)
.map_err(|_| String::from("INVALID_BOOL_VALUE"))?,
SupportedOscType::STRING => OscType::String(value),
};
data.push(osc_value);
}

osc_send(addr, osc_addr, data).await
}

#[tauri::command]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, DestroyRef, OnInit } from '@angular/core';
import { BaseModalComponent } from '../base-modal/base-modal.component';
import { MqttService } from '../../services/mqtt/mqtt.service';
import { AppSettingsService } from '../../services/app-settings.service';
import { cloneDeep } from 'lodash';

import { APP_SETTINGS_DEFAULT } from '../../models/settings';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { fadeUp, hshrink, vshrink } from '../../utils/animations';
Expand All @@ -16,7 +16,7 @@ import { error } from 'tauri-plugin-log-api';
animations: [fadeUp(), hshrink(), vshrink()],
})
export class MqttConfigModalComponent extends BaseModalComponent<void, void> implements OnInit {
config = MqttService.mapAppSettingsToMqttConfig(cloneDeep(APP_SETTINGS_DEFAULT));
config = MqttService.mapAppSettingsToMqttConfig(structuredClone(APP_SETTINGS_DEFAULT));
testResult: 'idle' | 'testing' | 'success' | 'error' = 'idle';
testError = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,20 @@ export class OscScriptCodeEditorComponent implements OnInit, AfterViewInit {
case 'SLEEP':
return `sleep ${command.duration}ms`;
case 'COMMAND': {
const type = { FLOAT: 'f', INT: 'i', BOOLEAN: 'b' }[
command.parameterType
] as OscParameterType;
const value = {
FLOAT: (v: string) => parseFloat(v),
INT: (v: string) => parseInt(v),
BOOLEAN: (v: string) => (v === 'true' ? 'true' : 'false'),
}[command.parameterType](command.value);
return `${type} ${value} ${command.address}`;
let commandParametersString = '';
command.parameters.forEach((parameter) => {
const type = { FLOAT: 'f', INT: 'i', BOOLEAN: 'b', STRING: 's' }[
parameter.type
] as OscParameterType;
const value = {
FLOAT: (v: string) => parseFloat(v),
INT: (v: string) => parseInt(v),
BOOLEAN: (v: string) => (v === 'true' ? 'true' : 'false'),
STRING: (v: string) => `"${v.replace(/"/g, '\\"')}"`, // put string into quotes and escape all inner quoutes
}[parameter.type](parameter.value);
commandParametersString += `${type} ${value} `;
});
return commandParametersString + command.address;
}
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
@import '@fontsource/fira-code/index.css';

:host {
top: 16px;
}

.modal-inner-wrapper {
height: 100%;
width: 100%;
max-width: min(1280px, calc(100% - 4em));
max-height: min(720px, calc(100% - 4em));
max-height: min(720px, calc(100% - 4em - 32px));
}

.modal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class OscScriptModalComponent
ngOnInit(): void {
if (!this.script) {
this.script = {
version: 1,
version: 2,
commands: [],
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,49 +35,86 @@
</div>
<div class="simple-command-index">{{ i + 1 }}.</div>
<div class="simple-command-action" translate>comp.osc-script-simple-editor.action.osc</div>
<app-select-box
[type]="'SMALL'"
[selected]="getSelectedParameterTypeForCommand(command)"
[items]="parameterTypeSelectItems"
(selectedChange)="setSelectedParameterTypeForCommand(command, $event!)"
[showPlaceholderInDropdown]="false"
class="simple-command-type-input"
></app-select-box>
<app-select-box
class="simple-command-boolean-input"
*ngIf="command.parameterType === 'BOOLEAN'"
[type]="'SMALL'"
[selected]="getSelectedBooleanValueForCommand(command)"
[items]="[
{ id: 'true', label: 'true' },
{ id: 'false', label: 'false' }
]"
(selectedChange)="setBoolValue(command, $event!)"
[showPlaceholderInDropdown]="false"
></app-select-box>
<div
class="input-wrapper simple-command-integer-input"
*ngIf="command.parameterType === 'INT'"
>
<input
type="number"
step="1"
min="0"
max="255"
[value]="command.value"
(change)="setIntValue(command, $event)"
/>
</div>
<div
class="input-wrapper simple-command-float-input"
*ngIf="command.parameterType === 'FLOAT'"
>
<input
type="number"
step="0.001"
[value]="command.value"
(change)="setFloatValue(command, $event)"
/>
<div class="simple-command-parameters-container">
<div
*ngFor="let parameter of command.parameters; let j = index"
class="simple-command-parameter-row"
@vshrink
>
<app-select-box
[type]="'SMALL'"
[selected]="getCommandParameterType(command, j)"
[items]="parameterTypeSelectItems"
(selectedChange)="setCommandParameterType(command, j, $event!)"
[showPlaceholderInDropdown]="false"
class="simple-command-type-input"
></app-select-box>
<app-select-box
class="simple-command-boolean-input"
*ngIf="getCommandParameterType(command, j)?.id === 'BOOLEAN'"
[type]="'SMALL'"
[selected]="{ id: parameter.value, label: parameter.value }"
[items]="[
{ id: 'true', label: 'true' },
{ id: 'false', label: 'false' }
]"
(selectedChange)="setBoolValue(command, j, $event!)"
[showPlaceholderInDropdown]="false"
></app-select-box>
<div
class="input-wrapper simple-command-integer-input"
*ngIf="getCommandParameterType(command, j)?.id === 'INT'"
>
<input
type="number"
step="1"
min="0"
max="255"
[value]="parameter.value"
(change)="setIntValue(command, j, $event)"
/>
</div>
<div
class="input-wrapper simple-command-float-input"
*ngIf="getCommandParameterType(command, j)?.id === 'FLOAT'"
>
<input
type="number"
step="0.001"
[value]="parameter.value"
(change)="setFloatValue(command, j, $event)"
/>
</div>
<div
class="input-wrapper simple-command-string-input"
*ngIf="getCommandParameterType(command, j)?.id === 'STRING'"
>
<input
type="text"
[max]="MAX_STRING_VALUE_LENGTH"
[value]="parameter.value"
(change)="setStringValue(command, j, $event)"
/>
</div>
<button
class="btn simple-command-remove-button"
*ngIf="command.parameters.length > 1"
(click)="removeParameter(i, j)"
@hshrink
>
<i class="material-icons">clear</i>
</button>
</div>
<div>
<button
class="btn btn-secondary btn-add-parameter"
*ngIf="command.parameters.length < MAX_PARAMETERS_PER_COMMAND"
(click)="addParameter(i)"
>
<i class="material-icons">add</i>
<span translate>comp.osc-script-simple-editor.addParameter</span>
</button>
</div>
</div>
<div class="input-wrapper simple-command-address-input">
<input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@
.simple-command {
display: flex;
flex-direction: row;
align-items: center;
align-items: flex-start;
gap: 0.5em;
padding: 0.5em 1em;
background: var(--color-surface-1);

& > * {
display: flex;
min-height: 2.5em;
}

&:not(:first-child) {
border-top: 1px solid var(--color-surface-3);
}
Expand Down Expand Up @@ -96,16 +102,23 @@
&-index {
font-weight: 600;
margin-right: 0.5em;
display: flex;
flex-direction: row;
align-items: center;
}

&-action {
margin-right: 0.5em;
display: flex;
flex-direction: row;
align-items: center;
}

&-type-input,
&-boolean-input,
&-integer-input,
&-float-input {
&-float-input,
&-string-input {
margin-right: 0.5em;
width: 8em;

Expand All @@ -115,6 +128,10 @@
}
}

&-string-input {
width: 24em;
}

&-address-input {
flex: 1;

Expand All @@ -126,7 +143,6 @@

&-remove-button {
padding: 0;
margin-left: 1em;

i.material-icons {
margin: 0;
Expand All @@ -138,6 +154,21 @@
width: 5em;
}
}

&-parameters-container {
display: flex;
flex-direction: column;
gap: 0.5em;
}

&-parameter-row {
display: flex;
align-items: center;
}

.btn-add-parameter {
min-height: 2.5em;
}
}

.error-tooltip {
Expand Down
Loading

0 comments on commit 24ce922

Please sign in to comment.