mirror of
https://github.com/morgan9e/gnome-shell-extension-freon
synced 2026-04-14 00:14:14 +09:00
This means doing all IO in a background thread, rather than popping lines synchronously off a pipe.
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
const ByteArray = imports.byteArray;
|
|
const GLib = imports.gi.GLib;
|
|
const Gio = imports.gi.Gio;
|
|
|
|
var CommandLineUtil = class {
|
|
|
|
constructor(){
|
|
this._argv = null;
|
|
this._updated = false;
|
|
}
|
|
|
|
execute(callback) {
|
|
try{
|
|
this._callback = callback;
|
|
|
|
let proc = Gio.Subprocess.new(this._argv,
|
|
Gio.SubprocessFlags.STDOUT_PIPE |
|
|
Gio.SubprocessFlags.STDERR_PIPE);
|
|
|
|
proc.communicate_utf8_async(null, null, (proc, result) => {
|
|
try {
|
|
let [, stdout, stderr] = proc.communicate_utf8_finish(result);
|
|
|
|
this._output = stdout ? stdout.split('\n') : [];
|
|
this._error_output = stderr ? stderr.split('\n') : [];
|
|
} catch (e) {
|
|
logError(e);
|
|
} finally {
|
|
this._updated = true;
|
|
callback();
|
|
}
|
|
});
|
|
} catch(e){
|
|
global.log(e.toString());
|
|
}
|
|
}
|
|
|
|
get available(){
|
|
return this._argv != null;
|
|
}
|
|
|
|
get updated (){
|
|
return this._updated;
|
|
}
|
|
|
|
set updated (updated){
|
|
this._updated = updated;
|
|
}
|
|
|
|
destroy(){
|
|
this._argv = null;
|
|
}
|
|
|
|
};
|