diff options
| author | Ja.KooLit <85185940+JaKooLit@users.noreply.github.com> | 2025-07-15 23:46:48 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-15 23:46:48 +0900 |
| commit | 71f1bc6920920f2a9337f18ceba6ebc12b276a6f (patch) | |
| tree | 34431efa13460f9e716ed162355fd08c535aedc0 /config/quickshell/modules/common/functions/object_utils.js | |
| parent | 7a3bd4f9fe48aad02ef8b13d3677b3bd8358252c (diff) | |
| parent | 3aadb2106a26988346f34afafe8393b0ba6bdf79 (diff) | |
Merge branch 'development' into fix-slow-brightness
Diffstat (limited to 'config/quickshell/modules/common/functions/object_utils.js')
| -rw-r--r-- | config/quickshell/modules/common/functions/object_utils.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/config/quickshell/modules/common/functions/object_utils.js b/config/quickshell/modules/common/functions/object_utils.js new file mode 100644 index 00000000..96c632fd --- /dev/null +++ b/config/quickshell/modules/common/functions/object_utils.js @@ -0,0 +1,45 @@ +function toPlainObject(qtObj) { + if (qtObj === null || typeof qtObj !== "object") return qtObj; + + // Handle arrays + if (Array.isArray(qtObj)) { + return qtObj.map(toPlainObject); + } + + const result = ({}); + for (let key in qtObj) { + if ( + typeof qtObj[key] !== "function" && + !key.startsWith("objectName") && + !key.startsWith("children") && + !key.startsWith("object") && + !key.startsWith("parent") && + !key.startsWith("metaObject") && + !key.startsWith("destroyed") && + !key.startsWith("reloadableId") + ) { + result[key] = toPlainObject(qtObj[key]); + } + } + return result; +} + +function applyToQtObject(qtObj, jsonObj) { + if (!qtObj || typeof jsonObj !== "object" || jsonObj === null) return; + + for (let key in jsonObj) { + if (!qtObj.hasOwnProperty(key)) continue; + + // Check if the property is a QtObject (not a value) + const value = qtObj[key]; + const jsonValue = jsonObj[key]; + + // If it's an object and not an array, recurse + if (value && typeof value === "object" && !Array.isArray(value)) { + applyToQtObject(value, jsonValue); + } else { + // Otherwise, assign the value + qtObj[key] = jsonValue; + } + } +} |
