forked from Shinonome/dots-hyprland
move toPlainObject to object_utils.js
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
function trimFileProtocol(str) {
|
||||||
|
return str.startsWith("file://") ? str.slice(7) : str;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -2,6 +2,8 @@ pragma Singleton
|
|||||||
pragma ComponentBehavior: Bound
|
pragma ComponentBehavior: Bound
|
||||||
|
|
||||||
import "root:/modules/common"
|
import "root:/modules/common"
|
||||||
|
import "root:/modules/common/functions/file_utils.js" as FileUtils
|
||||||
|
import "root:/modules/common/functions/object_utils.js" as ObjectUtils
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
@@ -12,35 +14,9 @@ Singleton {
|
|||||||
id: root
|
id: root
|
||||||
property string fileDir: `${StandardPaths.standardLocations(StandardPaths.ConfigLocation)[0]}/illogical-impulse`
|
property string fileDir: `${StandardPaths.standardLocations(StandardPaths.ConfigLocation)[0]}/illogical-impulse`
|
||||||
property string fileName: "config.json"
|
property string fileName: "config.json"
|
||||||
property string filePath: `${root.fileDir}/${root.fileName}`
|
property string filePath: FileUtils.trimFileProtocol(`${root.fileDir}/${root.fileName}`)
|
||||||
property bool firstLoad: true
|
property bool firstLoad: true
|
||||||
|
|
||||||
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 loadConfig() {
|
function loadConfig() {
|
||||||
configFileView.reload()
|
configFileView.reload()
|
||||||
}
|
}
|
||||||
@@ -94,7 +70,7 @@ Singleton {
|
|||||||
|
|
||||||
FileView {
|
FileView {
|
||||||
id: configFileView
|
id: configFileView
|
||||||
path: root.filePath
|
path: Qt.resolvedUrl(root.filePath)
|
||||||
watchChanges: true
|
watchChanges: true
|
||||||
onFileChanged: {
|
onFileChanged: {
|
||||||
console.log("[ConfigLoader] File changed, reloading...")
|
console.log("[ConfigLoader] File changed, reloading...")
|
||||||
@@ -108,8 +84,7 @@ Singleton {
|
|||||||
onLoadFailed: (error) => {
|
onLoadFailed: (error) => {
|
||||||
if(error == FileViewError.FileNotFound) {
|
if(error == FileViewError.FileNotFound) {
|
||||||
console.log("[ConfigLoader] File not found, creating new file.")
|
console.log("[ConfigLoader] File not found, creating new file.")
|
||||||
// Apply ConfigOptions json to file
|
const plainConfig = ObjectUtils.toPlainObject(ConfigOptions)
|
||||||
const plainConfig = toPlainObject(ConfigOptions)
|
|
||||||
configFileView.setText(JSON.stringify(plainConfig, null, 2))
|
configFileView.setText(JSON.stringify(plainConfig, null, 2))
|
||||||
Hyprland.dispatch(`exec notify-send "Shell configuration created" "${root.filePath}"`)
|
Hyprland.dispatch(`exec notify-send "Shell configuration created" "${root.filePath}"`)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user