在 GJS 中包含二手资料
Include secondary sources in GJS
我正在开发 Gnome 扩展。因此,我有一个 extension.js
我的所有代码所在的地方。
现在我有一些我想使用的其他代码,它位于文件 foo.js
中,遗憾的是还没有使用严格模式。如何加载此 foo.js
?
// GJS's Built-in Modules are in the top-level
// See: https://gitlab.gnome.org/GNOME/gjs/blob/master/doc/Modules.md
const Gettext = imports.gettext;
const Cairo = imports.cairo;
// GNOME APIs are under the `gi` namespace (except Cairo)
// See: https://gjs-docs.gnome.org/
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
// GNOME Shell imports
const Main = imports.ui.main;
const ExtensionUtils = imports.misc.extensionUtils;
// You can import your modules using the extension object.
// For example, if you had a file named `exampleLib.js` in your extension directory
const Me = ExtensionUtils.getCurrentExtension();
const ExampleLib = Me.imports.exampleLib;
let myObject = new ExampleLib.ExportedClass();
ExampleLib.exportedFunction(0, ExampleLib.EXPORTED_VARIABLE);
我正在开发 Gnome 扩展。因此,我有一个 extension.js
我的所有代码所在的地方。
现在我有一些我想使用的其他代码,它位于文件 foo.js
中,遗憾的是还没有使用严格模式。如何加载此 foo.js
?
// GJS's Built-in Modules are in the top-level
// See: https://gitlab.gnome.org/GNOME/gjs/blob/master/doc/Modules.md
const Gettext = imports.gettext;
const Cairo = imports.cairo;
// GNOME APIs are under the `gi` namespace (except Cairo)
// See: https://gjs-docs.gnome.org/
const GLib = imports.gi.GLib;
const Gtk = imports.gi.Gtk;
// GNOME Shell imports
const Main = imports.ui.main;
const ExtensionUtils = imports.misc.extensionUtils;
// You can import your modules using the extension object.
// For example, if you had a file named `exampleLib.js` in your extension directory
const Me = ExtensionUtils.getCurrentExtension();
const ExampleLib = Me.imports.exampleLib;
let myObject = new ExampleLib.ExportedClass();
ExampleLib.exportedFunction(0, ExampleLib.EXPORTED_VARIABLE);