微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在GJS中添加辅助资源

如何解决在GJS中添加辅助资源

我正在开发Gnome扩展。因此,我的所有代码都驻留在extension.js中。 现在,我还有其他一些要使用的代码,它们位于文件foo.js中,可悲的是尚未使用严格模式。如何加载此foo.js

解决方法

existing tutorial对此进行了介绍:

// 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);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。