Skip to content

Instantly share code, notes, and snippets.

@sciamp
Created August 26, 2013 21:12
Show Gist options
  • Save sciamp/6346724 to your computer and use it in GitHub Desktop.
Save sciamp/6346724 to your computer and use it in GitHub Desktop.
this should work but it doesn't :(
#!/usr/bin/gjs
const Lang = imports.lang;
const Gtk = imports.gi.Gtk;
const Gio = imports.gi.Gio;
const Application = new Lang.Class({
Name: 'Demo async file write',
_init: function() {
this.application = new Gtk.Application();
this.application.connect('startup', Lang.bind(this, this._onStartup));
this.application.connect('activate', Lang.bind(this, this._onActivate));
},
_onActivate: function() {
this._window.show_all();
},
_appendAsyncCb: function(obj, res, data) {
let output_stream = obj.append_to_finish (res, null);
output_stream.write_async("Writing asynchronously...", null,
Lang.bind (this, function(obj, res, data) {
obj.write_finish(res, null);
}));
},
_buildUI: function() {
this._window = new Gtk.ApplicationWindow({ application: this.application,
title: "Hello World!" });
this._window.set_default_size(200, 200);
this.label = new Gtk.Label({ label: "Hello World" });
this._window.add(this.label);
},
_onStartup: function() {
let file = Gio.File.new_for_path("/home/sciamp/async_file_write_demo.txt");
if(!file.query_exists(null))
file.create(Gio.FileCreateFlags.NONE, null);
file.append_to_async (Gio.FileCreateFlags.NONE, null, null,
Lang.bind(this, this._appendAsyncCb));
this._buildUI();
}
});
let app = new Application();
app.application.run(ARGV);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment