summaryrefslogtreecommitdiff
path: root/lang/gjs/src/file.ts
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-10-15 13:25:45 +0000
committerAylur <[email protected]>2024-10-15 13:29:19 +0000
commitbafd48d3df9b43a1d49ec015eff30619d595468b (patch)
treed5c3788835ca7e50d68cd023026e7738f39f6f71 /lang/gjs/src/file.ts
parentfe11c037bad45697451b7264ff93fa37f1fac78f (diff)
update lua and gjs layout
installing the gjs package through meson or npm now results in the same exposed structure lua: fix rockspec docs: aur package
Diffstat (limited to 'lang/gjs/src/file.ts')
-rw-r--r--lang/gjs/src/file.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/lang/gjs/src/file.ts b/lang/gjs/src/file.ts
new file mode 100644
index 0000000..7b9de3a
--- /dev/null
+++ b/lang/gjs/src/file.ts
@@ -0,0 +1,45 @@
+import Astal from "gi://AstalIO"
+import Gio from "gi://Gio"
+
+export function readFile(path: string): string {
+ return Astal.read_file(path) || ""
+}
+
+export function readFileAsync(path: string): Promise<string> {
+ return new Promise((resolve, reject) => {
+ Astal.read_file_async(path, (_, res) => {
+ try {
+ resolve(Astal.read_file_finish(res) || "")
+ }
+ catch (error) {
+ reject(error)
+ }
+ })
+ })
+}
+
+export function writeFile(path: string, content: string): void {
+ Astal.write_file(path, content)
+}
+
+export function writeFileAsync(path: string, content: string): Promise<void> {
+ return new Promise((resolve, reject) => {
+ Astal.write_file_async(path, content, (_, res) => {
+ try {
+ resolve(Astal.write_file_finish(res))
+ }
+ catch (error) {
+ reject(error)
+ }
+ })
+ })
+}
+
+export function monitorFile(
+ path: string,
+ callback: (file: string, event: Gio.FileMonitorEvent) => void,
+): Gio.FileMonitor {
+ return Astal.monitor_file(path, (file: string, event: Gio.FileMonitorEvent) => {
+ callback(file, event)
+ })!
+}