shell/screenshot: Throw error on failure
Commit da537cda43
moved the Shell.Screenshot API to GIO's async pattern,
but we never set the GError passed to the *_finish() functions and only
indicate failure by returning FALSE.
The expected behavior is to throw an error in that situation, so make sure
we do that.
https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1123
This commit is contained in:
parent
1bccbe7f11
commit
35484151ce
@ -113,8 +113,7 @@ var ScreenshotService = class {
|
|||||||
return [null, null];
|
return [null, null];
|
||||||
}
|
}
|
||||||
|
|
||||||
_onScreenshotComplete(result, area, stream, file, flash, invocation) {
|
_onScreenshotComplete(area, stream, file, flash, invocation) {
|
||||||
if (result) {
|
|
||||||
if (flash) {
|
if (flash) {
|
||||||
let flashspot = new Flashspot(area);
|
let flashspot = new Flashspot(area);
|
||||||
flashspot.fire(() => {
|
flashspot.fire(() => {
|
||||||
@ -123,7 +122,6 @@ var ScreenshotService = class {
|
|||||||
} else {
|
} else {
|
||||||
this._removeShooterForSender(invocation.get_sender());
|
this._removeShooterForSender(invocation.get_sender());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
stream.close(null);
|
stream.close(null);
|
||||||
|
|
||||||
@ -136,7 +134,7 @@ var ScreenshotService = class {
|
|||||||
clipboard.set_content(St.ClipboardType.CLIPBOARD, 'image/png', bytes);
|
clipboard.set_content(St.ClipboardType.CLIPBOARD, 'image/png', bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
let retval = GLib.Variant.new('(bs)', [result, filenameUsed]);
|
let retval = GLib.Variant.new('(bs)', [true, filenameUsed]);
|
||||||
invocation.return_value(retval);
|
invocation.return_value(retval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,12 +176,13 @@ var ScreenshotService = class {
|
|||||||
screenshot.screenshot_area(x, y, width, height, stream,
|
screenshot.screenshot_area(x, y, width, height, stream,
|
||||||
(o, res) => {
|
(o, res) => {
|
||||||
try {
|
try {
|
||||||
let [result, area] =
|
let [success_, area] =
|
||||||
screenshot.screenshot_area_finish(res);
|
screenshot.screenshot_area_finish(res);
|
||||||
this._onScreenshotComplete(
|
this._onScreenshotComplete(
|
||||||
result, area, stream, file, flash, invocation);
|
area, stream, file, flash, invocation);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
invocation.return_gerror(e);
|
this._removeShooterForSender(invocation.get_sender());
|
||||||
|
invocation.return_value(new GLib.Variant('(bs)', [false, '']));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -201,12 +200,13 @@ var ScreenshotService = class {
|
|||||||
screenshot.screenshot_window(includeFrame, includeCursor, stream,
|
screenshot.screenshot_window(includeFrame, includeCursor, stream,
|
||||||
(o, res) => {
|
(o, res) => {
|
||||||
try {
|
try {
|
||||||
let [result, area] =
|
let [success_, area] =
|
||||||
screenshot.screenshot_window_finish(res);
|
screenshot.screenshot_window_finish(res);
|
||||||
this._onScreenshotComplete(
|
this._onScreenshotComplete(
|
||||||
result, area, stream, file, flash, invocation);
|
area, stream, file, flash, invocation);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
invocation.return_gerror(e);
|
this._removeShooterForSender(invocation.get_sender());
|
||||||
|
invocation.return_value(new GLib.Variant('(bs)', [false, '']));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -224,12 +224,13 @@ var ScreenshotService = class {
|
|||||||
screenshot.screenshot(includeCursor, stream,
|
screenshot.screenshot(includeCursor, stream,
|
||||||
(o, res) => {
|
(o, res) => {
|
||||||
try {
|
try {
|
||||||
let [result, area] =
|
let [success_, area] =
|
||||||
screenshot.screenshot_finish(res);
|
screenshot.screenshot_finish(res);
|
||||||
this._onScreenshotComplete(
|
this._onScreenshotComplete(
|
||||||
result, area, stream, file, flash, invocation);
|
area, stream, file, flash, invocation);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
invocation.return_gerror(e);
|
this._removeShooterForSender(invocation.get_sender());
|
||||||
|
invocation.return_value(new GLib.Variant('(bs)', [false, '']));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -87,12 +87,12 @@ write_screenshot_thread (GTask *result,
|
|||||||
gpointer task_data,
|
gpointer task_data,
|
||||||
GCancellable *cancellable)
|
GCancellable *cancellable)
|
||||||
{
|
{
|
||||||
cairo_status_t status;
|
|
||||||
ShellScreenshot *screenshot = SHELL_SCREENSHOT (object);
|
ShellScreenshot *screenshot = SHELL_SCREENSHOT (object);
|
||||||
ShellScreenshotPrivate *priv;
|
ShellScreenshotPrivate *priv;
|
||||||
g_autoptr (GOutputStream) stream = NULL;
|
g_autoptr (GOutputStream) stream = NULL;
|
||||||
g_autoptr(GdkPixbuf) pixbuf = NULL;
|
g_autoptr(GdkPixbuf) pixbuf = NULL;
|
||||||
g_autofree char *creation_time = NULL;
|
g_autofree char *creation_time = NULL;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
g_assert (screenshot != NULL);
|
g_assert (screenshot != NULL);
|
||||||
|
|
||||||
@ -109,15 +109,15 @@ write_screenshot_thread (GTask *result,
|
|||||||
if (!creation_time)
|
if (!creation_time)
|
||||||
creation_time = g_date_time_format (priv->datetime, "%FT%T%z");
|
creation_time = g_date_time_format (priv->datetime, "%FT%T%z");
|
||||||
|
|
||||||
if (gdk_pixbuf_save_to_stream (pixbuf, stream, "png", NULL, NULL,
|
gdk_pixbuf_save_to_stream (pixbuf, stream, "png", NULL, &error,
|
||||||
"tEXt::Software", "gnome-screenshot",
|
"tEXt::Software", "gnome-screenshot",
|
||||||
"tEXt::Creation Time", creation_time,
|
"tEXt::Creation Time", creation_time,
|
||||||
NULL))
|
NULL);
|
||||||
status = CAIRO_STATUS_SUCCESS;
|
|
||||||
else
|
|
||||||
status = CAIRO_STATUS_WRITE_ERROR;
|
|
||||||
|
|
||||||
g_task_return_boolean (result, status == CAIRO_STATUS_SUCCESS);
|
if (error)
|
||||||
|
g_task_return_error (result, error);
|
||||||
|
else
|
||||||
|
g_task_return_boolean (result, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user