diff options
author | Philip Chimento <philip@endlessm.com> | 2013-06-25 15:37:16 -0700 |
---|---|---|
committer | Philip Chimento <philip@endlessm.com> | 2013-06-25 15:37:16 -0700 |
commit | 44ac371c365477ed4024fda148c9ef711bc95a02 (patch) | |
tree | 8d5fe15ed909edaec43884e8e0c2325c6db93e3c | |
parent | 39c845a71b01e9f8e8d3d74639f8e9e7c391f952 (diff) |
Gjs override for getting the directory of the script being run
Adapted this from the english app
[endlessm/eos-sdk#127]
-rw-r--r-- | overrides/Endless.js | 15 |
1 files changed, 15 insertions, 0 deletions
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 |