Review of "Light Dict" version 2

Details Page Preview

Manipulate primary selections on the fly, typically used as Lightweight Dictionaries For support, please report issues in time via the Homepage link below rather than the review section below it

Extension Homepage
https://github.com/tuberry/light-dict

No comments.

Diff Against

Files

Note: Binary files aren't shown on the web site. To see all files, please download the extension zipfile.

All Versions

Previous Reviews on this Version

andyholmes active
I would strongly recommend you use `Gio.Subprocess` instead of `GLib.spawn_async_with_pipes()`, as it is much safer in language bindings like GJS.
grroot posted a review
Thanks! Andy, I change the GLib.spwan to Gio.Subprocess and it works, but I am not sure it's right way or not, here is the new version of _lookUp(): _lookUp(text) { try { let rcmd = this._dcommand.split('LDWORD').join(GLib.shell_quote(text)); let proc = new Gio.Subprocess({ argv: ['/bin/bash', '-c', rcmd], flags: (Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_PIPE), }); proc.init(null); let that = this, lines = [], line, read = (() => { return function read_all(stream, exit) { stream.read_line_async(GLib.PRIORITY_LOW, null, (source, res) => { if((line = source.read_line_finish(res)) !== null && line[0] !== null) { lines.push(ByteArray.toString(line[0])); read_all(source, exit); } else { // some code here } else { if(!exit) return; read_all(new Gio.DataInputStream({base_stream: proc.get_stderr_pipe()}), false); } } }); } })(); read(new Gio.DataInputStream({base_stream: proc.get_stdout_pipe()}), true); } catch (e) { Main.notifyError(APPNAME, e.message); } } Any comments?
andyholmes posted a review
That looks pretty good. I think it would be easier to use `Gio.Subprocess.communicate_utf8_async()`. It will return a utf8 string and read all the output before returning from the thread: ``` // proc setup proc.communicate_utf8_async(null, null, (proc, res) => { try { let [_, stdout, stderr] = proc.communicate_utf8_finish(proc, res); // the program exited with an error if (proc.get_exit_code() !== 0) { log(stderr); return; } // the program exited without error log(stdout); } catch (e) { // the program failed to execute at all Main.notifyError(APPNAME, e.message); } }); ```
grroot posted a review
Thanks, it looks much more intuitional and neater now.