-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (28 loc) · 1.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*! (c) Andrea Giammarchi - ISC - https://github.com/WebReflection/gjs-require */
exports.default = (function (self) {'use strict';
const { gi, system } = imports;
const { GLib, Gio } = gi;
const { File } = Gio;
const DIR = GLib.get_current_dir();
const PROGRAM = resolve(DIR, system.programInvocationName);
let __dirname = getProgramDir(PROGRAM).get_path();
let __filename = PROGRAM.get_path();
Object.defineProperties(window, {
__dirname: {get: () => __dirname},
__filename: {get: () => __filename},
global: {value: window},
});
function getProgramDir(programFile) {
const info = programFile.query_info('standard::', Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null);
if (info.get_is_symlink()) {
const symlinkFile = programFile.get_parent().resolve_relative_path(info.get_symlink_target());
return symlinkFile.get_parent();
} else {
return programFile.get_parent();
}
}
function resolve(dir, file) {
return File.new_for_path(dir).resolve_relative_path(file);
}
return window
}(this));