summaryrefslogtreecommitdiff
path: root/overrides
diff options
context:
space:
mode:
authormattdangerw <mattdangerw@gmail.com>2013-06-25 16:16:38 -0700
committermattdangerw <mattdangerw@gmail.com>2013-06-25 16:16:38 -0700
commitfe90102bc9ebd808a7abe7ce060d2182399e3899 (patch)
treea5d593d5ecf1fe46e68ce47e5451e4c7ca95c8f5 /overrides
parentdb4c92e4b25380451114a7cb3c6d5838d561d52a (diff)
parent44ac371c365477ed4024fda148c9ef711bc95a02 (diff)
Merge pull request #128 from endlessm/issues/127
Gjs override for getting the directory of the script being run
Diffstat (limited to 'overrides')
-rw-r--r--overrides/Endless.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/overrides/Endless.js b/overrides/Endless.js
index 59e55ac..9645f85 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