summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2025-08-16 16:23:20 +0800
committerlittleblack111 <littleblack11111@gmail.com>2025-08-16 16:23:20 +0800
commit4fe12bbabfe2bb4c468c66348afedb34aee0b783 (patch)
tree904ce21bf2b39d988483d91a585a23ede5da424b /utils
parentc4eca807dacd407af939c2200055acb4326ccfe0 (diff)
feat(Clip): metadatas(app it's taken from, timestamp)
Persistent and Directories are partially copied from end4-dots which is GPL Licensed
Diffstat (limited to 'utils')
-rw-r--r--utils/Directories.qml60
1 files changed, 60 insertions, 0 deletions
diff --git a/utils/Directories.qml b/utils/Directories.qml
new file mode 100644
index 0000000..f643a78
--- /dev/null
+++ b/utils/Directories.qml
@@ -0,0 +1,60 @@
+pragma Singleton
+// pragma ComponentBehavior: Bound
+
+import Qt.labs.platform
+import QtQuick
+import Quickshell
+import Quickshell.Hyprland
+
+Singleton {
+ /**
+ * Trims the File protocol off the input string
+ * @param {string} str
+ * @returns {string}
+ */
+ function trimFileProtocol(str) {
+ return str.startsWith("file://") ? str.slice(7) : str;
+ }
+
+ /**
+ * Extracts the file name from a file path
+ * @param {string} str
+ * @returns {string}
+ */
+ function fileNameForPath(str) {
+ if (typeof str !== "string")
+ return "";
+ const trimmed = trimFileProtocol(str);
+ return trimmed.split(/[\\/]/).pop();
+ }
+
+ /**
+ * Removes the file extension from a file path or name
+ * @param {string} str
+ * @returns {string}
+ */
+ function trimFileExt(str) {
+ if (typeof str !== "string")
+ return "";
+ const trimmed = trimFileProtocol(str);
+ const lastDot = trimmed.lastIndexOf(".");
+ if (lastDot > -1 && lastDot > trimmed.lastIndexOf("/")) {
+ return trimmed.slice(0, lastDot);
+ }
+ return trimmed;
+ }
+
+ // XDG Dirs, with "file://"
+ readonly property string config: StandardPaths.standardLocations(StandardPaths.ConfigLocation)[0]
+ readonly property string state: StandardPaths.standardLocations(StandardPaths.StateLocation)[0]
+ readonly property string cache: StandardPaths.standardLocations(StandardPaths.CacheLocation)[0]
+ readonly property string pictures: StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0]
+ readonly property string downloads: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
+
+ property string clipHistMetaDataPath: `${state}/cliphist.json`
+
+ // Cleanup on init
+ Component.onCompleted: {
+ Quickshell.execDetached(["touch", trimFileProtocol(clipHistMetaDataPath)]);
+ }
+}