Account for old setting
This commit is contained in:
@ -950,7 +950,7 @@ export class CameraControls {
|
||||
}
|
||||
|
||||
async centerModelRelativeToPanes(zoomObjectId?: string): Promise<void> {
|
||||
const panes = this.modelingSidebarRef.current
|
||||
const panes = this.modelingSidebarRef?.current
|
||||
if (!panes) return
|
||||
|
||||
const panesWidth = panes.offsetWidth + panes.offsetLeft
|
||||
|
||||
@ -159,7 +159,7 @@ export const EngineStream = () => {
|
||||
}
|
||||
}, [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
|
||||
const timeoutStart = useRef<number | null>(null)
|
||||
|
||||
@ -118,6 +118,8 @@ export class Setting<T = unknown> {
|
||||
}
|
||||
}
|
||||
|
||||
const MS_IN_MINUTE = 1000 * 60
|
||||
|
||||
export function createSettings() {
|
||||
return {
|
||||
/** Settings that affect the behavior of the entire app,
|
||||
@ -186,16 +188,16 @@ export function createSettings() {
|
||||
description: 'Toggle stream idling, saving bandwidth and battery',
|
||||
validate: (v) =>
|
||||
v === null ||
|
||||
(typeof v === 'number' &&
|
||||
Number(v) >= 0 &&
|
||||
Number(v) <= 60),
|
||||
(typeof v === 'number' && Number(v) >= 1 * MS_IN_MINUTE && Number(v) <= 60 * MS_IN_MINUTE),
|
||||
Component: ({ value, updateValue }) => (
|
||||
<div className="flex item-center gap-4 px-2 m-0 py-0">
|
||||
<div className="flex flex-col">
|
||||
<input
|
||||
type="checkbox"
|
||||
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"
|
||||
/>
|
||||
<div></div>
|
||||
@ -203,21 +205,23 @@ export function createSettings() {
|
||||
<div className="flex flex-col grow">
|
||||
<input
|
||||
type="range"
|
||||
onChange={(e) =>
|
||||
updateValue(parseInt(e.currentTarget.value))
|
||||
}
|
||||
onChange={(e) => updateValue(parseInt(e.currentTarget.value) * 1000 * 60)}
|
||||
disabled={value === null}
|
||||
value={value}
|
||||
value={value/MS_IN_MINUTE}
|
||||
min={1}
|
||||
max={60}
|
||||
step={1}
|
||||
className="block flex-1"
|
||||
/>
|
||||
{ value !== null &&
|
||||
<div>
|
||||
{value === 60 ? '1 hour' : value === 1 ? '1 minute' : value + ' minutes'}
|
||||
</div>
|
||||
}
|
||||
{value !== null && (
|
||||
<div>
|
||||
{value/MS_IN_MINUTE === 60
|
||||
? '1 hour'
|
||||
: value/MS_IN_MINUTE === 1
|
||||
? '1 minute'
|
||||
: value/MS_IN_MINUTE + ' minutes'}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
|
||||
@ -5,7 +5,8 @@ pub mod project;
|
||||
use anyhow::Result;
|
||||
use parse_display::{Display, FromStr};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::{de, Deserializer, Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
use validator::{Validate, ValidateRange};
|
||||
|
||||
const DEFAULT_THEME_COLOR: f64 = 264.5;
|
||||
@ -120,11 +121,46 @@ pub struct AppSettings {
|
||||
#[serde(default, alias = "dismissWebBanner", skip_serializing_if = "is_default")]
|
||||
pub dismiss_web_banner: bool,
|
||||
/// When the user is idle, and this is true, the stream will be torn down.
|
||||
#[serde(default, alias = "streamIdleMode", skip_serializing_if = "is_default")]
|
||||
stream_idle_mode: Option<FloatOrInt>,
|
||||
#[serde(default, deserialize_with = "deserialize_stream_idle_mode", alias = "streamIdleMode", skip_serializing_if = "is_default")]
|
||||
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)]
|
||||
#[ts(export)]
|
||||
#[serde(untagged)]
|
||||
|
||||
Reference in New Issue
Block a user