Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pseudo reload on wayland #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ function prettyPrint(obj) {

/** pathString: absolute path to a js file descending from the extension root */
function findExtensionRoot(pathString) {
let path = Gio.file_new_for_path(pathString);
let dir = path.get_parent();
let dir = Gio.file_new_for_path(pathString);
if (!GLib.file_test(pathString, GLib.FileTest.IS_DIR))
dir = dir.get_parent();

while (dir !== null) {
let metadata = dir.get_child("metadata.json");
Expand Down Expand Up @@ -522,11 +523,38 @@ function Reload(code, path) {
return [false, 'Not in a valid extension'];
}

let modules = [[code, path]];
if (path === root) {
modules = extensionImports.extension.modules.map(m => {
let module = extensionImports[m];
let file = module.__file__;
let [ok, code] = GLib.file_get_contents(file);
return [code, file];
});
}

// Guard against syntax errors
for (let [code, path] of modules) {
try {
Reflect.parse(code);
} catch(e) {
// We know there's a syntax error, so let Eval take care of error location
return Eval(code, path);
}
}

// Disable the extension
extensionImports.extension.disable();

// Reload the code
const [evalSuccess, result] = Eval(code, path);
let evalSuccess, result;
for (let [code, path] of modules) {
try {
[evalSuccess, result] = Eval(code, path);
} catch(e) {
return [evalSuccess, result];
}
}

// Enable the extension again
extensionImports.extension.enable();
return [evalSuccess, result];
Expand All @@ -536,7 +564,12 @@ function Reload(code, path) {
Run extension.disable and then restart Gnome Shell
*/
function Restart(path) {
let [type, extensionImports, _] = findExtensionImports(path);
let [type, extensionImports, root] = findExtensionImports(path);

if (imports.gi.Meta.is_wayland_compositor()) {
return Reload(null, root);
}

if (type !== 'extension')
return;
extensionImports.extension.disable();
Expand Down