Skip to content

Commit

Permalink
Add --ignore-dbus-ok for auxhelper.js
Browse files Browse the repository at this point in the history
Apparently sometimes `ok=false` for unclear reasons

Issue: #122
  • Loading branch information
OttoAllmendinger committed May 17, 2020
1 parent 4adf8fb commit 98fc350
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 14 deletions.
9 changes: 8 additions & 1 deletion src/auxhelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const params = {
"--flash" : "flash",
"--filename FILENAME" : "output file",
"--spawntest" : "test GLib spawn call",
"--ignore-dbus-ok" : "ignore `ok` result of dbus call",
"--debug" : "print debug output",
"--help" : "show this"
}
Expand Down Expand Up @@ -203,8 +204,14 @@ const main = () => {
logDebug("calling func...");
const [ok, fileNameUsed] = func();
if (!ok) {
throw new Error("ok=false");
const err = new Error("ok=false");
if (opts.ignoreDbusOk) {
logError(`${err} - ignoreDbusOk set, continuing...`);
} else {
throw err;
}
}

if (fileName !== fileNameUsed) {
throw new Error(`path mismatch fileName=${fileName} fileNameUsed=${fileNameUsed}`)
}
Expand Down
2 changes: 2 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ var exports = {
KeyImgurAutoUpload: "imgur-auto-upload",
KeyImgurAutoCopyLink: "imgur-auto-copy-link",
KeyImgurAutoOpenLink: "imgur-auto-open-link",

KeyAuxHelperIgnoreDBusOK: "auxhelper-ignore-dbus-ok",
};
3 changes: 2 additions & 1 deletion src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const settings = Convenience.getSettings();

const getSelectionOptions = () => {
const captureDelay = settings.get_int(Config.KeyCaptureDelay);
return { captureDelay }
const ignoreDbusOk = settings.get_boolean(Config.KeyAuxHelperIgnoreDBusOK);
return { captureDelay, ignoreDbusOk };
}

class Screenshot {
Expand Down
Binary file modified src/schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@
<key name="imgur-auto-open-link" type="b">
<default>false</default>
</key>

<key name="auxhelper-ignore-dbus-ok" type="b">
<default>false</default>
</key>
</schema>
</schemalist>
<!--
vi:sts=2:st=2:et
vi:sts=2:et
-->
28 changes: 17 additions & 11 deletions src/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ const selectWindow = (windows, px, py) => {
return filtered[0];
};

const callHelper = (argv, fileName, callback) => {
argv = ["gjs", Local.path + "/auxhelper.js", "--filename", fileName, ...argv];
const callHelper = (options, appendArgv, fileName, callback) => {
const argv = ["gjs", Local.path + "/auxhelper.js"];
if (options.ignoreDbusOk) {
argv.push("--ignore-dbus-ok");
}
argv.push("--filename", fileName, ...appendArgv);

// log(JSON.stringify(options));
// log(argv.join(' '));
const [success, pid] = GLib.spawn_async(
null, /* pwd */
Expand All @@ -92,19 +98,19 @@ const callHelper = (argv, fileName, callback) => {
}


const makeAreaScreenshot = ({x, y, w, h}, callback) => {
const makeAreaScreenshot = (options, {x, y, w, h}, callback) => {
const fileName = Filename.getTemp();
callHelper(["--area", [x, y, w, h].join(",")], fileName, callback);
callHelper(options, ["--area", [x, y, w, h].join(",")], fileName, callback);
};

const makeWindowScreenshot = (callback) => {
const makeWindowScreenshot = (options, callback) => {
const fileName = Filename.getTemp();
callHelper(["--window"], fileName, callback);
callHelper(options, ["--window"], fileName, callback);
};

const makeDesktopScreenshot = (callback) => {
const makeDesktopScreenshot = (options, callback) => {
const fileName = Filename.getTemp();
callHelper(["--desktop"], fileName, callback);
callHelper(options, ["--desktop"], fileName, callback);
};


Expand Down Expand Up @@ -243,7 +249,7 @@ class SelectionArea {
}

Mainloop.timeout_add(this._options.captureDelay, () => {
makeAreaScreenshot(region, emitScreenshotOnSuccess(this))
makeAreaScreenshot(this._options, region, emitScreenshotOnSuccess(this))
});
}
}
Expand Down Expand Up @@ -293,7 +299,7 @@ class SelectionWindow {
Mainloop.timeout_add(this._options.captureDelay, () => {
Main.activateWindow(win.get_meta_window());
Mainloop.idle_add(() =>
makeWindowScreenshot(emitScreenshotOnSuccess(this))
makeWindowScreenshot(this._options, emitScreenshotOnSuccess(this))
);
});
}
Expand All @@ -310,7 +316,7 @@ class SelectionDesktop {
constructor(options) {
this._options = options;
Mainloop.timeout_add(this._options.captureDelay, () => {
makeDesktopScreenshot(emitScreenshotOnSuccess(this));
makeDesktopScreenshot(this._options, emitScreenshotOnSuccess(this));
this.emit("stop");
});
}
Expand Down

0 comments on commit 98fc350

Please sign in to comment.