In order to write to a file from the gnome extension, I use replace_contents_bytes_async
, as in the example here File Operations | GNOME JavaScript
extension.js:
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
import GLib from 'gi://GLib';
import Gio from 'gi://Gio';
export default class ExampleExtension extends Extension {
async enable() {
const file = Gio.File.new_for_path('/tmp/test-file.txt');
const bytes = new GLib.Bytes('some file contents');
const [etag] = await file.replace_contents_bytes_async(bytes, null, false,
Gio.FileCreateFlags.REPLACE_DESTINATION, null);
}
disable() {
}
}
But this code gives an error:
Judging by the documentation, replace_contents_bytes_async
should also accept a callback Gio.File.replace_contents_bytes_async :
const [etag] = await file.replace_contents_bytes_async(bytes, null, false,
Gio.FileCreateFlags.REPLACE_DESTINATION, null, function(source_object, res, data){});
But this code also gives an error: