diff options
-rw-r--r-- | docs/guide/typescript/utilities.md | 36 | ||||
-rw-r--r-- | lang/gjs/src/file.ts | 4 | ||||
-rw-r--r-- | lang/gjs/src/gobject.ts | 8 | ||||
-rw-r--r-- | lang/gjs/src/index.ts | 1 | ||||
-rw-r--r-- | lang/gjs/src/process.ts | 2 | ||||
-rw-r--r-- | lang/gjs/src/time.ts | 2 | ||||
-rw-r--r-- | lang/lua/astal/process.lua | 2 | ||||
-rw-r--r-- | lang/lua/astal/time.lua | 2 |
8 files changed, 35 insertions, 22 deletions
diff --git a/docs/guide/typescript/utilities.md b/docs/guide/typescript/utilities.md index f808044..02dfdaf 100644 --- a/docs/guide/typescript/utilities.md +++ b/docs/guide/typescript/utilities.md @@ -2,14 +2,10 @@ ## File functions +Import from `astal` or `astal/file` + ```ts -import { - readFile, - readFileAsync, - writeFile, - writeFileAsync, - monitorFile, -} from "astal" +import { readFile, readFileAsync, writeFile, writeFileAsync, monitorFile, } from "astal/file" ``` ### Reading files @@ -28,6 +24,8 @@ function writeFileAsync(path: string, content: string): Promise<void> ### Monitoring files +If `path` is a directory it will be recursively monitored. + ```ts function monitorFile( path: string, @@ -37,23 +35,25 @@ function monitorFile( ## Timeouts and Intervals +Import from `astal` or `astal/time` + ```ts -import { interval, timeout, idle } from "astal" +import { interval, timeout, idle } from "astal/time" ``` You can use javascript native `setTimeout` or `setInterval` they return a [GLib.Source](https://docs.gtk.org/glib/struct.Source.html) instance. Alternatively you can use these functions provided by Astal, -which return an [Astal.Time](https://aylur.github.io/libastal/io/class.Time.html) instance. +which return an [AstalIO.Time](https://aylur.github.io/libastal/io/class.Time.html) instance. -`Astal.Time` has a `now` signal and a `cancelled` signal. +`AstalIO.Time` has a `now` signal and a `cancelled` signal. ### Interval Will immediately execute the function and every `interval` millisecond. ```ts -function interval(interval: number, callback?: () => void): Astal.Time +function interval(interval: number, callback?: () => void): AstalIO.Time ``` ### Timeout @@ -61,7 +61,7 @@ function interval(interval: number, callback?: () => void): Astal.Time Will execute the `callback` after `timeout` millisecond. ```ts -function timeout(timeout: number, callback?: () => void): Astal.Time +function timeout(timeout: number, callback?: () => void): AstalIO.Time ``` ### Idle @@ -69,7 +69,7 @@ function timeout(timeout: number, callback?: () => void): Astal.Time Executes `callback` whenever there are no higher priority events pending. ```ts -function idle(callback?: () => void): Astal.Time +function idle(callback?: () => void): AstalIO.Time ``` Example: @@ -92,27 +92,29 @@ timer.cancel() ## Process functions +Import from `astal` or `astal/process` + ```ts -import { subprocess, exec, execAsync } from "astal" +import { subprocess, exec, execAsync } from "astal/process" ``` ### Subprocess You can start a subprocess and run callback functions whenever it outputs to -stdout or stderr. [Astal.Process](https://aylur.github.io/libastal/io/class.Process.html) has a `stdout` and `stderr` signal. +stdout or stderr. [AstalIO.Process](https://aylur.github.io/libastal/io/class.Process.html) has a `stdout` and `stderr` signal. ```ts function subprocess(args: { cmd: string | string[] out?: (stdout: string) => void err?: (stderr: string) => void -}): Astal.Process +}): AstalIO.Process function subprocess( cmd: string | string[], onOut?: (stdout: string) => void, onErr?: (stderr: string) => void, -): Astal.Process +): AstalIO.Process ``` Example: diff --git a/lang/gjs/src/file.ts b/lang/gjs/src/file.ts index 7b9de3a..6ad8be3 100644 --- a/lang/gjs/src/file.ts +++ b/lang/gjs/src/file.ts @@ -1,5 +1,7 @@ import Astal from "gi://AstalIO" -import Gio from "gi://Gio" +import Gio from "gi://Gio?version=2.0" + +export { Gio } export function readFile(path: string): string { return Astal.read_file(path) || "" diff --git a/lang/gjs/src/gobject.ts b/lang/gjs/src/gobject.ts index 4740764..d37ac69 100644 --- a/lang/gjs/src/gobject.ts +++ b/lang/gjs/src/gobject.ts @@ -1,8 +1,8 @@ -export { default as GObject, default as default } from "gi://GObject" -export { default as Gio } from "gi://Gio" -export { default as GLib } from "gi://GLib" - import GObject from "gi://GObject" + +export { default as GLib } from "gi://GLib?version=2.0" +export { GObject, GObject as default } + const meta = Symbol("meta") const { ParamSpec, ParamFlags } = GObject diff --git a/lang/gjs/src/index.ts b/lang/gjs/src/index.ts index 161c369..cabc961 100644 --- a/lang/gjs/src/index.ts +++ b/lang/gjs/src/index.ts @@ -1,3 +1,4 @@ +export { default as AstalIO } from "gi://AstalIO?version=0.1" export * from "./process.js" export * from "./time.js" export * from "./file.js" diff --git a/lang/gjs/src/process.ts b/lang/gjs/src/process.ts index 2f7816b..c41adc1 100644 --- a/lang/gjs/src/process.ts +++ b/lang/gjs/src/process.ts @@ -6,6 +6,8 @@ type Args = { err?: (stderr: string) => void } +export const { Process } = Astal + export function subprocess(args: Args): Astal.Process export function subprocess( diff --git a/lang/gjs/src/time.ts b/lang/gjs/src/time.ts index a7e1e61..1939d98 100644 --- a/lang/gjs/src/time.ts +++ b/lang/gjs/src/time.ts @@ -1,5 +1,7 @@ import Astal from "gi://AstalIO" +export const { Time } = Astal + export function interval(interval: number, callback?: () => void) { return Astal.Time.interval(interval, () => void callback?.()) } diff --git a/lang/lua/astal/process.lua b/lang/lua/astal/process.lua index b8b7436..800e83a 100644 --- a/lang/lua/astal/process.lua +++ b/lang/lua/astal/process.lua @@ -3,6 +3,8 @@ local Astal = lgi.require("AstalIO", "0.1") local M = {} +M.Process = Astal.Process + ---@param commandline string | string[] ---@param on_stdout? fun(out: string): nil ---@param on_stderr? fun(err: string): nil diff --git a/lang/lua/astal/time.lua b/lang/lua/astal/time.lua index 7719da9..2b81dbd 100644 --- a/lang/lua/astal/time.lua +++ b/lang/lua/astal/time.lua @@ -4,6 +4,8 @@ local GObject = lgi.require("GObject", "2.0") local M = {} +M.Time = Astal.Time + ---@param interval number ---@param fn function ---@return { cancel: function, on_now: function } |