From 44ac371c365477ed4024fda148c9ef711bc95a02 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Tue, 25 Jun 2013 15:37:16 -0700 Subject: Gjs override for getting the directory of the script being run Adapted this from the english app [endlessm/eos-sdk#127] --- overrides/Endless.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'overrides') diff --git a/overrides/Endless.js b/overrides/Endless.js index 00315a3..835688a 100644 --- a/overrides/Endless.js +++ b/overrides/Endless.js @@ -1,8 +1,23 @@ +const Gio = imports.gi.Gio; + let Endless; +// Returns the directory that the currently executing JS file resides in +// This is a silly hack that creates an error and looks at its stack trace +function getCurrentFileDir() { + let e = new Error(); + let caller = e.stack.split('\n')[1]; + let pathAndLine = caller.split('@')[1]; + let path = pathAndLine.split(':')[0]; + + // Get full path from GIO + return Gio.File.new_for_path(path).get_parent().get_path(); +} + function _init() { // this is imports.gi.Endless Endless = this; + Endless.getCurrentFileDir = getCurrentFileDir; // Override Endless.PageManager.add() so that you can set child properties // at the same time -- cgit v1.2.3