Skip to content
Merged
Show file tree
Hide file tree
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
75 changes: 27 additions & 48 deletions src/Previewer/previewer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -122,68 +122,42 @@ namespace Workbench {
Gtk.StyleContext.add_provider_for_display (Gdk.Display.get_default (), this.css , Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
}

// filename to loadable module or empty string ("") to just run it again
// also builder_symbol can be empty. Then the builder object is not handed over to the module
public void run (string filename, string run_symbol, string builder_symbol, string window_symbol, string uri) {
void* function;

if (filename == "") {
if (this.module == null) {
stderr.printf ("No Module specified yet.\n");
return;
}
} else {
if (!Module.supported ()) {
stderr.printf ("This system does not support loadable modules.\n");
return;
}
public void run (string filename, string uri) {
if (this.module != null) {
this.module.close ();
}

if (this.module != null)
this.module.close ();
this.module = Module.open (filename, ModuleFlags.LAZY);
if (this.module == null) {
stderr.printf ("Module loading failed.\n");
return;
}
this.module = Module.open (filename, ModuleFlags.LAZY);
if (this.module == null) {
stderr.printf ("Module loading failed.\n");
return;
}

void* function;

this.module.symbol ("set_base_uri", out function);
var set_base_uri = (BaseUriFunction) function;
set_base_uri (uri);

if (builder_symbol != "") {
if (this.builder == null) {
stderr.printf ("No UI definition loaded yet.\n");
return;
}

this.module.symbol (builder_symbol, out function);
if (function == null) {
stderr.printf (@"Module does not contain symbol '$builder_symbol'.\n");
return;
}

var set_builder = (BuilderFunction) function;
this.module.symbol ("set_builder", out function);
var set_builder = (BuilderFunction) function;
if (this.builder != null) {
set_builder (this.builder);
}

this.module.symbol (window_symbol, out function);
if (function == null) {
stderr.printf (@"Module does not contain symbol '$window_symbol'.\n");
return;
}

var set_window = (WindowFunction) function;
this.module.symbol ("set_window", out function);
var set_window = (WindowFunction) function;
if (this.window != null) {
set_window (this.window);
}

this.module.symbol (run_symbol, out function);
this.module.symbol ("main", out function);
if (function == null) {
stderr.printf (@"Function '$run_symbol' not found.\n");
stderr.printf (@"Function 'main' not found.\n");
return;
}

var run = (RunFunction) function;
run ();
var main_function = (MainFunction) function;
main_function ();
}

public void close_window () {
Expand Down Expand Up @@ -211,7 +185,7 @@ namespace Workbench {
public signal void css_parser_error (string message, int start_line, int start_char, int end_line, int end_char);

[CCode (has_target=false)]
private delegate void RunFunction ();
private delegate void MainFunction ();

[CCode (has_target=false)]
private delegate void BuilderFunction (Gtk.Builder builder);
Expand All @@ -231,6 +205,11 @@ namespace Workbench {
}

void main (string[] args) {
if (!Module.supported ()) {
stderr.printf ("This system does not support loadable modules.\n");
Process.exit (1);
}

var loop = new MainLoop();

Adw.init();
Expand Down
3 changes: 0 additions & 3 deletions src/Previewer/previewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
</method>
<method name="Run">
<arg type="s" name="filename" direction="in"/>
<arg type="s" name="run_symbol" direction="in"/>
<arg type="s" name="builder_symbol" direction="in"/>
<arg type="s" name="window_symbol" direction="in"/>
<arg type="s" name="uri" direction="in"/>
</method>
<method name="CloseWindow">
Expand Down
11 changes: 1 addition & 10 deletions src/langs/vala/Compiler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Gio from "gi://Gio";
import GLib from "gi://GLib";
import dbus_previewer from "../../Previewer/DBusPreviewer.js";
import { decode } from "../../util.js";

Expand All @@ -21,8 +20,6 @@ export default function Compiler({ session }) {
return;
}

await module_file.delete_async(GLib.PRIORITY_DEFAULT, null).catch(() => {});

const valac_launcher = new Gio.SubprocessLauncher();
valac_launcher.set_cwd(file.get_path());
const valac = valac_launcher.spawnv([
Expand Down Expand Up @@ -52,13 +49,7 @@ export default function Compiler({ session }) {
async function run() {
try {
const proxy = await dbus_previewer.getProxy();
await proxy.RunAsync(
module_file.get_path(),
"main",
"set_builder",
"set_window",
session.file.get_uri(),
);
await proxy.RunAsync(module_file.get_path(), session.file.get_uri());
} catch (err) {
logError(err);
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/langs/vala/workbench.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace workbench {
}
}

public void set_builder (Gtk.Builder b) {
workbench.builder = b;
public void set_builder (Gtk.Builder builder) {
workbench.builder = builder;
}

public void set_window (Gtk.Window w) {
workbench.window = w;
public void set_window (Gtk.Window window) {
workbench.window = window;
}

public void set_base_uri (string uri) {
Expand Down