From a30a70c6b5c2bf114e3bbae6071afa023254b351 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Sat, 7 Jan 2023 19:19:44 +0100 Subject: [PATCH] get UI to somewhat work. TODO: get scripts to work --- src/common/js/utils.ts | 8 ++++- src/csui/src/PlayerUIWindow.vue | 4 +++ .../SiteExtensionSettings.vue | 7 ++--- .../VideoSettings/CropOptionsPanel.vue | 14 +++------ .../VideoSettings/StretchOptionsPanel.vue | 12 ++------ .../VideoSettings/ZoomOptionsPanel.vue | 5 ++-- src/csui/src/PlayerUiPanels/VideoSettings.vue | 16 ++++------ src/ext/lib/settings/SiteSettings.ts | 30 +++++++++++-------- 8 files changed, 46 insertions(+), 50 deletions(-) diff --git a/src/common/js/utils.ts b/src/common/js/utils.ts index 1536751..0631ba4 100644 --- a/src/common/js/utils.ts +++ b/src/common/js/utils.ts @@ -8,5 +8,11 @@ export async function sleep(timeout) { * @returns */ export function _cp(obj) { - return JSON.parse(JSON.stringify(obj)); + try { + return JSON.parse(JSON.stringify(obj)); + } catch (e) { + console.error('Failed to parse json. This probably means that the data we received was not an object. Will return data as-is'); + console.error('data in:', obj, 'error:', e); + return obj; + } } diff --git a/src/csui/src/PlayerUIWindow.vue b/src/csui/src/PlayerUIWindow.vue index 7870783..cf54cf1 100644 --- a/src/csui/src/PlayerUIWindow.vue +++ b/src/csui/src/PlayerUIWindow.vue @@ -87,12 +87,14 @@ @@ -100,11 +102,13 @@ diff --git a/src/csui/src/PlayerUiPanels/PanelComponents/ExtensionSettings/SiteExtensionSettings.vue b/src/csui/src/PlayerUiPanels/PanelComponents/ExtensionSettings/SiteExtensionSettings.vue index d32ed02..7b7f9de 100644 --- a/src/csui/src/PlayerUiPanels/PanelComponents/ExtensionSettings/SiteExtensionSettings.vue +++ b/src/csui/src/PlayerUiPanels/PanelComponents/ExtensionSettings/SiteExtensionSettings.vue @@ -131,8 +131,7 @@ export default { ], props: [ - 'settings', - 'site', + 'siteSettings', 'isDefaultConfiguration' ], components: { @@ -141,12 +140,12 @@ export default { computed: { siteDefaultCrop() { return JSON.stringify( - this.settings?.getDefaultCrop(this.site) ?? {type: this.site === '@global' ? AspectRatioType.Automatic : AspectRatioType.Default} + this.siteSettings.data.defaults.crop ); }, siteDefaultStretch() { return JSON.stringify( - this.settings?.getDefaultStretch(this.site) ?? {type: this.site === '@global' ? StretchMode.NoStretch : StretchMode.Default} + this.siteSettings.data.defaults.stretch ); }, siteDefaultCropPersistence() { diff --git a/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/CropOptionsPanel.vue b/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/CropOptionsPanel.vue index 9100ed9..70ca7e7 100644 --- a/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/CropOptionsPanel.vue +++ b/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/CropOptionsPanel.vue @@ -165,10 +165,9 @@ export default { CommsMixin ], props: [ - 'settings', - 'frame', + 'settings', // required for buttons and actions, which are global + 'siteSettings', 'eventBus', - 'site', 'isEditing' ], components: { @@ -176,14 +175,9 @@ export default { EditShortcutButton, }, computed: { - extensionDefaultCrop() { - return JSON.stringify( - this.settings?.active.crop?.default ?? {type: AspectRatioType.Automatic} - ); - }, siteDefaultCrop() { return JSON.stringify( - this.settings?.getDefaultCrop(this.site) ?? {type: AspectRatioType.Automatic} + this.siteSettings.data.defaults.crop ); }, }, @@ -215,7 +209,7 @@ export default { return false; } - const defaultCrop = this.settings.getDefaultCrop(this.site); + const defaultCrop = this.siteSettings.data.defaults.crop; if (cropCommand.arguments.type === AspectRatioType.Automatic) { return this.resizerConfig.crop.type === AspectRatioType.Automatic diff --git a/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/StretchOptionsPanel.vue b/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/StretchOptionsPanel.vue index 128a0dc..315dede 100644 --- a/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/StretchOptionsPanel.vue +++ b/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/StretchOptionsPanel.vue @@ -198,10 +198,9 @@ export default { CommsMixin ], props: [ - 'settings', - 'frame', + 'settings', // required for buttons and actions, which are global + 'siteSettings', 'eventBus', - 'site', 'isEditing' ], components: { @@ -209,14 +208,9 @@ export default { EditShortcutButton, }, computed: { - extensionDefaultStretch() { - return JSON.stringify( - this.settings?.active.stretch?.default ?? {type: StretchMode.NoStretch} - ); - }, siteDefaultStretch() { return JSON.stringify( - this.settings?.getDefaultStretch(this.site) ?? {type: StretchMode.NoStretch} + this.siteSettings.data.defaults.stretch ); }, }, diff --git a/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/ZoomOptionsPanel.vue b/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/ZoomOptionsPanel.vue index cfa0650..b4531cf 100644 --- a/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/ZoomOptionsPanel.vue +++ b/src/csui/src/PlayerUiPanels/PanelComponents/VideoSettings/ZoomOptionsPanel.vue @@ -100,10 +100,9 @@ export default { ], props: [ - 'settings', - 'frame', + 'settings', // required for buttons and actions, which are global + 'siteSettings', 'eventBus', - 'site', 'isEditing' ], methods: { diff --git a/src/csui/src/PlayerUiPanels/VideoSettings.vue b/src/csui/src/PlayerUiPanels/VideoSettings.vue index 36066e9..3fe1e0f 100644 --- a/src/csui/src/PlayerUiPanels/VideoSettings.vue +++ b/src/csui/src/PlayerUiPanels/VideoSettings.vue @@ -39,10 +39,8 @@ @@ -57,10 +55,8 @@ @@ -75,10 +71,9 @@ @@ -142,7 +137,8 @@ export default { CommsMixin, ], props: [ - 'settings', + 'settings', // required for buttons and actions, which are global + 'siteSettings', 'frame', 'eventBus', 'site' diff --git a/src/ext/lib/settings/SiteSettings.ts b/src/ext/lib/settings/SiteSettings.ts index c7ba1e5..acc50e8 100644 --- a/src/ext/lib/settings/SiteSettings.ts +++ b/src/ext/lib/settings/SiteSettings.ts @@ -48,21 +48,25 @@ export class SiteSettings { } - // 'undefined' default here means use default - this.data.defaults.crop = this.data.defaults.crop ?? _cp(this.defaultSettings.defaults.crop); - - // these can contain default options, but can also be undefined - if (this.data.defaults?.stretch === StretchType.Default || this.data.defaults?.stretch === undefined) { - this.data.defaults.stretch = _cp(this.defaultSettings.defaults.stretch); - } - if (this.data.defaults?.alignment === undefined) { // distinguish between undefined and 0! - this.data.defaults.alignment = _cp(this.defaultSettings.defaults.alignment); + if (!this.data.defaults) { + this.data.defaults = _cp(this.defaultSettings.defaults); } else { - if (this.data.defaults?.alignment.x === VideoAlignmentType.Default) { - this.data.defaults.alignment.x = _cp(this.defaultSettings.defaults.alignment.x); + // 'undefined' default here means use default + this.data.defaults.crop = this.data.defaults.crop ?? _cp(this.defaultSettings.defaults.crop); + + // these can contain default options, but can also be undefined + if (this.data.defaults?.stretch === StretchType.Default || this.data.defaults?.stretch === undefined) { + this.data.defaults.stretch = _cp(this.defaultSettings.defaults.stretch); } - if (this.data.defaults.alignment.y === VideoAlignmentType.Default) { - this.data.defaults.alignment.y = _cp(this.defaultSettings.defaults.alignment.y); + if (this.data.defaults?.alignment === undefined) { // distinguish between undefined and 0! + this.data.defaults.alignment = _cp(this.defaultSettings.defaults.alignment); + } else { + if (this.data.defaults?.alignment.x === VideoAlignmentType.Default) { + this.data.defaults.alignment.x = _cp(this.defaultSettings.defaults.alignment.x); + } + if (this.data.defaults.alignment.y === VideoAlignmentType.Default) { + this.data.defaults.alignment.y = _cp(this.defaultSettings.defaults.alignment.y); + } } }