Account for old setting
This commit is contained in:
@ -950,7 +950,7 @@ export class CameraControls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async centerModelRelativeToPanes(zoomObjectId?: string): Promise<void> {
|
async centerModelRelativeToPanes(zoomObjectId?: string): Promise<void> {
|
||||||
const panes = this.modelingSidebarRef.current
|
const panes = this.modelingSidebarRef?.current
|
||||||
if (!panes) return
|
if (!panes) return
|
||||||
|
|
||||||
const panesWidth = panes.offsetWidth + panes.offsetLeft
|
const panesWidth = panes.offsetWidth + panes.offsetLeft
|
||||||
|
|||||||
@ -159,7 +159,7 @@ export const EngineStream = () => {
|
|||||||
}
|
}
|
||||||
}, [file?.path, engineCommandManager.engineConnection])
|
}, [file?.path, engineCommandManager.engineConnection])
|
||||||
|
|
||||||
const IDLE_TIME_MS = Number(streamIdleMode) * 1000 * 60
|
const IDLE_TIME_MS = Number(streamIdleMode)
|
||||||
|
|
||||||
// When streamIdleMode is changed, setup or teardown the timeouts
|
// When streamIdleMode is changed, setup or teardown the timeouts
|
||||||
const timeoutStart = useRef<number | null>(null)
|
const timeoutStart = useRef<number | null>(null)
|
||||||
|
|||||||
@ -118,6 +118,8 @@ export class Setting<T = unknown> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MS_IN_MINUTE = 1000 * 60
|
||||||
|
|
||||||
export function createSettings() {
|
export function createSettings() {
|
||||||
return {
|
return {
|
||||||
/** Settings that affect the behavior of the entire app,
|
/** Settings that affect the behavior of the entire app,
|
||||||
@ -186,16 +188,16 @@ export function createSettings() {
|
|||||||
description: 'Toggle stream idling, saving bandwidth and battery',
|
description: 'Toggle stream idling, saving bandwidth and battery',
|
||||||
validate: (v) =>
|
validate: (v) =>
|
||||||
v === null ||
|
v === null ||
|
||||||
(typeof v === 'number' &&
|
(typeof v === 'number' && Number(v) >= 1 * MS_IN_MINUTE && Number(v) <= 60 * MS_IN_MINUTE),
|
||||||
Number(v) >= 0 &&
|
|
||||||
Number(v) <= 60),
|
|
||||||
Component: ({ value, updateValue }) => (
|
Component: ({ value, updateValue }) => (
|
||||||
<div className="flex item-center gap-4 px-2 m-0 py-0">
|
<div className="flex item-center gap-4 px-2 m-0 py-0">
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={value !== null}
|
checked={value !== null}
|
||||||
onChange={(e) => updateValue(!e.currentTarget.checked ? null : 5)}
|
onChange={(e) =>
|
||||||
|
updateValue(!e.currentTarget.checked ? null : 5 * 1000 * 60)
|
||||||
|
}
|
||||||
className="block w-4 h-4"
|
className="block w-4 h-4"
|
||||||
/>
|
/>
|
||||||
<div></div>
|
<div></div>
|
||||||
@ -203,21 +205,23 @@ export function createSettings() {
|
|||||||
<div className="flex flex-col grow">
|
<div className="flex flex-col grow">
|
||||||
<input
|
<input
|
||||||
type="range"
|
type="range"
|
||||||
onChange={(e) =>
|
onChange={(e) => updateValue(parseInt(e.currentTarget.value) * 1000 * 60)}
|
||||||
updateValue(parseInt(e.currentTarget.value))
|
|
||||||
}
|
|
||||||
disabled={value === null}
|
disabled={value === null}
|
||||||
value={value}
|
value={value/MS_IN_MINUTE}
|
||||||
min={1}
|
min={1}
|
||||||
max={60}
|
max={60}
|
||||||
step={1}
|
step={1}
|
||||||
className="block flex-1"
|
className="block flex-1"
|
||||||
/>
|
/>
|
||||||
{ value !== null &&
|
{value !== null && (
|
||||||
<div>
|
<div>
|
||||||
{value === 60 ? '1 hour' : value === 1 ? '1 minute' : value + ' minutes'}
|
{value/MS_IN_MINUTE === 60
|
||||||
|
? '1 hour'
|
||||||
|
: value/MS_IN_MINUTE === 1
|
||||||
|
? '1 minute'
|
||||||
|
: value/MS_IN_MINUTE + ' minutes'}
|
||||||
</div>
|
</div>
|
||||||
}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
|
|||||||
@ -5,7 +5,8 @@ pub mod project;
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use parse_display::{Display, FromStr};
|
use parse_display::{Display, FromStr};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{de, Deserializer, Deserialize, Serialize};
|
||||||
|
use std::fmt;
|
||||||
use validator::{Validate, ValidateRange};
|
use validator::{Validate, ValidateRange};
|
||||||
|
|
||||||
const DEFAULT_THEME_COLOR: f64 = 264.5;
|
const DEFAULT_THEME_COLOR: f64 = 264.5;
|
||||||
@ -120,11 +121,46 @@ pub struct AppSettings {
|
|||||||
#[serde(default, alias = "dismissWebBanner", skip_serializing_if = "is_default")]
|
#[serde(default, alias = "dismissWebBanner", skip_serializing_if = "is_default")]
|
||||||
pub dismiss_web_banner: bool,
|
pub dismiss_web_banner: bool,
|
||||||
/// When the user is idle, and this is true, the stream will be torn down.
|
/// When the user is idle, and this is true, the stream will be torn down.
|
||||||
#[serde(default, alias = "streamIdleMode", skip_serializing_if = "is_default")]
|
#[serde(default, deserialize_with = "deserialize_stream_idle_mode", alias = "streamIdleMode", skip_serializing_if = "is_default")]
|
||||||
stream_idle_mode: Option<FloatOrInt>,
|
stream_idle_mode: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: When we remove backwards compatibility with the old settings file, we can remove this.
|
fn deserialize_stream_idle_mode<'de, D>(deserializer: D) -> Result<Option<u64>, D::Error>
|
||||||
|
where D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
struct StreamIdleMode;
|
||||||
|
|
||||||
|
impl<'de> de::Visitor<'de> for StreamIdleMode
|
||||||
|
{
|
||||||
|
type Value = Option<u64>;
|
||||||
|
|
||||||
|
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
formatter.write_str("boolean or integer")
|
||||||
|
}
|
||||||
|
|
||||||
|
// In an older config, stream idle mode used to be a boolean (on/off)
|
||||||
|
// I'm willing to say almost no one used the option.
|
||||||
|
fn visit_bool<E>(self, value: bool) -> Result<Option<u64>, E>
|
||||||
|
where E: de::Error
|
||||||
|
{
|
||||||
|
if value {
|
||||||
|
Ok(Some(1000 * 60 * 5))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_i64<E>(self, value: i64) -> Result<Option<u64>, E>
|
||||||
|
where E: de::Error
|
||||||
|
{
|
||||||
|
Ok(Some(value.try_into().unwrap()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deserializer.deserialize_any(StreamIdleMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, ts_rs::TS, PartialEq)]
|
#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, ts_rs::TS, PartialEq)]
|
||||||
#[ts(export)]
|
#[ts(export)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
|
|||||||
Reference in New Issue
Block a user