Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Compile with the following:
- * valac --pkg gee-1.0 --pkg diodon get_last_copied_item.vala
- *
- * libgee-0.8-dev and diodon-dev packages need to be installed
- */
- using Diodon;
- public delegate void AsyncBegin(AsyncReadyCallback callback);
- public delegate void AsyncFinish(AsyncResult result) throws GLib.Error;
- public bool wait_for_async(AsyncBegin async_function, AsyncFinish async_finish, int timeout = 200) throws GLib.Error
- {
- var loop = new MainLoop(MainContext.default(), true);
- AsyncResult? result = null;
- // Plan the async function
- async_function((o, r) => { result = r; loop.quit(); });
- // Plan timeout
- var t1 = Timeout.add(timeout, () => { loop.quit(); return false; });
- // Run the loop if it was not quit yet.
- if(loop.is_running())
- loop.run();
- // Cancel timer
- Source.remove(t1);
- // Check the outcome
- if(result == null)
- return false;
- async_finish(result);
- return true;
- }
- public static int main(string[] args)
- {
- ZeitgeistClipboardStorage storage = new ZeitgeistClipboardStorage();
- try {
- wait_for_async(
- cb => storage.get_recent_items.begin(1, null, ClipboardTimerange.ALL, null, cb),
- res => {
- var items = storage.get_recent_items.end(res);
- if(items.first() != null) {
- print(items.first().get_text());
- }
- } );
- } catch(Error e) {}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement