From cc6f3bccd7623c79e35da0c06beb1de0b18083ed Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 15 Nov 2020 07:48:08 +0100 Subject: [PATCH 01/48] Add run and stop button --- src/Widgets/HeaderBar.vala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index 351cd6f85d..52940ec8cd 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -63,6 +63,20 @@ namespace Scratch.Widgets { _("Save this file with a different name") ); + var run_button = new Gtk.Button.from_icon_name ("media-playback-start", Gtk.IconSize.LARGE_TOOLBAR); + run_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_REVERT; + run_button.tooltip_markup = Granite.markup_accel_tooltip ( + app_instance.get_accels_for_action (run_button.action_name), + _("Run") + ); + + var stop_button = new Gtk.Button.from_icon_name ("media-playback-stop", Gtk.IconSize.LARGE_TOOLBAR); + stop_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_REVERT; + stop_button.tooltip_markup = Granite.markup_accel_tooltip ( + app_instance.get_accels_for_action (stop_button.action_name), + _("Stop") + ); + var revert_button = new Gtk.Button.from_icon_name ("document-revert", Gtk.IconSize.LARGE_TOOLBAR); revert_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_REVERT; revert_button.tooltip_markup = Granite.markup_accel_tooltip ( @@ -186,6 +200,8 @@ namespace Scratch.Widgets { pack_start (save_button); pack_start (save_as_button); pack_start (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); + pack_start (run_button); + pack_start (stop_button); pack_start (revert_button); pack_end (app_menu); pack_end (share_app_menu); From f76b1da3bc44b613ef1ba550eb56d85966451e6d Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 6 Feb 2021 08:55:30 +0100 Subject: [PATCH 02/48] Add ProjectManager --- src/FolderManager/FileView.vala | 18 +++++- src/MainWindow.vala | 26 +++++++++ src/Services/ProjectManager.vala | 99 ++++++++++++++++++++++++++++++++ src/Widgets/HeaderBar.vala | 4 +- src/meson.build | 1 + 5 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 src/Services/ProjectManager.vala diff --git a/src/FolderManager/FileView.vala b/src/FolderManager/FileView.vala index c97a540b18..7588489756 100644 --- a/src/FolderManager/FileView.vala +++ b/src/FolderManager/FileView.vala @@ -26,6 +26,7 @@ namespace Scratch.FolderManager { private GLib.Settings settings; public signal void select (string file); + public signal void select_project (string path); // This is a workaround for SourceList silliness: you cannot remove an item // without it automatically selecting another one. @@ -52,7 +53,22 @@ namespace Scratch.FolderManager { } if (item is FileItem) { - select (((FileItem) item).file.path); + FileItem file_item = (FileItem) item; + var project_path = file_item.file.path; + + select (file_item.file.path); + + Granite.Widgets.SourceList.Item? parent_item = item; + while (parent_item != parent_item.parent) { + if (parent_item.parent.name == null || parent_item.parent.name == "") { + break; + } + + parent_item = parent_item.parent; + project_path += "/.."; + } + + select_project (GLib.File.new_for_path (project_path).get_path ()); } } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 186a81d5ba..9f49626795 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -24,6 +24,8 @@ namespace Scratch { public const int FONT_SIZE_MIN = 7; private const uint MAX_SEARCH_TEXT_LENGTH = 255; + private Services.ProjectManager project; + public weak Scratch.Application app { get; construct; } public Scratch.Widgets.DocumentView document_view; @@ -74,6 +76,8 @@ namespace Scratch { public const string ACTION_PREFERENCES = "preferences"; public const string ACTION_UNDO = "action_undo"; public const string ACTION_REDO = "action_redo"; + public const string ACTION_RUN = "action_run"; + public const string ACTION_STOP = "action_stop"; public const string ACTION_REVERT = "action_revert"; public const string ACTION_SAVE = "action_save"; public const string ACTION_SAVE_AS = "action_save_as"; @@ -104,6 +108,8 @@ namespace Scratch { { ACTION_COLLAPSE_ALL_FOLDERS, action_collapse_all_folders }, { ACTION_ORDER_FOLDERS, action_order_folders }, { ACTION_PREFERENCES, action_preferences }, + { ACTION_RUN, action_run }, + { ACTION_STOP, action_stop }, { ACTION_REVERT, action_revert }, { ACTION_SAVE, action_save }, { ACTION_SAVE_AS, action_save_as }, @@ -145,6 +151,8 @@ namespace Scratch { action_accelerators.set (ACTION_FIND_NEXT, "g"); action_accelerators.set (ACTION_FIND_PREVIOUS, "g"); action_accelerators.set (ACTION_OPEN, "o"); + action_accelerators.set (ACTION_RUN, ""); + action_accelerators.set (ACTION_STOP, ""); action_accelerators.set (ACTION_REVERT, "o"); action_accelerators.set (ACTION_SAVE, "s"); action_accelerators.set (ACTION_SAVE_AS, "s"); @@ -181,6 +189,8 @@ namespace Scratch { } construct { + project = new Services.ProjectManager (); + actions = new SimpleActionGroup (); actions.add_action_entries (ACTION_ENTRIES, this); insert_action_group ("win", actions); @@ -345,6 +355,10 @@ namespace Scratch { } }); + folder_manager_view.select_project.connect ((path) => { + project.path = path; + }); + folder_manager_view.restore_saved_state (); bottombar = new Gtk.Notebook (); @@ -517,6 +531,8 @@ namespace Scratch { Utils.action_from_group (ACTION_SAVE_AS, actions).set_enabled (val); Utils.action_from_group (ACTION_UNDO, actions).set_enabled (val); Utils.action_from_group (ACTION_REDO, actions).set_enabled (val); + Utils.action_from_group (ACTION_RUN, actions).set_enabled (val); + Utils.action_from_group (ACTION_STOP, actions).set_enabled (val); Utils.action_from_group (ACTION_REVERT, actions).set_enabled (val); search_bar.sensitive = val; toolbar.share_app_menu.sensitive = val; @@ -820,6 +836,16 @@ namespace Scratch { } } + private void action_run () { + project.build (); + project.install (); + project.run (); + } + + private void action_stop () { + project.run (); + } + private void action_revert () { var confirmation_dialog = new Scratch.Dialogs.RestoreConfirmationDialog (this); if (confirmation_dialog.run () == Gtk.ResponseType.ACCEPT) { diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala new file mode 100644 index 0000000000..6755a3bd5a --- /dev/null +++ b/src/Services/ProjectManager.vala @@ -0,0 +1,99 @@ +public class Scratch.Services.ProjectManager : Object{ + public string path { get; set; } + + private string? project_name () { + try { + string content; + FileUtils.get_contents (Path.build_filename (path, "meson.build"), out content); + + var regex = new Regex ("project\\s*\\(\\s*'(?P[^']*)'[^\\)]*\\)"); + + MatchInfo mi; + if (regex.match (content, 0, out mi)) { + return mi.fetch_named ("name"); + } + } catch (FileError e) { + stderr.printf (e.message); + } catch (RegexError e) { + stderr.printf (e.message); + } + + return null; + } + + private bool run_command (string[] cmd) { + try { + string[] spawn_args = cmd; + string[] spawn_env = Environ.get (); + int status; + + Process.spawn_sync (path, + spawn_args, + spawn_env, + SpawnFlags.SEARCH_PATH, + null, + null, + null, + out status); + + if (status != 0) { + return false; + } + } catch (SpawnError e) { + print ("Error: %s\n", e.message); + return false; + } + + return true; + } + + public bool build () { + var meson_build = Path.build_filename (path, "meson.build"); + if (FileUtils.test (meson_build, FileTest.IS_REGULAR)) { + var build_folder = Path.build_filename (path, "build"); + var is_ready = FileUtils.test (build_folder, FileTest.IS_DIR); + if (!is_ready) { + is_ready = run_command ({ + "meson", + "build", + "--prefix=/usr" + }); + } + + if (!is_ready) { + return false; + } + + return run_command ({ + "ninja", + "-C", + "%s".printf (Path.build_filename (path, "build")) + }); + } + + return false; + } + + public bool install () { + return run_command ({ + "pkexec", + "bash", + "-c", + "ninja -C %s install; chown %s:%s %s".printf ( + Path.build_filename (path, "build"), + Environment.get_variable ("USER"), + Environment.get_variable ("USER"), + Path.build_filename (path, "build", ".ninja_*") + ) + }); + } + + public bool run () { + var project_name = project_name (); + if (project_name != null) { + return run_command ({project_name}); + } + + return false; + } +} diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index 52940ec8cd..242e023dc1 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -64,14 +64,14 @@ namespace Scratch.Widgets { ); var run_button = new Gtk.Button.from_icon_name ("media-playback-start", Gtk.IconSize.LARGE_TOOLBAR); - run_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_REVERT; + run_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_RUN; run_button.tooltip_markup = Granite.markup_accel_tooltip ( app_instance.get_accels_for_action (run_button.action_name), _("Run") ); var stop_button = new Gtk.Button.from_icon_name ("media-playback-stop", Gtk.IconSize.LARGE_TOOLBAR); - stop_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_REVERT; + stop_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_STOP; stop_button.tooltip_markup = Granite.markup_accel_tooltip ( app_instance.get_accels_for_action (stop_button.action_name), _("Stop") diff --git a/src/meson.build b/src/meson.build index 58a4ba688a..10751e13bc 100644 --- a/src/meson.build +++ b/src/meson.build @@ -28,6 +28,7 @@ code_files = files( 'Services/Document.vala', 'Services/FileHandler.vala', 'Services/PluginManager.vala', + 'Services/ProjectManager.vala', 'Services/Settings.vala', 'Services/TemplateManager.vala', 'Services/ZeitgeistLogger.vala', From 2a66e7cea3151dda6680110282ca8a826bf947d0 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 6 Feb 2021 09:09:29 +0100 Subject: [PATCH 03/48] Satisfy linter --- src/FolderManager/FileView.vala | 2 -- src/Services/ProjectManager.vala | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/FolderManager/FileView.vala b/src/FolderManager/FileView.vala index 83486c4d9f..2d649acdc4 100644 --- a/src/FolderManager/FileView.vala +++ b/src/FolderManager/FileView.vala @@ -26,9 +26,7 @@ namespace Scratch.FolderManager { private GLib.Settings settings; public signal void select (string file); - public signal void select_project (string path); - public signal void close_all_docs_from_path (string path); diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 6755a3bd5a..ce0124cc0e 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -1,4 +1,4 @@ -public class Scratch.Services.ProjectManager : Object{ +public class Scratch.Services.ProjectManager : Object { public string path { get; set; } private string? project_name () { @@ -38,7 +38,7 @@ public class Scratch.Services.ProjectManager : Object{ if (status != 0) { return false; - } + } } catch (SpawnError e) { print ("Error: %s\n", e.message); return false; From c99319f73fbd9fab75ef1adda9892ff5d4d77887 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 6 Feb 2021 09:16:47 +0100 Subject: [PATCH 04/48] Add TODO --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index a5797b33df..2e0c34023b 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -840,7 +840,7 @@ namespace Scratch { } private void action_stop () { - project.run (); + // TODO: stop running application } private void action_revert () { From fac9c1f28999c0594fae48758c67831c9f321b36 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 6 Feb 2021 09:20:15 +0100 Subject: [PATCH 05/48] Remove stop action --- src/MainWindow.vala | 8 -------- src/Widgets/HeaderBar.vala | 8 -------- 2 files changed, 16 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 2e0c34023b..9412e6b622 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -77,7 +77,6 @@ namespace Scratch { public const string ACTION_UNDO = "action_undo"; public const string ACTION_REDO = "action_redo"; public const string ACTION_RUN = "action_run"; - public const string ACTION_STOP = "action_stop"; public const string ACTION_REVERT = "action_revert"; public const string ACTION_SAVE = "action_save"; public const string ACTION_SAVE_AS = "action_save_as"; @@ -109,7 +108,6 @@ namespace Scratch { { ACTION_ORDER_FOLDERS, action_order_folders }, { ACTION_PREFERENCES, action_preferences }, { ACTION_RUN, action_run }, - { ACTION_STOP, action_stop }, { ACTION_REVERT, action_revert }, { ACTION_SAVE, action_save }, { ACTION_SAVE_AS, action_save_as }, @@ -152,7 +150,6 @@ namespace Scratch { action_accelerators.set (ACTION_FIND_PREVIOUS, "g"); action_accelerators.set (ACTION_OPEN, "o"); action_accelerators.set (ACTION_RUN, ""); - action_accelerators.set (ACTION_STOP, ""); action_accelerators.set (ACTION_REVERT, "o"); action_accelerators.set (ACTION_SAVE, "s"); action_accelerators.set (ACTION_SAVE_AS, "s"); @@ -544,7 +541,6 @@ namespace Scratch { Utils.action_from_group (ACTION_UNDO, actions).set_enabled (val); Utils.action_from_group (ACTION_REDO, actions).set_enabled (val); Utils.action_from_group (ACTION_RUN, actions).set_enabled (val); - Utils.action_from_group (ACTION_STOP, actions).set_enabled (val); Utils.action_from_group (ACTION_REVERT, actions).set_enabled (val); search_bar.sensitive = val; toolbar.share_app_menu.sensitive = val; @@ -839,10 +835,6 @@ namespace Scratch { project.run (); } - private void action_stop () { - // TODO: stop running application - } - private void action_revert () { var confirmation_dialog = new Scratch.Dialogs.RestoreConfirmationDialog (this); if (confirmation_dialog.run () == Gtk.ResponseType.ACCEPT) { diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index 428b78025d..b0316700f6 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -74,13 +74,6 @@ namespace Scratch.Widgets { _("Run") ); - var stop_button = new Gtk.Button.from_icon_name ("media-playback-stop", Gtk.IconSize.LARGE_TOOLBAR); - stop_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_STOP; - stop_button.tooltip_markup = Granite.markup_accel_tooltip ( - app_instance.get_accels_for_action (stop_button.action_name), - _("Stop") - ); - var revert_button = new Gtk.Button.from_icon_name ("document-revert", Gtk.IconSize.LARGE_TOOLBAR); revert_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_REVERT; revert_button.tooltip_markup = Granite.markup_accel_tooltip ( @@ -210,7 +203,6 @@ namespace Scratch.Widgets { pack_start (save_as_button); pack_start (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); pack_start (run_button); - pack_start (stop_button); pack_start (revert_button); pack_end (app_menu); pack_end (share_app_menu); From 4dd856825d1c0bc05a44c547e66bc6fe7745c61e Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 6 Feb 2021 09:40:20 +0100 Subject: [PATCH 06/48] Make calls async --- src/MainWindow.vala | 6 +-- src/Services/ProjectManager.vala | 70 ++++++++++++++++++++------------ 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 9412e6b622..fd0eb6beb7 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -830,9 +830,9 @@ namespace Scratch { } private void action_run () { - project.build (); - project.install (); - project.run (); + project.build_install_run.begin ((obj, res) => { + project.build_install_run.end (res); + }); } private void action_revert () { diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index ce0124cc0e..c7b91d0580 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -21,39 +21,47 @@ public class Scratch.Services.ProjectManager : Object { return null; } - private bool run_command (string[] cmd) { + private async bool run_command (string[] cmd) { + MainLoop loop = new MainLoop (); + bool exit_status = false; + try { string[] spawn_args = cmd; string[] spawn_env = Environ.get (); - int status; - - Process.spawn_sync (path, - spawn_args, - spawn_env, - SpawnFlags.SEARCH_PATH, - null, - null, - null, - out status); - - if (status != 0) { - return false; - } + Pid child_pid; + + Process.spawn_async ( + path, + spawn_args, + spawn_env, + SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, + null, + out child_pid + ); + + ChildWatch.add (child_pid, (pid, status) => { + // Triggered when the child indicated by child_pid exits + Process.close_pid (pid); + exit_status = (status == 0); + loop.quit (); + }); + + loop.run (); + + return exit_status; } catch (SpawnError e) { - print ("Error: %s\n", e.message); + warning ("Could not run command: %s\n", e.message); return false; } - - return true; } - public bool build () { + private async bool build () { var meson_build = Path.build_filename (path, "meson.build"); if (FileUtils.test (meson_build, FileTest.IS_REGULAR)) { var build_folder = Path.build_filename (path, "build"); var is_ready = FileUtils.test (build_folder, FileTest.IS_DIR); if (!is_ready) { - is_ready = run_command ({ + is_ready = yield run_command ({ "meson", "build", "--prefix=/usr" @@ -64,7 +72,7 @@ public class Scratch.Services.ProjectManager : Object { return false; } - return run_command ({ + return yield run_command ({ "ninja", "-C", "%s".printf (Path.build_filename (path, "build")) @@ -74,8 +82,8 @@ public class Scratch.Services.ProjectManager : Object { return false; } - public bool install () { - return run_command ({ + private async bool install () { + return yield run_command ({ "pkexec", "bash", "-c", @@ -88,12 +96,24 @@ public class Scratch.Services.ProjectManager : Object { }); } - public bool run () { + private async bool run () { var project_name = project_name (); if (project_name != null) { - return run_command ({project_name}); + return yield run_command ({project_name}); } return false; } + + public async bool build_install_run () { + if (!yield build ()) { + return false; + } + + if (!yield install ()) { + return false; + } + + return yield run (); + } } From 3dba84e390881157c134b9ac60058d1b7d1fae62 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 6 Feb 2021 09:41:29 +0100 Subject: [PATCH 07/48] Separate run button --- src/Widgets/HeaderBar.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index b0316700f6..a670f49c11 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -203,6 +203,7 @@ namespace Scratch.Widgets { pack_start (save_as_button); pack_start (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); pack_start (run_button); + pack_start (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); pack_start (revert_button); pack_end (app_menu); pack_end (share_app_menu); From 13c4b61d35ed8f08944d6278787b5920038ec726 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 6 Feb 2021 11:42:06 +0100 Subject: [PATCH 08/48] Prevent running same project multiple times --- src/Services/ProjectManager.vala | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index c7b91d0580..daa905c249 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -1,5 +1,6 @@ public class Scratch.Services.ProjectManager : Object { public string path { get; set; } + public bool is_running { get; set; } private string? project_name () { try { @@ -106,14 +107,25 @@ public class Scratch.Services.ProjectManager : Object { } public async bool build_install_run () { + if (is_running) { + debug ("Project “%s“ is already running", path); + return false; + } + + is_running = true; if (!yield build ()) { + is_running = false; return false; } if (!yield install ()) { + is_running = false; return false; } - return yield run (); + var result = yield run (); + is_running = false; + + return result; } } From 808dcb658c4d35a18fbd495ea13ade6a6b6788dd Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 6 Feb 2021 11:53:30 +0100 Subject: [PATCH 09/48] Run application when hitting F5 --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index fd0eb6beb7..d1e6795c0a 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -149,7 +149,7 @@ namespace Scratch { action_accelerators.set (ACTION_FIND_NEXT, "g"); action_accelerators.set (ACTION_FIND_PREVIOUS, "g"); action_accelerators.set (ACTION_OPEN, "o"); - action_accelerators.set (ACTION_RUN, ""); + action_accelerators.set (ACTION_RUN, "F5"); action_accelerators.set (ACTION_REVERT, "o"); action_accelerators.set (ACTION_SAVE, "s"); action_accelerators.set (ACTION_SAVE_AS, "s"); From afedcd0b8bc0b8924851c11f0146f02345c25856 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 7 Feb 2021 07:42:01 +0100 Subject: [PATCH 10/48] Provide project command outputs with signals --- src/Services/ProjectManager.vala | 57 ++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index daa905c249..1218516601 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -2,6 +2,9 @@ public class Scratch.Services.ProjectManager : Object { public string path { get; set; } public bool is_running { get; set; } + public signal void on_standard_output (string line); + public signal void on_standard_error (string line); + private string? project_name () { try { string content; @@ -22,6 +25,36 @@ public class Scratch.Services.ProjectManager : Object { return null; } + private bool process_line (IOChannel channel, IOCondition condition, string stream_name) { + if (condition == IOCondition.HUP) { + return false; + } + + try { + string line; + channel.read_line (out line, null, null); + + switch (stream_name) { + case "stdout": + print (line); + on_standard_output (line); + break; + case "stderr": + print (line); + on_standard_error (line); + break; + } + } catch (IOChannelError e) { + warning ("%s: IOChannelError: %s", stream_name, e.message); + return false; + } catch (ConvertError e) { + warning ("%s: ConvertError: %s", stream_name, e.message); + return false; + } + + return true; + } + private async bool run_command (string[] cmd) { MainLoop loop = new MainLoop (); bool exit_status = false; @@ -31,15 +64,35 @@ public class Scratch.Services.ProjectManager : Object { string[] spawn_env = Environ.get (); Pid child_pid; - Process.spawn_async ( + int standard_input; + int standard_output; + int standard_error; + + Process.spawn_async_with_pipes ( path, spawn_args, spawn_env, SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, null, - out child_pid + out child_pid, + out standard_input, + out standard_output, + out standard_error ); + // stdout + IOChannel output = new IOChannel.unix_new (standard_output); + output.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => { + return process_line (channel, condition, "stdout"); + }); + + // stderr + IOChannel error = new IOChannel.unix_new (standard_error); + error.add_watch (IOCondition.IN | IOCondition.HUP, (channel, condition) => { + return process_line (channel, condition, "stderr"); + }); + + ChildWatch.add (child_pid, (pid, status) => { // Triggered when the child indicated by child_pid exits Process.close_pid (pid); From 1d188e951795f0506e7ae8ddbc6316e2a698a2a1 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 7 Feb 2021 07:50:50 +0100 Subject: [PATCH 11/48] Add build action --- src/MainWindow.vala | 10 ++++++++++ src/Services/ProjectManager.vala | 24 ++++++++++++++++++------ src/Widgets/HeaderBar.vala | 8 ++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index d1e6795c0a..3caf7bd139 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -62,6 +62,7 @@ namespace Scratch { public SimpleActionGroup actions { get; construct; } public const string ACTION_PREFIX = "win."; + public const string ACTION_BUILD = "action_build"; public const string ACTION_FIND = "action_find"; public const string ACTION_FIND_NEXT = "action_find_next"; public const string ACTION_FIND_PREVIOUS = "action_find_previous"; @@ -99,6 +100,7 @@ namespace Scratch { public static Gee.MultiMap action_accelerators = new Gee.HashMultiMap (); private const ActionEntry[] ACTION_ENTRIES = { + { ACTION_BUILD, action_build }, { ACTION_FIND, action_fetch }, { ACTION_FIND_NEXT, action_find_next }, { ACTION_FIND_PREVIOUS, action_find_previous }, @@ -145,6 +147,7 @@ namespace Scratch { } static construct { + action_accelerators.set (ACTION_BUILD, "F4"); action_accelerators.set (ACTION_FIND, "f"); action_accelerators.set (ACTION_FIND_NEXT, "g"); action_accelerators.set (ACTION_FIND_PREVIOUS, "g"); @@ -540,6 +543,7 @@ namespace Scratch { Utils.action_from_group (ACTION_SAVE_AS, actions).set_enabled (val); Utils.action_from_group (ACTION_UNDO, actions).set_enabled (val); Utils.action_from_group (ACTION_REDO, actions).set_enabled (val); + Utils.action_from_group (ACTION_BUILD, actions).set_enabled (val); Utils.action_from_group (ACTION_RUN, actions).set_enabled (val); Utils.action_from_group (ACTION_REVERT, actions).set_enabled (val); search_bar.sensitive = val; @@ -829,6 +833,12 @@ namespace Scratch { } } + private void action_build () { + project.build.begin ((obj, res) => { + project.build.end (res); + }); + } + private void action_run () { project.build_install_run.begin ((obj, res) => { project.build_install_run.end (res); diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 1218516601..ea1913e39f 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -109,7 +109,7 @@ public class Scratch.Services.ProjectManager : Object { } } - private async bool build () { + private async bool build_project () { var meson_build = Path.build_filename (path, "meson.build"); if (FileUtils.test (meson_build, FileTest.IS_REGULAR)) { var build_folder = Path.build_filename (path, "build"); @@ -136,7 +136,7 @@ public class Scratch.Services.ProjectManager : Object { return false; } - private async bool install () { + private async bool install_project () { return yield run_command ({ "pkexec", "bash", @@ -150,7 +150,7 @@ public class Scratch.Services.ProjectManager : Object { }); } - private async bool run () { + private async bool run_project () { var project_name = project_name (); if (project_name != null) { return yield run_command ({project_name}); @@ -159,6 +159,18 @@ public class Scratch.Services.ProjectManager : Object { return false; } + public async bool build () { + if (is_running) { + debug ("Project “%s“ is already running", path); + return false; + } + + var result = yield build_project (); + is_running = false; + + return result; + } + public async bool build_install_run () { if (is_running) { debug ("Project “%s“ is already running", path); @@ -166,17 +178,17 @@ public class Scratch.Services.ProjectManager : Object { } is_running = true; - if (!yield build ()) { + if (!yield build_project ()) { is_running = false; return false; } - if (!yield install ()) { + if (!yield install_project ()) { is_running = false; return false; } - var result = yield run (); + var result = yield run_project (); is_running = false; return result; diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index a670f49c11..a5056bc321 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -67,6 +67,13 @@ namespace Scratch.Widgets { _("Save this file with a different name") ); + var build_button = new Gtk.Button.from_icon_name ("media-playlist-repeat", Gtk.IconSize.LARGE_TOOLBAR); + build_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_BUILD; + build_button.tooltip_markup = Granite.markup_accel_tooltip ( + app_instance.get_accels_for_action (build_button.action_name), + _("Build") + ); + var run_button = new Gtk.Button.from_icon_name ("media-playback-start", Gtk.IconSize.LARGE_TOOLBAR); run_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_RUN; run_button.tooltip_markup = Granite.markup_accel_tooltip ( @@ -202,6 +209,7 @@ namespace Scratch.Widgets { pack_start (save_button); pack_start (save_as_button); pack_start (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); + pack_start (build_button); pack_start (run_button); pack_start (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); pack_start (revert_button); From 04d10032946456674f7c64f8ce2204ed57b53c0c Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 7 Feb 2021 08:05:08 +0100 Subject: [PATCH 12/48] Add stop button --- src/MainWindow.vala | 8 ++++++++ src/Services/ProjectManager.vala | 21 +++++++++++++++++---- src/Widgets/HeaderBar.vala | 8 ++++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 3caf7bd139..edeb3464a5 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -82,6 +82,7 @@ namespace Scratch { public const string ACTION_SAVE = "action_save"; public const string ACTION_SAVE_AS = "action_save_as"; public const string ACTION_SHOW_FIND = "action_show_find"; + public const string ACTION_STOP = "action_stop"; public const string ACTION_TEMPLATES = "action_templates"; public const string ACTION_SHOW_REPLACE = "action_show_replace"; public const string ACTION_TO_LOWER_CASE = "action_to_lower_case"; @@ -114,6 +115,7 @@ namespace Scratch { { ACTION_SAVE, action_save }, { ACTION_SAVE_AS, action_save_as }, { ACTION_SHOW_FIND, action_show_fetch, null, "false" }, + { ACTION_STOP, action_stop }, { ACTION_TEMPLATES, action_templates }, { ACTION_GO_TO, action_go_to }, { ACTION_SORT_LINES, action_sort_lines }, @@ -162,6 +164,7 @@ namespace Scratch { action_accelerators.set (ACTION_UNDO, "z"); action_accelerators.set (ACTION_REDO, "z"); action_accelerators.set (ACTION_SHOW_REPLACE, "r"); + action_accelerators.set (ACTION_STOP, "F6"); action_accelerators.set (ACTION_TO_LOWER_CASE, "l"); action_accelerators.set (ACTION_TO_UPPER_CASE, "u"); action_accelerators.set (ACTION_DUPLICATE, "d"); @@ -545,6 +548,7 @@ namespace Scratch { Utils.action_from_group (ACTION_REDO, actions).set_enabled (val); Utils.action_from_group (ACTION_BUILD, actions).set_enabled (val); Utils.action_from_group (ACTION_RUN, actions).set_enabled (val); + Utils.action_from_group (ACTION_STOP, actions).set_enabled (val); Utils.action_from_group (ACTION_REVERT, actions).set_enabled (val); search_bar.sensitive = val; toolbar.share_app_menu.sensitive = val; @@ -845,6 +849,10 @@ namespace Scratch { }); } + private void action_stop () { + project.stop (); + } + private void action_revert () { var confirmation_dialog = new Scratch.Dialogs.RestoreConfirmationDialog (this); if (confirmation_dialog.run () == Gtk.ResponseType.ACCEPT) { diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index ea1913e39f..7d46803a73 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -5,6 +5,8 @@ public class Scratch.Services.ProjectManager : Object { public signal void on_standard_output (string line); public signal void on_standard_error (string line); + private Pid command_pid; + private string? project_name () { try { string content; @@ -62,7 +64,6 @@ public class Scratch.Services.ProjectManager : Object { try { string[] spawn_args = cmd; string[] spawn_env = Environ.get (); - Pid child_pid; int standard_input; int standard_output; @@ -74,7 +75,7 @@ public class Scratch.Services.ProjectManager : Object { spawn_env, SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, null, - out child_pid, + out command_pid, out standard_input, out standard_output, out standard_error @@ -93,8 +94,8 @@ public class Scratch.Services.ProjectManager : Object { }); - ChildWatch.add (child_pid, (pid, status) => { - // Triggered when the child indicated by child_pid exits + ChildWatch.add (command_pid, (pid, status) => { + // Triggered when the child indicated by command_pid exits Process.close_pid (pid); exit_status = (status == 0); loop.quit (); @@ -193,4 +194,16 @@ public class Scratch.Services.ProjectManager : Object { return result; } + + public bool stop () { + if (!is_running) { + debug ("Project “%s“ is not running", path); + return true; + } + + var result = Posix.kill(command_pid, Posix.Signal.TERM) == 0; + is_running = !result; + + return result; + } } diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index a5056bc321..9540f753ae 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -81,6 +81,13 @@ namespace Scratch.Widgets { _("Run") ); + var stop_button = new Gtk.Button.from_icon_name ("media-playback-stop", Gtk.IconSize.LARGE_TOOLBAR); + stop_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_STOP; + stop_button.tooltip_markup = Granite.markup_accel_tooltip ( + app_instance.get_accels_for_action (stop_button.action_name), + _("Stop") + ); + var revert_button = new Gtk.Button.from_icon_name ("document-revert", Gtk.IconSize.LARGE_TOOLBAR); revert_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_REVERT; revert_button.tooltip_markup = Granite.markup_accel_tooltip ( @@ -211,6 +218,7 @@ namespace Scratch.Widgets { pack_start (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); pack_start (build_button); pack_start (run_button); + pack_start (stop_button); pack_start (new Gtk.Separator (Gtk.Orientation.HORIZONTAL)); pack_start (revert_button); pack_end (app_menu); From fa5d8655db012832729db419900741863b6e5500 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 7 Feb 2021 08:07:18 +0100 Subject: [PATCH 13/48] Satisfy linter --- src/MainWindow.vala | 2 +- src/Services/ProjectManager.vala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index edeb3464a5..e1649fb24c 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -546,7 +546,7 @@ namespace Scratch { Utils.action_from_group (ACTION_SAVE_AS, actions).set_enabled (val); Utils.action_from_group (ACTION_UNDO, actions).set_enabled (val); Utils.action_from_group (ACTION_REDO, actions).set_enabled (val); - Utils.action_from_group (ACTION_BUILD, actions).set_enabled (val); + Utils.action_from_group (ACTION_BUILD, actions).set_enabled (val); Utils.action_from_group (ACTION_RUN, actions).set_enabled (val); Utils.action_from_group (ACTION_STOP, actions).set_enabled (val); Utils.action_from_group (ACTION_REVERT, actions).set_enabled (val); diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 7d46803a73..0b6dfcebd9 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -201,7 +201,7 @@ public class Scratch.Services.ProjectManager : Object { return true; } - var result = Posix.kill(command_pid, Posix.Signal.TERM) == 0; + var result = Posix.kill (command_pid, Posix.Signal.TERM) == 0; is_running = !result; return result; From 50b9f6392059ca591208622eec57cbed2522f7a2 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 7 Feb 2021 08:55:38 +0100 Subject: [PATCH 14/48] Set sensitive for build, run and stop buttons --- src/MainWindow.vala | 20 +++++++++++++++----- src/Services/ProjectManager.vala | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index e1649fb24c..7a8dace55e 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -194,8 +194,6 @@ namespace Scratch { } construct { - project = new Services.ProjectManager (); - actions = new SimpleActionGroup (); actions.add_action_entries (ACTION_ENTRIES, this); insert_action_group ("win", actions); @@ -265,6 +263,12 @@ namespace Scratch { // Show/Hide widgets show_all (); + project = new Services.ProjectManager (); + set_build_run_widgets_sensitive (); + project.notify.connect ((s, p) => { + set_build_run_widgets_sensitive (); + }); + toolbar.templates_button.visible = (plugins.plugin_iface.template_manager.template_available); plugins.plugin_iface.template_manager.notify["template_available"].connect (() => { toolbar.templates_button.visible = (plugins.plugin_iface.template_manager.template_available); @@ -546,9 +550,6 @@ namespace Scratch { Utils.action_from_group (ACTION_SAVE_AS, actions).set_enabled (val); Utils.action_from_group (ACTION_UNDO, actions).set_enabled (val); Utils.action_from_group (ACTION_REDO, actions).set_enabled (val); - Utils.action_from_group (ACTION_BUILD, actions).set_enabled (val); - Utils.action_from_group (ACTION_RUN, actions).set_enabled (val); - Utils.action_from_group (ACTION_STOP, actions).set_enabled (val); Utils.action_from_group (ACTION_REVERT, actions).set_enabled (val); search_bar.sensitive = val; toolbar.share_app_menu.sensitive = val; @@ -561,6 +562,15 @@ namespace Scratch { } } + private void set_build_run_widgets_sensitive () { + bool is_project_selected = project.path != null; + bool is_running = project.is_running; + + Utils.action_from_group (ACTION_BUILD, actions).set_enabled (is_project_selected && !is_running); + Utils.action_from_group (ACTION_RUN, actions).set_enabled (is_project_selected && !is_running); + Utils.action_from_group (ACTION_STOP, actions).set_enabled (is_project_selected && is_running); + } + // Get current document public Scratch.Services.Document? get_current_document () { return document_view.current_document; diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 0b6dfcebd9..a9a0724d67 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -1,3 +1,24 @@ +/* + * Copyright (c) 2021 elementary, Inc. (https://elementary.io) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authored by: Marius Meisenzahl + */ + public class Scratch.Services.ProjectManager : Object { public string path { get; set; } public bool is_running { get; set; } @@ -166,6 +187,7 @@ public class Scratch.Services.ProjectManager : Object { return false; } + is_running = true; var result = yield build_project (); is_running = false; From 59298264c15a1d01c44b3877238d6a1625ab0c70 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 7 Feb 2021 09:40:53 +0100 Subject: [PATCH 15/48] Select project when opening folder --- src/FolderManager/FileView.vala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/FolderManager/FileView.vala b/src/FolderManager/FileView.vala index 2d649acdc4..becfdc44ba 100644 --- a/src/FolderManager/FileView.vala +++ b/src/FolderManager/FileView.vala @@ -93,6 +93,8 @@ namespace Scratch.FolderManager { return; } + select_project (folder.path); + add_folder (folder, true); write_settings (); } From 21fc31181e57b2c0dd291c51ba2f5ee0e4eecac7 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 18 Apr 2021 07:25:56 +0200 Subject: [PATCH 16/48] Restrict support to build and run projects to Flatpak --- src/Services/ProjectManager.vala | 92 +++++++++++++++----------------- 1 file changed, 42 insertions(+), 50 deletions(-) diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index a9a0724d67..9aac071d4f 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -28,16 +28,28 @@ public class Scratch.Services.ProjectManager : Object { private Pid command_pid; - private string? project_name () { + private FlatpakManifest? flatpak_manifest () { try { - string content; - FileUtils.get_contents (Path.build_filename (path, "meson.build"), out content); - - var regex = new Regex ("project\\s*\\(\\s*'(?P[^']*)'[^\\)]*\\)"); - - MatchInfo mi; - if (regex.match (content, 0, out mi)) { - return mi.fetch_named ("name"); + Dir dir = Dir.open (path, 0); + string? name = null; + while ((name = dir.read_name ()) != null) { + string f = Path.build_filename (path, name); + + if (FileUtils.test (f, FileTest.IS_REGULAR) && f.has_suffix (".yml")) { + string content; + FileUtils.get_contents (f, out content); + + var regex = new Regex ("app-id:\\s*(?P[A-Za-z0-9-\\.]+)"); + + MatchInfo mi; + if (regex.match (content, 0, out mi)) { + return new FlatpakManifest () { + manifest = f, + build_dir = Path.build_filename (path, "build-dir"), + app_id = mi.fetch_named ("app_id") + }; + } + } } } catch (FileError e) { stderr.printf (e.message); @@ -48,6 +60,12 @@ public class Scratch.Services.ProjectManager : Object { return null; } + private class FlatpakManifest : Object { + public string manifest { get; set; } + public string build_dir { get; set; } + public string app_id { get; set; } + } + private bool process_line (IOChannel channel, IOCondition condition, string stream_name) { if (condition == IOCondition.HUP) { return false; @@ -132,50 +150,29 @@ public class Scratch.Services.ProjectManager : Object { } private async bool build_project () { - var meson_build = Path.build_filename (path, "meson.build"); - if (FileUtils.test (meson_build, FileTest.IS_REGULAR)) { - var build_folder = Path.build_filename (path, "build"); - var is_ready = FileUtils.test (build_folder, FileTest.IS_DIR); - if (!is_ready) { - is_ready = yield run_command ({ - "meson", - "build", - "--prefix=/usr" - }); - } - - if (!is_ready) { - return false; - } - + var flatpak_manifest = flatpak_manifest (); + if (flatpak_manifest != null) { return yield run_command ({ - "ninja", - "-C", - "%s".printf (Path.build_filename (path, "build")) + "flatpak-builder", + "--force-clean", + flatpak_manifest.build_dir, + flatpak_manifest.manifest }); } return false; } - private async bool install_project () { - return yield run_command ({ - "pkexec", - "bash", - "-c", - "ninja -C %s install; chown %s:%s %s".printf ( - Path.build_filename (path, "build"), - Environment.get_variable ("USER"), - Environment.get_variable ("USER"), - Path.build_filename (path, "build", ".ninja_*") - ) - }); - } - private async bool run_project () { - var project_name = project_name (); - if (project_name != null) { - return yield run_command ({project_name}); + var flatpak_manifest = flatpak_manifest (); + if (flatpak_manifest != null) { + return yield run_command ({ + "flatpak-builder", + "--run", + flatpak_manifest.build_dir, + flatpak_manifest.manifest, + flatpak_manifest.app_id + }); } return false; @@ -206,11 +203,6 @@ public class Scratch.Services.ProjectManager : Object { return false; } - if (!yield install_project ()) { - is_running = false; - return false; - } - var result = yield run_project (); is_running = false; From e006310de6c2e8844d417c613d7595b58c1f3e87 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 18 Apr 2021 07:28:48 +0200 Subject: [PATCH 17/48] Satisfy linter --- src/Services/ProjectManager.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 9aac071d4f..4d819f4e5f 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -48,7 +48,7 @@ public class Scratch.Services.ProjectManager : Object { build_dir = Path.build_filename (path, "build-dir"), app_id = mi.fetch_named ("app_id") }; - } + } } } } catch (FileError e) { From 8a1422a37fe86044096f0322651d6a11d6428e37 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Mon, 19 Apr 2021 15:40:57 +0200 Subject: [PATCH 18/48] Refactor variable names --- src/MainWindow.vala | 22 +++++++++++----------- src/Services/ProjectManager.vala | 16 ++++++++-------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 96e8fb87a9..7a7b1647ea 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -24,7 +24,7 @@ namespace Scratch { public const int FONT_SIZE_MIN = 7; private const uint MAX_SEARCH_TEXT_LENGTH = 255; - private Services.ProjectManager project; + private Services.ProjectManager project_manager; public weak Scratch.Application app { get; construct; } @@ -263,9 +263,9 @@ namespace Scratch { // Show/Hide widgets show_all (); - project = new Services.ProjectManager (); + project_manager = new Services.ProjectManager (); set_build_run_widgets_sensitive (); - project.notify.connect ((s, p) => { + project_manager.notify.connect ((s, p) => { set_build_run_widgets_sensitive (); }); @@ -366,7 +366,7 @@ namespace Scratch { folder_manager_view.select_project.connect ((path) => { - project.path = path; + project_manager.project_path = path; }); folder_manager_view.close_all_docs_from_path.connect ((a) => { @@ -566,8 +566,8 @@ namespace Scratch { } private void set_build_run_widgets_sensitive () { - bool is_project_selected = project.path != null; - bool is_running = project.is_running; + bool is_project_selected = project_manager.project_path != null; + bool is_running = project_manager.is_running; Utils.action_from_group (ACTION_BUILD, actions).set_enabled (is_project_selected && !is_running); Utils.action_from_group (ACTION_RUN, actions).set_enabled (is_project_selected && !is_running); @@ -851,19 +851,19 @@ namespace Scratch { } private void action_build () { - project.build.begin ((obj, res) => { - project.build.end (res); + project_manager.build.begin ((obj, res) => { + project_manager.build.end (res); }); } private void action_run () { - project.build_install_run.begin ((obj, res) => { - project.build_install_run.end (res); + project_manager.build_install_run.begin ((obj, res) => { + project_manager.build_install_run.end (res); }); } private void action_stop () { - project.stop (); + project_manager.stop (); } private void action_revert () { diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 4d819f4e5f..7614c602f1 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -20,7 +20,7 @@ */ public class Scratch.Services.ProjectManager : Object { - public string path { get; set; } + public string project_path { get; set; } public bool is_running { get; set; } public signal void on_standard_output (string line); @@ -30,10 +30,10 @@ public class Scratch.Services.ProjectManager : Object { private FlatpakManifest? flatpak_manifest () { try { - Dir dir = Dir.open (path, 0); + Dir dir = Dir.open (project_path, 0); string? name = null; while ((name = dir.read_name ()) != null) { - string f = Path.build_filename (path, name); + string f = Path.build_filename (project_path, name); if (FileUtils.test (f, FileTest.IS_REGULAR) && f.has_suffix (".yml")) { string content; @@ -45,7 +45,7 @@ public class Scratch.Services.ProjectManager : Object { if (regex.match (content, 0, out mi)) { return new FlatpakManifest () { manifest = f, - build_dir = Path.build_filename (path, "build-dir"), + build_dir = Path.build_filename (project_path, "build-dir"), app_id = mi.fetch_named ("app_id") }; } @@ -109,7 +109,7 @@ public class Scratch.Services.ProjectManager : Object { int standard_error; Process.spawn_async_with_pipes ( - path, + project_path, spawn_args, spawn_env, SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, @@ -180,7 +180,7 @@ public class Scratch.Services.ProjectManager : Object { public async bool build () { if (is_running) { - debug ("Project “%s“ is already running", path); + debug ("Project “%s“ is already running", project_path); return false; } @@ -193,7 +193,7 @@ public class Scratch.Services.ProjectManager : Object { public async bool build_install_run () { if (is_running) { - debug ("Project “%s“ is already running", path); + debug ("Project “%s“ is already running", project_path); return false; } @@ -211,7 +211,7 @@ public class Scratch.Services.ProjectManager : Object { public bool stop () { if (!is_running) { - debug ("Project “%s“ is not running", path); + debug ("Project “%s“ is not running", project_path); return true; } From a86ac53e14372fb715b4b83158a96f82e4ce5293 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Mon, 19 Apr 2021 15:45:35 +0200 Subject: [PATCH 19/48] Read command from Flatpak manifest --- src/Services/ProjectManager.vala | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 7614c602f1..a68d589c95 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -35,19 +35,29 @@ public class Scratch.Services.ProjectManager : Object { while ((name = dir.read_name ()) != null) { string f = Path.build_filename (project_path, name); - if (FileUtils.test (f, FileTest.IS_REGULAR) && f.has_suffix (".yml")) { + if (FileUtils.test (f, FileTest.IS_REGULAR) && (f.has_suffix (".yml") || f.has_suffix (".yaml"))) { string content; FileUtils.get_contents (f, out content); - var regex = new Regex ("app-id:\\s*(?P[A-Za-z0-9-\\.]+)"); + var re_app_id = new Regex ("app-id:\\s*(?P[A-Za-z0-9-\\.]+)"); + var re_command = new Regex ("command:\\s*(?P[A-Za-z0-9-\\.]+)"); + + var flatpak_manifest = new FlatpakManifest () { + manifest = f, + build_dir = Path.build_filename (project_path, "build-dir") + }; MatchInfo mi; - if (regex.match (content, 0, out mi)) { - return new FlatpakManifest () { - manifest = f, - build_dir = Path.build_filename (project_path, "build-dir"), - app_id = mi.fetch_named ("app_id") - }; + if (re_app_id.match (content, 0, out mi)) { + flatpak_manifest.app_id = mi.fetch_named ("app_id"); + } + + if (re_command.match (content, 0, out mi)) { + flatpak_manifest.command = mi.fetch_named ("command"); + } + + if (flatpak_manifest.app_id.length > 0 && flatpak_manifest.command.length > 0) { + return flatpak_manifest; } } } @@ -64,6 +74,7 @@ public class Scratch.Services.ProjectManager : Object { public string manifest { get; set; } public string build_dir { get; set; } public string app_id { get; set; } + public string command { get; set; } } private bool process_line (IOChannel channel, IOCondition condition, string stream_name) { @@ -171,7 +182,7 @@ public class Scratch.Services.ProjectManager : Object { "--run", flatpak_manifest.build_dir, flatpak_manifest.manifest, - flatpak_manifest.app_id + flatpak_manifest.command }); } From a8a4eff73a38c4f8e6c8821a046859ff625fb76f Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Mon, 19 Apr 2021 16:01:27 +0200 Subject: [PATCH 20/48] Add support for JSON --- .github/workflows/main.yml | 2 +- README.md | 1 + meson.build | 2 + src/Services/ProjectManager.vala | 85 +++++++++++++++++++++----------- 4 files changed, 59 insertions(+), 31 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5e33d7460c..38f346a8f6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: - name: Install Dependencies run: | apt update - apt install -y exuberant-ctags libeditorconfig-dev libgail-3-dev libgee-0.8-dev libgit2-glib-1.0-dev libgranite-dev libgtk-3-dev libgtksourceview-4-dev libgtkspell3-3-dev libhandy-1-dev libpeas-dev libsoup2.4-dev libvala-dev libvte-2.91-dev libzeitgeist-2.0-dev meson valac + apt install -y exuberant-ctags libeditorconfig-dev libgail-3-dev libgee-0.8-dev libgit2-glib-1.0-dev libgranite-dev libgtk-3-dev libgtksourceview-4-dev libgtkspell3-3-dev libhandy-1-dev libjson-glib-dev libpeas-dev libsoup2.4-dev libvala-dev libvte-2.91-dev libzeitgeist-2.0-dev meson valac - name: Build env: DESTDIR: out diff --git a/README.md b/README.md index a3db900b44..e39d156a07 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ You'll need the following dependencies: * libgtkspell3-3-dev * libgranite-dev >= 5.2.0 * libhandy-1-dev >= 0.90.0 +* libjson-glib-dev * libpeas-dev * libsoup2.4-dev * libvala-0.34-dev (or higher) diff --git a/meson.build b/meson.build index f7d6e7e9c3..4400e54b55 100644 --- a/meson.build +++ b/meson.build @@ -31,6 +31,7 @@ gee_dep = dependency('gee-0.8', version: '>=0.8.5') gtk_dep = dependency('gtk+-3.0', version: '>=3.6.0') granite_dep = dependency('granite', version: '>=6.0.0') handy_dep = dependency('libhandy-1', version: '>=0.90.0') +json_dep = dependency('json-glib-1.0') gtksourceview_dep = dependency('gtksourceview-4') peas_dep = dependency('libpeas-1.0') peasgtk_dep = dependency('libpeas-gtk-1.0') @@ -51,6 +52,7 @@ dependencies = [ gtk_dep, granite_dep, handy_dep, + json_dep, gtksourceview_dep, peas_dep, peasgtk_dep, diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index a68d589c95..1123e5bdab 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -29,42 +29,67 @@ public class Scratch.Services.ProjectManager : Object { private Pid command_pid; private FlatpakManifest? flatpak_manifest () { + Dir dir; try { - Dir dir = Dir.open (project_path, 0); - string? name = null; - while ((name = dir.read_name ()) != null) { - string f = Path.build_filename (project_path, name); - - if (FileUtils.test (f, FileTest.IS_REGULAR) && (f.has_suffix (".yml") || f.has_suffix (".yaml"))) { - string content; - FileUtils.get_contents (f, out content); - - var re_app_id = new Regex ("app-id:\\s*(?P[A-Za-z0-9-\\.]+)"); - var re_command = new Regex ("command:\\s*(?P[A-Za-z0-9-\\.]+)"); - - var flatpak_manifest = new FlatpakManifest () { - manifest = f, - build_dir = Path.build_filename (project_path, "build-dir") - }; - - MatchInfo mi; - if (re_app_id.match (content, 0, out mi)) { - flatpak_manifest.app_id = mi.fetch_named ("app_id"); - } + dir = Dir.open (project_path, 0); + } catch (Error e) { + warning ("Could not read Flatpak manifest: %s", e.message); + return null; + } - if (re_command.match (content, 0, out mi)) { - flatpak_manifest.command = mi.fetch_named ("command"); + string? name = null; + while ((name = dir.read_name ()) != null) { + string f = Path.build_filename (project_path, name); + + if (FileUtils.test (f, FileTest.IS_REGULAR)) { + if (f.has_suffix (".yml") || f.has_suffix (".yaml")) { + try { + string content; + FileUtils.get_contents (f, out content); + + var re_app_id = new Regex ("app-id:\\s*(?P[A-Za-z0-9-\\.]+)"); + var re_command = new Regex ("command:\\s*(?P[A-Za-z0-9-\\.]+)"); + + var flatpak_manifest = new FlatpakManifest () { + manifest = f, + build_dir = Path.build_filename (project_path, "build-dir") + }; + + MatchInfo mi; + if (re_app_id.match (content, 0, out mi)) { + flatpak_manifest.app_id = mi.fetch_named ("app_id"); + } + + if (re_command.match (content, 0, out mi)) { + flatpak_manifest.command = mi.fetch_named ("command"); + } + + if (flatpak_manifest.app_id.length > 0 && flatpak_manifest.command.length > 0) { + return flatpak_manifest; + } + } catch (Error e) { + warning ("Could not read Flatpak manifest: %s", e.message); } - - if (flatpak_manifest.app_id.length > 0 && flatpak_manifest.command.length > 0) { - return flatpak_manifest; + } else if (f.has_suffix (".json")) { + try { + string content; + FileUtils.get_contents (f, out content); + + var parser = new Json.Parser (); + parser.load_from_data (content, -1); + var object = parser.get_root ().get_object (); + + return new FlatpakManifest () { + manifest = f, + build_dir = Path.build_filename (project_path, "build-dir"), + app_id = object.get_string_member ("app-id"), + command = object.get_string_member ("command") + }; + } catch (Error e) { + warning ("Could not read Flatpak manifest: %s", e.message); } } } - } catch (FileError e) { - stderr.printf (e.message); - } catch (RegexError e) { - stderr.printf (e.message); } return null; From eb25136f9a249ce259b0c213c6e25d447394fb9f Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Fri, 23 Apr 2021 15:15:32 +0200 Subject: [PATCH 21/48] Update path of build directory --- src/Services/ProjectManager.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 1123e5bdab..90bc98228e 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -52,7 +52,7 @@ public class Scratch.Services.ProjectManager : Object { var flatpak_manifest = new FlatpakManifest () { manifest = f, - build_dir = Path.build_filename (project_path, "build-dir") + build_dir = Path.build_filename (project_path, "build") }; MatchInfo mi; @@ -81,7 +81,7 @@ public class Scratch.Services.ProjectManager : Object { return new FlatpakManifest () { manifest = f, - build_dir = Path.build_filename (project_path, "build-dir"), + build_dir = Path.build_filename (project_path, "build"), app_id = object.get_string_member ("app-id"), command = object.get_string_member ("command") }; From 266638526e9a105f701be3cee3e22371b21b33f0 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 24 Apr 2021 14:31:21 +0200 Subject: [PATCH 22/48] Update tooltip text with project name --- src/MainWindow.vala | 11 +++++++++++ src/Widgets/HeaderBar.vala | 9 ++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index e0bcad7419..7ee370ca43 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -555,6 +555,17 @@ namespace Scratch { Utils.action_from_group (ACTION_BUILD, actions).set_enabled (is_project_selected && !is_running); Utils.action_from_group (ACTION_RUN, actions).set_enabled (is_project_selected && !is_running); Utils.action_from_group (ACTION_STOP, actions).set_enabled (is_project_selected && is_running); + + if (is_project_selected) { + var project_name = Path.get_basename (project_manager.project_path); + toolbar.build_button.tooltip_markup = _("Build ”%s”".printf (project_name)); + toolbar.run_button.tooltip_markup = _("Run ”%s”".printf (project_name)); + toolbar.stop_button.tooltip_markup = _("Stop ”%s”".printf (project_name)); + } else { + toolbar.build_button.tooltip_markup = _("Build"); + toolbar.run_button.tooltip_markup = _("Run"); + toolbar.stop_button.tooltip_markup = _("Stop"); + } } // Get current document diff --git a/src/Widgets/HeaderBar.vala b/src/Widgets/HeaderBar.vala index 9540f753ae..27bac6c7d2 100644 --- a/src/Widgets/HeaderBar.vala +++ b/src/Widgets/HeaderBar.vala @@ -27,6 +27,9 @@ namespace Scratch.Widgets { public Gtk.ToggleButton find_button; public Gtk.Button templates_button; public Code.FormatBar format_bar; + public Gtk.Button build_button; + public Gtk.Button run_button; + public Gtk.Button stop_button; private const string STYLE_SCHEME_HIGH_CONTRAST = "classic"; private const string STYLE_SCHEME_LIGHT = "solarized-light"; @@ -67,21 +70,21 @@ namespace Scratch.Widgets { _("Save this file with a different name") ); - var build_button = new Gtk.Button.from_icon_name ("media-playlist-repeat", Gtk.IconSize.LARGE_TOOLBAR); + build_button = new Gtk.Button.from_icon_name ("media-playlist-repeat", Gtk.IconSize.LARGE_TOOLBAR); build_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_BUILD; build_button.tooltip_markup = Granite.markup_accel_tooltip ( app_instance.get_accels_for_action (build_button.action_name), _("Build") ); - var run_button = new Gtk.Button.from_icon_name ("media-playback-start", Gtk.IconSize.LARGE_TOOLBAR); + run_button = new Gtk.Button.from_icon_name ("media-playback-start", Gtk.IconSize.LARGE_TOOLBAR); run_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_RUN; run_button.tooltip_markup = Granite.markup_accel_tooltip ( app_instance.get_accels_for_action (run_button.action_name), _("Run") ); - var stop_button = new Gtk.Button.from_icon_name ("media-playback-stop", Gtk.IconSize.LARGE_TOOLBAR); + stop_button = new Gtk.Button.from_icon_name ("media-playback-stop", Gtk.IconSize.LARGE_TOOLBAR); stop_button.action_name = MainWindow.ACTION_PREFIX + MainWindow.ACTION_STOP; stop_button.tooltip_markup = Granite.markup_accel_tooltip ( app_instance.get_accels_for_action (stop_button.action_name), From 4970a07087cb11424e5140bb81d3961843931a4e Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 25 Apr 2021 07:19:27 +0200 Subject: [PATCH 23/48] Refactor --- src/FolderManager/FileView.vala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/FolderManager/FileView.vala b/src/FolderManager/FileView.vala index 0978698afd..228d47441d 100644 --- a/src/FolderManager/FileView.vala +++ b/src/FolderManager/FileView.vala @@ -29,7 +29,6 @@ namespace Scratch.FolderManager { public signal void select_project (string path); public signal void close_all_docs_from_path (string path); - // This is a workaround for SourceList silliness: you cannot remove an item // without it automatically selecting another one. public bool ignore_next_select { get; set; default = false; } @@ -55,7 +54,7 @@ namespace Scratch.FolderManager { } if (item is FileItem) { - FileItem file_item = (FileItem) item; + var file_item = (FileItem) item; var project_path = file_item.file.path; select (file_item.file.path); From 03dfb7174f564b249b22395e0eaeee9e372d3b09 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 25 Apr 2021 07:27:31 +0200 Subject: [PATCH 24/48] Set sensitivity based on whether the project is a Flatpak --- src/MainWindow.vala | 2 +- src/Services/ProjectManager.vala | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 7ee370ca43..9aa1c5176c 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -549,7 +549,7 @@ namespace Scratch { } private void set_build_run_widgets_sensitive () { - bool is_project_selected = project_manager.project_path != null; + bool is_project_selected = (project_manager.project_path != null) && (project_manager.flatpak_manifest != null); bool is_running = project_manager.is_running; Utils.action_from_group (ACTION_BUILD, actions).set_enabled (is_project_selected && !is_running); diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 90bc98228e..bafc10bc1a 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -28,7 +28,7 @@ public class Scratch.Services.ProjectManager : Object { private Pid command_pid; - private FlatpakManifest? flatpak_manifest () { + public FlatpakManifest? flatpak_manifest () { Dir dir; try { dir = Dir.open (project_path, 0); @@ -95,7 +95,7 @@ public class Scratch.Services.ProjectManager : Object { return null; } - private class FlatpakManifest : Object { + public class FlatpakManifest : Object { public string manifest { get; set; } public string build_dir { get; set; } public string app_id { get; set; } From 95531d66fca2e66a82dce85bf381fa8ccb3332b9 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Tue, 27 Apr 2021 21:06:02 +0200 Subject: [PATCH 25/48] Use `get_root_folder ()` --- src/FolderManager/FileView.vala | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/FolderManager/FileView.vala b/src/FolderManager/FileView.vala index 9bcc710957..b8259f3a1e 100644 --- a/src/FolderManager/FileView.vala +++ b/src/FolderManager/FileView.vala @@ -57,19 +57,15 @@ namespace Scratch.FolderManager { var file_item = (FileItem) item; var project_path = file_item.file.path; - select (file_item.file.path); + select (project_path); - Granite.Widgets.SourceList.Item? parent_item = item; - while (parent_item != parent_item.parent) { - if (parent_item.parent.name == null || parent_item.parent.name == "") { - break; + var item_for_path = (Item?)(expand_to_path (project_path)); + if (item_for_path != null) { + var search_root = item_for_path.get_root_folder (); + if (search_root is ProjectFolderItem) { + select_project (search_root.file.file.get_path ()); } - - parent_item = parent_item.parent; - project_path += "/.."; } - - select_project (GLib.File.new_for_path (project_path).get_path ()); } } From 8d3d019ed7b468d1dbd6d4c0e7a2409be2a29f15 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Tue, 4 May 2021 19:54:16 +0200 Subject: [PATCH 26/48] Apply suggestions from code review Co-authored-by: Jeremy Wootten --- src/Services/ProjectManager.vala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index bafc10bc1a..eae6f0af92 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -28,7 +28,7 @@ public class Scratch.Services.ProjectManager : Object { private Pid command_pid; - public FlatpakManifest? flatpak_manifest () { + public FlatpakManifest? get_flatpak_manifest () { Dir dir; try { dir = Dir.open (project_path, 0); @@ -52,7 +52,7 @@ public class Scratch.Services.ProjectManager : Object { var flatpak_manifest = new FlatpakManifest () { manifest = f, - build_dir = Path.build_filename (project_path, "build") + build_dir = Path.build_filename (project_path, "flatpak-build") }; MatchInfo mi; @@ -81,7 +81,7 @@ public class Scratch.Services.ProjectManager : Object { return new FlatpakManifest () { manifest = f, - build_dir = Path.build_filename (project_path, "build"), + build_dir = Path.build_filename (project_path, "flatpak-build"), app_id = object.get_string_member ("app-id"), command = object.get_string_member ("command") }; @@ -186,7 +186,7 @@ public class Scratch.Services.ProjectManager : Object { } private async bool build_project () { - var flatpak_manifest = flatpak_manifest (); + var flatpak_manifest = get_flatpak_manifest (); if (flatpak_manifest != null) { return yield run_command ({ "flatpak-builder", @@ -200,7 +200,7 @@ public class Scratch.Services.ProjectManager : Object { } private async bool run_project () { - var flatpak_manifest = flatpak_manifest (); + var flatpak_manifest = get_flatpak_manifest (); if (flatpak_manifest != null) { return yield run_command ({ "flatpak-builder", From 38a8f6099b46f2ccbc4449ab5a3b1415fea969e4 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Tue, 4 May 2021 19:58:21 +0200 Subject: [PATCH 27/48] Fix --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 2734f4a794..bf1a1fe388 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -561,7 +561,7 @@ namespace Scratch { } private void set_build_run_widgets_sensitive () { - bool is_project_selected = (project_manager.project_path != null) && (project_manager.flatpak_manifest != null); + bool is_project_selected = (project_manager.project_path != null) && (project_manager.get_flatpak_manifest() != null); bool is_running = project_manager.is_running; Utils.action_from_group (ACTION_BUILD, actions).set_enabled (is_project_selected && !is_running); From e6b1a77f7b22e5f4c9c0ca7fc2c59ae8b1887d6d Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Tue, 4 May 2021 19:58:41 +0200 Subject: [PATCH 28/48] Satisfy linter --- src/MainWindow.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index bf1a1fe388..4bdb85937b 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -561,7 +561,7 @@ namespace Scratch { } private void set_build_run_widgets_sensitive () { - bool is_project_selected = (project_manager.project_path != null) && (project_manager.get_flatpak_manifest() != null); + bool is_project_selected = (project_manager.project_path != null) && (project_manager.get_flatpak_manifest () != null); bool is_running = project_manager.is_running; Utils.action_from_group (ACTION_BUILD, actions).set_enabled (is_project_selected && !is_running); From 304764f3577cb25e67da8778a779f4723f3c87e1 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Tue, 4 May 2021 20:38:04 +0200 Subject: [PATCH 29/48] Show error dialog --- src/MainWindow.vala | 42 ++++++++++++++++++++++++++++++-- src/Services/ProjectManager.vala | 10 ++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 4bdb85937b..3f7559fbd7 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -25,6 +25,7 @@ namespace Scratch { private const uint MAX_SEARCH_TEXT_LENGTH = 255; private Services.ProjectManager project_manager; + private Array project_output; public weak Scratch.Application app { get; construct; } @@ -271,6 +272,20 @@ namespace Scratch { show_all (); project_manager = new Services.ProjectManager (); + project_output = new Array (); + + project_manager.on_standard_output.connect ((line) => { + project_output.append_val (line); + }); + + project_manager.on_standard_error.connect ((line) => { + project_output.append_val (line); + }); + + project_manager.on_clear.connect ((line) => { + project_output.set_size (0); + }); + set_build_run_widgets_sensitive (); project_manager.notify.connect ((s, p) => { set_build_run_widgets_sensitive (); @@ -858,13 +873,19 @@ namespace Scratch { private void action_build () { project_manager.build.begin ((obj, res) => { - project_manager.build.end (res); + var success = project_manager.build.end (res); + if (!success) { + show_error_dialog (); + } }); } private void action_run () { project_manager.build_install_run.begin ((obj, res) => { - project_manager.build_install_run.end (res); + var success = project_manager.build_install_run.end (res); + if (!success) { + show_error_dialog (); + } }); } @@ -1081,5 +1102,22 @@ namespace Scratch { folder_manager_view.new_branch (file); } + + private void show_error_dialog () { + var message_dialog = new Granite.MessageDialog.with_image_from_icon_name ( + _("Project “%s“ could not be built").printf (project_manager.project_name), + "", + "media-playback-start" + ); + message_dialog.badge_icon = new ThemedIcon ("dialog-error"); + message_dialog.transient_for = this; + + message_dialog.show_error_details (string.joinv ("\n", project_output.data)); + + message_dialog.show_all (); + message_dialog.response.connect ((response_id) => { + message_dialog.destroy (); + }); + } } } diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index eae6f0af92..22581d98a5 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -21,10 +21,16 @@ public class Scratch.Services.ProjectManager : Object { public string project_path { get; set; } + public string project_name { + owned get { + return Path.get_basename (project_path); + } + } public bool is_running { get; set; } public signal void on_standard_output (string line); public signal void on_standard_error (string line); + public signal void on_clear (); private Pid command_pid; @@ -220,6 +226,8 @@ public class Scratch.Services.ProjectManager : Object { return false; } + on_clear (); + is_running = true; var result = yield build_project (); is_running = false; @@ -233,6 +241,8 @@ public class Scratch.Services.ProjectManager : Object { return false; } + on_clear (); + is_running = true; if (!yield build_project ()) { is_running = false; From 285a655e8bc2ef6c54033923560ed3922e3de04b Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Tue, 4 May 2021 20:40:36 +0200 Subject: [PATCH 30/48] Satisfy linter --- src/MainWindow.vala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 3f7559fbd7..f0ab338503 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -1111,11 +1111,11 @@ namespace Scratch { ); message_dialog.badge_icon = new ThemedIcon ("dialog-error"); message_dialog.transient_for = this; - + message_dialog.show_error_details (string.joinv ("\n", project_output.data)); - + message_dialog.show_all (); - message_dialog.response.connect ((response_id) => { + message_dialog.response.connect ((response_id) => { message_dialog.destroy (); }); } From 50619fed8c4f8cb2d7613a5df8c63974a3dea058 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Wed, 5 May 2021 12:44:22 +0200 Subject: [PATCH 31/48] Show last line as secondary_text --- src/MainWindow.vala | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index f0ab338503..4e66bc3459 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -1112,6 +1112,10 @@ namespace Scratch { message_dialog.badge_icon = new ThemedIcon ("dialog-error"); message_dialog.transient_for = this; + if (project_output.length > 0) { + message_dialog.secondary_text = project_output.index (project_output.length - 1); + } + message_dialog.show_error_details (string.joinv ("\n", project_output.data)); message_dialog.show_all (); From e6a8e2f95bbb9e39624899152790ad7895e0ca2e Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Thu, 13 May 2021 08:28:43 +0200 Subject: [PATCH 32/48] Use Gee.ArrayList --- src/MainWindow.vala | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 4e66bc3459..457e010379 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -25,7 +25,7 @@ namespace Scratch { private const uint MAX_SEARCH_TEXT_LENGTH = 255; private Services.ProjectManager project_manager; - private Array project_output; + private Gee.ArrayList project_output; public weak Scratch.Application app { get; construct; } @@ -272,18 +272,18 @@ namespace Scratch { show_all (); project_manager = new Services.ProjectManager (); - project_output = new Array (); + project_output = new Gee.ArrayList (); project_manager.on_standard_output.connect ((line) => { - project_output.append_val (line); + project_output.add (line); }); project_manager.on_standard_error.connect ((line) => { - project_output.append_val (line); + project_output.add (line); }); project_manager.on_clear.connect ((line) => { - project_output.set_size (0); + project_output.clear (); }); set_build_run_widgets_sensitive (); @@ -1112,11 +1112,11 @@ namespace Scratch { message_dialog.badge_icon = new ThemedIcon ("dialog-error"); message_dialog.transient_for = this; - if (project_output.length > 0) { - message_dialog.secondary_text = project_output.index (project_output.length - 1); + if (project_output.size > 0) { + message_dialog.secondary_text = project_output.get (project_output.size - 1); } - message_dialog.show_error_details (string.joinv ("\n", project_output.data)); + message_dialog.show_error_details (string.joinv ("\n", project_output.to_array ())); message_dialog.show_all (); message_dialog.response.connect ((response_id) => { From 8f52a02a481b8e278934c5ed0edd045465cea860 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Thu, 13 May 2021 08:46:12 +0200 Subject: [PATCH 33/48] Show error dialog only if project was not stopped on purpose --- src/MainWindow.vala | 4 ++-- src/Services/ProjectManager.vala | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 457e010379..005bd118ad 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -874,7 +874,7 @@ namespace Scratch { private void action_build () { project_manager.build.begin ((obj, res) => { var success = project_manager.build.end (res); - if (!success) { + if (!success && !project_manager.was_stopped) { show_error_dialog (); } }); @@ -883,7 +883,7 @@ namespace Scratch { private void action_run () { project_manager.build_install_run.begin ((obj, res) => { var success = project_manager.build_install_run.end (res); - if (!success) { + if (!success && !project_manager.was_stopped) { show_error_dialog (); } }); diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 22581d98a5..693e30f968 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -27,6 +27,7 @@ public class Scratch.Services.ProjectManager : Object { } } public bool is_running { get; set; } + public bool was_stopped { get; set; } public signal void on_standard_output (string line); public signal void on_standard_error (string line); @@ -226,6 +227,7 @@ public class Scratch.Services.ProjectManager : Object { return false; } + was_stopped = false; on_clear (); is_running = true; @@ -241,6 +243,7 @@ public class Scratch.Services.ProjectManager : Object { return false; } + was_stopped = false; on_clear (); is_running = true; @@ -261,6 +264,7 @@ public class Scratch.Services.ProjectManager : Object { return true; } + was_stopped = true; var result = Posix.kill (command_pid, Posix.Signal.TERM) == 0; is_running = !result; From 3bf8399668e731932f2f60c52ea83717445c8ce7 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 17 Jul 2021 08:33:04 +0200 Subject: [PATCH 34/48] Try to package flatpak-builder --- ...ush-custom-thread-local-main-context.patch | 59 ++++++++ ...inloop-finish-pending-sources-when-r.patch | 44 ++++++ io.elementary.code.yml | 75 ++++++++++ polkit-autogen | 4 + ...-Add-option-to-build-without-polkitd.patch | 131 ++++++++++++++++++ 5 files changed, 313 insertions(+) create mode 100644 0001-flatpak-http-utils-push-custom-thread-local-main-context.patch create mode 100644 0002-flatpak-custom-thread-mainloop-finish-pending-sources-when-r.patch create mode 100755 polkit-autogen create mode 100644 polkit-build-Add-option-to-build-without-polkitd.patch diff --git a/0001-flatpak-http-utils-push-custom-thread-local-main-context.patch b/0001-flatpak-http-utils-push-custom-thread-local-main-context.patch new file mode 100644 index 0000000000..e7975706b3 --- /dev/null +++ b/0001-flatpak-http-utils-push-custom-thread-local-main-context.patch @@ -0,0 +1,59 @@ +From 1b130c5cc36ce522e367e133fd53ea428133a37c Mon Sep 17 00:00:00 2001 +From: Alexander Larsson +Date: Thu, 18 Mar 2021 10:14:30 +0100 +Subject: [PATCH 1/2] http utils: push custom thread local main context + +We're calling async soup APIs with SOUP_SESSION_USE_THREAD_CONTEXT +set, which means that libsoup async APIs will run async callbacks on +the loop of the thread-default main context. We then manually spin +this main context, because we're supposed to look like a sync call and +the async stuff is just internally. + +This is not really right, because normally there isn't any custom +mainloop context registred, which means we're spinning the main thread +context on some other thread, as well as queuing soup sorces on +it. This can't be any good! + +Rather than doing this we actually create and push our own main +context that we then spin isolated from the default mainloop. +--- + common/flatpak-utils-http.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/common/flatpak-utils-http.c b/common/flatpak-utils-http.c +index ffe1b476..3d144051 100644 +--- a/common/flatpak-utils-http.c ++++ b/common/flatpak-utils-http.c +@@ -670,6 +670,9 @@ flatpak_load_uri (SoupSession *soup_session, + { + g_autoptr(GError) local_error = NULL; + guint n_retries_remaining = DEFAULT_N_NETWORK_RETRIES; ++ g_autoptr(GMainContextPopDefault) main_context = NULL; ++ ++ main_context = flatpak_main_context_new_default (); + + /* Ensure we handle file: uris always */ + if (g_ascii_strncasecmp (uri, "file:", 5) == 0) +@@ -788,6 +791,9 @@ flatpak_download_http_uri (SoupSession *soup_session, + { + g_autoptr(GError) local_error = NULL; + guint n_retries_remaining = DEFAULT_N_NETWORK_RETRIES; ++ g_autoptr(GMainContextPopDefault) main_context = NULL; ++ ++ main_context = flatpak_main_context_new_default (); + + do + { +@@ -1032,6 +1038,9 @@ flatpak_cache_http_uri (SoupSession *soup_session, + { + g_autoptr(GError) local_error = NULL; + guint n_retries_remaining = DEFAULT_N_NETWORK_RETRIES; ++ g_autoptr(GMainContextPopDefault) main_context = NULL; ++ ++ main_context = flatpak_main_context_new_default (); + + do + { +-- +2.30.2 + diff --git a/0002-flatpak-custom-thread-mainloop-finish-pending-sources-when-r.patch b/0002-flatpak-custom-thread-mainloop-finish-pending-sources-when-r.patch new file mode 100644 index 0000000000..8571e29905 --- /dev/null +++ b/0002-flatpak-custom-thread-mainloop-finish-pending-sources-when-r.patch @@ -0,0 +1,44 @@ +From adfa816cd498597abde24a9e13df34fe30ac976e Mon Sep 17 00:00:00 2001 +From: Alexander Larsson +Date: Thu, 18 Mar 2021 10:20:27 +0100 +Subject: [PATCH 2/2] custom thread mainloop: finish pending sources when + removing + +We sometimes set a custom per-thread mainloop because and then spin it +manually to fake a sync call on a thread using async calls. Primarily +this happens with the soup streaming calls. In this case, eventually +we finish the main loop iteration (because, say, the download is done) +so we stop iterating the mainloop and return from the fake sync code. + +However, that might not necessarily be the only thing queued on the +main context. I ran into a situation where it seems like libsoup did +some call to a thread-pool during the async call, and the next time i +used soup aync everything froze. It looks like there is some threaded +soup service that returned a response on the old context, and since +that never got handled (since that context is now dead) it now doesn't +work. + +To solve this situation we're now iterating the main context until +there are no pending sources before killing the main context. +--- + common/flatpak-utils-private.h | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/common/flatpak-utils-private.h b/common/flatpak-utils-private.h +index 1a921547..84c458f5 100644 +--- a/common/flatpak-utils-private.h ++++ b/common/flatpak-utils-private.h +@@ -679,6 +679,10 @@ flatpak_main_context_pop_default_destroy (void *p) + + if (main_context) + { ++ /* Ensure we don't leave some cleanup callbacks unhandled as we will never iterate this context again. */ ++ while (g_main_context_pending (main_context)) ++ g_main_context_iteration (main_context, TRUE); ++ + g_main_context_pop_thread_default (main_context); + g_main_context_unref (main_context); + } +-- +2.30.2 + diff --git a/io.elementary.code.yml b/io.elementary.code.yml index 29cdbc54c2..fb3e004d3d 100644 --- a/io.elementary.code.yml +++ b/io.elementary.code.yml @@ -25,6 +25,81 @@ cleanup: - '*.a' - '*.la' modules: + - name: intltool + buildsystem: autotools + sources: + - type: archive + url: https://launchpad.net/intltool/trunk/0.51.0/+download/intltool-0.51.0.tar.gz + sha256: 67c74d94196b153b774ab9f89b2fa6c6ba79352407037c8c14d5aeb334e959cd + cleanup: + - '*' + + - name: polkit + config-opts: + - '--disable-polkitd' + - '--disable-man-pages' + - '--disable-introspection' + - '--disable-examples' + - '--disable-gtk-doc' + - '--disable-libelogind' + - '--disable-libsystemd-login' + - '--with-systemdsystemunitdir=no' + - '--with-authdb=dummy' + - '--with-authfw=none' + cleanup: + - '/bin/*' + - '/etc/pam.d' + - '/etc/dbus-1' + - '/share/dbus-1/system-services/*' + - '/share/polkit-1' + - '/lib/polkit-1' + sources: + - type: archive + url: https://www.freedesktop.org/software/polkit/releases/polkit-0.116.tar.gz + sha256: 88170c9e711e8db305a12fdb8234fac5706c61969b94e084d0f117d8ec5d34b1 + - type: patch + path: polkit-build-Add-option-to-build-without-polkitd.patch + - type: file + path: polkit-autogen + dest-filename: autogen.sh + + - name: flatpak + config-opts: + - '--disable-documentation' + - '--disable-seccomp' + - '--disable-sandboxed-triggers' + - '--disable-system-helper' + - '--with-system-install-dir=/var/lib/flatpak' + - '--sysconfdir=/var/run/host/etc' + cleanup: + - '/bin/flatpak-bisect' + - '/bin/flatpak-coredumpctl' + - '/etc/profile.d' + - '/libexec' + - '/lib/systemd' + - '/share/dbus-1/interfaces/org.freedesktop.*' + - '/share/dbus-1/services/org.freedesktop.*' + - '/share/flatpak/triggers' + - '/share/gdm' + - '/share/zsh' + post-install: + - 'cp /usr/bin/update-mime-database /app/bin' + - 'cp /usr/bin/update-desktop-database /app/bin' + sources: + - type: git + url: https://github.com/flatpak/flatpak + tag: '1.10.2' + - type: patch + path: 0001-flatpak-http-utils-push-custom-thread-local-main-context.patch + - type: patch + path: 0002-flatpak-custom-thread-mainloop-finish-pending-sources-when-r.patch + + - name: flatpak-builder + sources: + - type: git + url: https://github.com/flatpak/flatpak-builder + tag: '1.0.12' + - name: gtksourceview buildsystem: meson sources: diff --git a/polkit-autogen b/polkit-autogen new file mode 100755 index 0000000000..3ba457e5a8 --- /dev/null +++ b/polkit-autogen @@ -0,0 +1,4 @@ +#!/bin/sh + +gtkdocize --flavour no-tmpl +autoreconf -if diff --git a/polkit-build-Add-option-to-build-without-polkitd.patch b/polkit-build-Add-option-to-build-without-polkitd.patch new file mode 100644 index 0000000000..9b1a56d8f3 --- /dev/null +++ b/polkit-build-Add-option-to-build-without-polkitd.patch @@ -0,0 +1,131 @@ +From 1073a44277316348d40d86ecec908f1d4812f360 Mon Sep 17 00:00:00 2001 +From: Christian Hergert +Date: Mon, 27 May 2019 11:49:09 -0700 +Subject: [PATCH] flatpak: make polkit suitable for use within flatpak + +This is based on patches from Patrick Griffis with additional fixes +to allow us to disable use of PAM within Flaptak. +--- + configure.ac | 20 ++++++++++++++++---- + src/Makefile.am | 6 +++++- + src/polkitagent/Makefile.am | 5 +++++ + test/Makefile.am | 6 +++++- + 4 files changed, 31 insertions(+), 6 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 5cedb4e..729d78d 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -79,11 +79,13 @@ PKG_CHECK_MODULES(GLIB, [gmodule-2.0 gio-unix-2.0 >= 2.30.0]) + AC_SUBST(GLIB_CFLAGS) + AC_SUBST(GLIB_LIBS) + +-PKG_CHECK_MODULES(LIBJS, [mozjs-60]) ++AS_IF([test x${enable_polkitd} = yes], [ ++ PKG_CHECK_MODULES(LIBJS, [mozjs-60]) + +-AC_SUBST(LIBJS_CFLAGS) +-AC_SUBST(LIBJS_CXXFLAGS) +-AC_SUBST(LIBJS_LIBS) ++ AC_SUBST(LIBJS_CFLAGS) ++ AC_SUBST(LIBJS_CXXFLAGS) ++ AC_SUBST(LIBJS_LIBS) ++]) + + EXPAT_LIB="" + AC_ARG_WITH(expat, [ --with-expat= Use expat from here], +@@ -236,6 +238,15 @@ if test "x$with_systemdsystemunitdir" != "xno"; then + fi + AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$systemdsystemunitdir"]) + ++dnl --------------------------------------------------------------------------- ++dnl - Disable polkitd when using library alone ++dnl --------------------------------------------------------------------------- ++ ++AC_ARG_ENABLE([polkitd], ++ [AS_HELP_STRING([--disable-polkitd], [Do not build polkitd])], ++ [enable_polkitd=$enableval], [enable_polkitd=yes]) ++AM_CONDITIONAL(BUILD_POLKITD, [test x${enable_polkitd} = yes]) ++ + dnl --------------------------------------------------------------------------- + dnl - User for running polkitd + dnl --------------------------------------------------------------------------- +@@ -579,6 +590,7 @@ echo " + Session tracking: ${SESSION_TRACKING} + PAM support: ${have_pam} + systemdsystemunitdir: ${systemdsystemunitdir} ++ polkitd: ${enable_polkitd} + polkitd user: ${POLKITD_USER}" + + if test "$have_pam" = yes ; then +diff --git a/src/Makefile.am b/src/Makefile.am +index 09fc7b3..c6fe91b 100644 +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -1,5 +1,9 @@ + +-SUBDIRS = polkit polkitbackend polkitagent programs ++SUBDIRS = polkit polkitagent programs ++ ++if BUILD_POLKITD ++SUBDIRS += polkitbackend ++endif + + if BUILD_EXAMPLES + SUBDIRS += examples +diff --git a/src/polkitagent/Makefile.am b/src/polkitagent/Makefile.am +index 49720db..633f9d4 100644 +--- a/src/polkitagent/Makefile.am ++++ b/src/polkitagent/Makefile.am +@@ -79,6 +79,7 @@ libpolkit_agent_1_la_LIBADD = \ + + libpolkit_agent_1_la_LDFLAGS = -export-symbols-regex '(^polkit_.*)' + ++if !POLKIT_AUTHFW_NONE + libprivdir = $(prefix)/lib/polkit-1 + libpriv_PROGRAMS = polkit-agent-helper-1 + +@@ -113,6 +114,8 @@ polkit_agent_helper_1_LDFLAGS = \ + $(AM_LDFLAGS) \ + $(NULL) + ++endif # !POLKIT_AUTHFW_NONE ++ + if HAVE_INTROSPECTION + + girdir = $(INTROSPECTION_GIRDIR) +@@ -142,6 +145,7 @@ include $(INTROSPECTION_MAKEFILE) + + endif # HAVE_INTROSPECTION + ++if !POLKIT_AUTHFW_NONE + # polkit-agent-helper-1 need to be setuid root because it's used to + # authenticate not only the invoking user, but possibly also root + # and/or other users. +@@ -149,6 +153,7 @@ endif # HAVE_INTROSPECTION + install-data-hook: + -chown root $(DESTDIR)$(libprivdir)/polkit-agent-helper-1 + -chmod 4755 $(DESTDIR)$(libprivdir)/polkit-agent-helper-1 ++endif # !POLKIT_AUTHFW_NONE + + EXTRA_DIST = polkitagentmarshal.list polkitagentenumtypes.h.template polkitagentenumtypes.c.template + CLEANFILES = $(gir_DATA) $(typelibs_DATA) +diff --git a/test/Makefile.am b/test/Makefile.am +index 59d0680..d43b0fe 100644 +--- a/test/Makefile.am ++++ b/test/Makefile.am +@@ -1,7 +1,11 @@ + +-SUBDIRS = mocklibc . polkit polkitbackend ++SUBDIRS = mocklibc . polkit + AM_CFLAGS = $(GLIB_CFLAGS) + ++if BUILD_POLKITD ++SUBDIRS += polkitbackend ++endif ++ + noinst_LTLIBRARIES = libpolkit-test-helper.la + libpolkit_test_helper_la_SOURCES = polkittesthelper.c polkittesthelper.h + libpolkit_test_helper_la_LIBADD = $(GLIB_LIBS) +-- +2.21.0 From 5473f784da9b5572939400bfd31aebbde9dadd39 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Tue, 20 Jul 2021 19:07:07 +0200 Subject: [PATCH 35/48] Try to package flatpak-builder --- fuse-2.9.2-namespace-conflict-fix.patch | 21 +++ fuse-disable-sys-mount-under-flatpak.patch | 25 ++++ fusermount-wrapper.sh | 9 ++ io.elementary.code.yml | 161 ++++++++++++--------- 4 files changed, 147 insertions(+), 69 deletions(-) create mode 100644 fuse-2.9.2-namespace-conflict-fix.patch create mode 100644 fuse-disable-sys-mount-under-flatpak.patch create mode 100755 fusermount-wrapper.sh diff --git a/fuse-2.9.2-namespace-conflict-fix.patch b/fuse-2.9.2-namespace-conflict-fix.patch new file mode 100644 index 0000000000..ae67e7d45b --- /dev/null +++ b/fuse-2.9.2-namespace-conflict-fix.patch @@ -0,0 +1,21 @@ +diff -up fuse-2.9.2/include/fuse_kernel.h.conflictfix fuse-2.9.2/include/fuse_kernel.h +--- fuse-2.9.2/include/fuse_kernel.h.conflictfix 2013-06-26 09:31:57.862198038 -0400 ++++ fuse-2.9.2/include/fuse_kernel.h 2013-06-26 09:32:19.679198365 -0400 +@@ -88,12 +88,16 @@ + #ifndef _LINUX_FUSE_H + #define _LINUX_FUSE_H + +-#include ++#ifdef __linux__ ++#include ++#else ++#include + #define __u64 uint64_t + #define __s64 int64_t + #define __u32 uint32_t + #define __s32 int32_t + #define __u16 uint16_t ++#endif + + /* + * Version negotiation: diff --git a/fuse-disable-sys-mount-under-flatpak.patch b/fuse-disable-sys-mount-under-flatpak.patch new file mode 100644 index 0000000000..fb5ba22860 --- /dev/null +++ b/fuse-disable-sys-mount-under-flatpak.patch @@ -0,0 +1,25 @@ +From 1ec935f4abecd08957affc7b21bae6bf5be78931 Mon Sep 17 00:00:00 2001 +From: Christian Hergert +Date: Thu, 12 Apr 2018 01:47:57 -0700 +Subject: [PATCH] libfuse: disable sys mount under flatpak + +--- + lib/mount.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/lib/mount.c b/lib/mount.c +index 7a18c11..1667db2 100644 +--- a/lib/mount.c ++++ b/lib/mount.c +@@ -392,6 +392,9 @@ static int fuse_mount_sys(const char *mnt, struct mount_opts *mo, + int fd; + int res; + ++ /* disable in flatpak */ ++ return -2; ++ + if (!mnt) { + fprintf(stderr, "fuse: missing mountpoint parameter\n"); + return -1; +-- +2.17.0.rc2 diff --git a/fusermount-wrapper.sh b/fusermount-wrapper.sh new file mode 100755 index 0000000000..24bfa9dac7 --- /dev/null +++ b/fusermount-wrapper.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ -z "$_FUSE_COMMFD" ]; then + FD_ARGS= +else + FD_ARGS="--env=_FUSE_COMMFD=${_FUSE_COMMFD} --forward-fd=${_FUSE_COMMFD}" +fi + +exec flatpak-spawn --host --forward-fd=1 --forward-fd=2 --forward-fd=3 $FD_ARGS fusermount "$@" diff --git a/io.elementary.code.yml b/io.elementary.code.yml index fb3e004d3d..65a9a4e7de 100644 --- a/io.elementary.code.yml +++ b/io.elementary.code.yml @@ -5,14 +5,18 @@ sdk: io.elementary.Sdk command: io.elementary.code finish-args: - '--filesystem=host' + - '--filesystem=/var/lib/flatpak' + - '--filesystem=~/.local/share/flatpak' - '--share=ipc' + - '--share=network' - '--socket=fallback-x11' - '--socket=wayland' - '--talk-name=org.gtk.vfs.*' - '--talk-name=org.gnome.SettingsDaemon' - '--talk-name=org.elementary.Contractor' + - '--talk-name=org.freedesktop.Flatpak' - '--metadata=X-DConf=migrate-path=/io/elementary/code/' cleanup: @@ -25,80 +29,99 @@ cleanup: - '*.a' - '*.la' modules: - - name: intltool - buildsystem: autotools - sources: - - type: archive - url: https://launchpad.net/intltool/trunk/0.51.0/+download/intltool-0.51.0.tar.gz - sha256: 67c74d94196b153b774ab9f89b2fa6c6ba79352407037c8c14d5aeb334e959cd - cleanup: - - '*' - - - name: polkit - config-opts: - - '--disable-polkitd' - - '--disable-man-pages' - - '--disable-introspection' - - '--disable-examples' - - '--disable-gtk-doc' - - '--disable-libelogind' - - '--disable-libsystemd-login' - - '--with-systemdsystemunitdir=no' - - '--with-authdb=dummy' - - '--with-authfw=none' - cleanup: - - '/bin/*' - - '/etc/pam.d' - - '/etc/dbus-1' - - '/share/dbus-1/system-services/*' - - '/share/polkit-1' - - '/lib/polkit-1' - sources: - - type: archive - url: https://www.freedesktop.org/software/polkit/releases/polkit-0.116.tar.gz - sha256: 88170c9e711e8db305a12fdb8234fac5706c61969b94e084d0f117d8ec5d34b1 - - type: patch - path: polkit-build-Add-option-to-build-without-polkitd.patch - - type: file - path: polkit-autogen - dest-filename: autogen.sh - - - name: flatpak - config-opts: - - '--disable-documentation' - - '--disable-seccomp' - - '--disable-sandboxed-triggers' - - '--disable-system-helper' - - '--with-system-install-dir=/var/lib/flatpak' - - '--sysconfdir=/var/run/host/etc' - cleanup: - - '/bin/flatpak-bisect' - - '/bin/flatpak-coredumpctl' - - '/etc/profile.d' - - '/libexec' - - '/lib/systemd' - - '/share/dbus-1/interfaces/org.freedesktop.*' - - '/share/dbus-1/services/org.freedesktop.*' - - '/share/flatpak/triggers' - - '/share/gdm' - - '/share/zsh' - post-install: - - 'cp /usr/bin/update-mime-database /app/bin' - - 'cp /usr/bin/update-desktop-database /app/bin' - sources: - - type: git - url: https://github.com/flatpak/flatpak - tag: '1.10.2' - - type: patch - path: 0001-flatpak-http-utils-push-custom-thread-local-main-context.patch - - type: patch - path: 0002-flatpak-custom-thread-mainloop-finish-pending-sources-when-r.patch - - name: flatpak-builder sources: - type: git url: https://github.com/flatpak/flatpak-builder tag: '1.0.12' + modules: + - name: flatpak + config-opts: + - '--disable-documentation' + - '--disable-seccomp' + - '--disable-sandboxed-triggers' + - '--disable-system-helper' + - '--with-system-install-dir=/var/lib/flatpak' + - '--sysconfdir=/var/run/host/etc' + cleanup: + - '/bin/flatpak-bisect' + - '/bin/flatpak-coredumpctl' + - '/etc/profile.d' + - '/libexec' + - '/lib/systemd' + - '/share/dbus-1/interfaces/org.freedesktop.*' + - '/share/dbus-1/services/org.freedesktop.*' + - '/share/flatpak/triggers' + - '/share/gdm' + - '/share/zsh' + post-install: + - 'cp /usr/bin/update-mime-database /app/bin' + - 'cp /usr/bin/update-desktop-database /app/bin' + sources: + - type: git + url: https://github.com/flatpak/flatpak + tag: '1.10.2' + - type: patch + path: 0001-flatpak-http-utils-push-custom-thread-local-main-context.patch + - type: patch + path: 0002-flatpak-custom-thread-mainloop-finish-pending-sources-when-r.patch + modules: + - name: libfuse + config-opts: + - 'UDEV_RULES_PATH=/app/etc/udev/rules.d' + - 'INIT_D_PATH=/app/etc/init.d' + cleanup: + - '/bin/ulockmgr_server' + post-install: + - 'install -m a+rx fusermount-wrapper.sh /app/bin/fusermount' + sources: + - type: archive + url: https://github.com/libfuse/libfuse/releases/download/fuse-2.9.9/fuse-2.9.9.tar.gz + sha256: d0e69d5d608cc22ff4843791ad097f554dd32540ddc9bed7638cc6fea7c1b4b5 + - type: patch + path: fuse-2.9.2-namespace-conflict-fix.patch + - type: patch + path: fuse-disable-sys-mount-under-flatpak.patch + - type: file + path: fusermount-wrapper.sh + - name: polkit + config-opts: + - '--disable-polkitd' + - '--disable-man-pages' + - '--disable-introspection' + - '--disable-examples' + - '--disable-gtk-doc' + - '--disable-libelogind' + - '--disable-libsystemd-login' + - '--with-systemdsystemunitdir=no' + - '--with-authdb=dummy' + - '--with-authfw=none' + rm-configure: true + cleanup: + - '/bin/*' + - '/etc/pam.d' + - '/etc/dbus-1' + - '/share/dbus-1/system-services/*' + - '/share/polkit-1' + - '/lib/polkit-1' + sources: + - type: archive + url: https://www.freedesktop.org/software/polkit/releases/polkit-0.116.tar.gz + sha256: 88170c9e711e8db305a12fdb8234fac5706c61969b94e084d0f117d8ec5d34b1 + - type: patch + path: polkit-build-Add-option-to-build-without-polkitd.patch + - type: file + path: polkit-autogen + dest-filename: autogen.sh + modules: + - name: intltool + buildsystem: autotools + sources: + - type: archive + url: https://launchpad.net/intltool/trunk/0.51.0/+download/intltool-0.51.0.tar.gz + sha256: 67c74d94196b153b774ab9f89b2fa6c6ba79352407037c8c14d5aeb334e959cd + cleanup: + - '*' - name: gtksourceview buildsystem: meson From 5f9c6fcb4e25ef9f17f67caa20bdceb484e9d60c Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Tue, 20 Jul 2021 19:13:40 +0200 Subject: [PATCH 36/48] Add ostree --- io.elementary.code.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/io.elementary.code.yml b/io.elementary.code.yml index 65a9a4e7de..2d671a9dac 100644 --- a/io.elementary.code.yml +++ b/io.elementary.code.yml @@ -84,6 +84,20 @@ modules: path: fuse-disable-sys-mount-under-flatpak.patch - type: file path: fusermount-wrapper.sh + - name: ostree + config-opts: + - '--disable-man' + - '--without-libsystemd' + cleanup: + - '/bin' + - '/etc/grub.d' + - '/etc/ostree' + - '/share/ostree' + - '/libexec' + sources: + - type: git + url: https://github.com/ostreedev/ostree.git + branch: v2021.1 - name: polkit config-opts: - '--disable-polkitd' From cbc9bccfac4fb521df9ea782591ac09157f6722f Mon Sep 17 00:00:00 2001 From: Marukesu Date: Tue, 17 Aug 2021 17:31:00 -0300 Subject: [PATCH 37/48] update manifest * update Flatpak and remove patches * update flatpak-builder * add pyparsing * remove polkit --- ...ush-custom-thread-local-main-context.patch | 59 ------ ...inloop-finish-pending-sources-when-r.patch | 44 ---- .../fuse-2.9.2-namespace-conflict-fix.patch | 0 ...fuse-disable-sys-mount-under-flatpak.patch | 0 .../fusermount-wrapper.sh | 0 io.elementary.code.yml | 199 ++++++++---------- polkit-autogen | 4 - ...-Add-option-to-build-without-polkitd.patch | 131 ------------ 8 files changed, 90 insertions(+), 347 deletions(-) delete mode 100644 0001-flatpak-http-utils-push-custom-thread-local-main-context.patch delete mode 100644 0002-flatpak-custom-thread-mainloop-finish-pending-sources-when-r.patch rename fuse-2.9.2-namespace-conflict-fix.patch => flatpak/fuse-2.9.2-namespace-conflict-fix.patch (100%) rename fuse-disable-sys-mount-under-flatpak.patch => flatpak/fuse-disable-sys-mount-under-flatpak.patch (100%) rename fusermount-wrapper.sh => flatpak/fusermount-wrapper.sh (100%) delete mode 100755 polkit-autogen delete mode 100644 polkit-build-Add-option-to-build-without-polkitd.patch diff --git a/0001-flatpak-http-utils-push-custom-thread-local-main-context.patch b/0001-flatpak-http-utils-push-custom-thread-local-main-context.patch deleted file mode 100644 index e7975706b3..0000000000 --- a/0001-flatpak-http-utils-push-custom-thread-local-main-context.patch +++ /dev/null @@ -1,59 +0,0 @@ -From 1b130c5cc36ce522e367e133fd53ea428133a37c Mon Sep 17 00:00:00 2001 -From: Alexander Larsson -Date: Thu, 18 Mar 2021 10:14:30 +0100 -Subject: [PATCH 1/2] http utils: push custom thread local main context - -We're calling async soup APIs with SOUP_SESSION_USE_THREAD_CONTEXT -set, which means that libsoup async APIs will run async callbacks on -the loop of the thread-default main context. We then manually spin -this main context, because we're supposed to look like a sync call and -the async stuff is just internally. - -This is not really right, because normally there isn't any custom -mainloop context registred, which means we're spinning the main thread -context on some other thread, as well as queuing soup sorces on -it. This can't be any good! - -Rather than doing this we actually create and push our own main -context that we then spin isolated from the default mainloop. ---- - common/flatpak-utils-http.c | 9 +++++++++ - 1 file changed, 9 insertions(+) - -diff --git a/common/flatpak-utils-http.c b/common/flatpak-utils-http.c -index ffe1b476..3d144051 100644 ---- a/common/flatpak-utils-http.c -+++ b/common/flatpak-utils-http.c -@@ -670,6 +670,9 @@ flatpak_load_uri (SoupSession *soup_session, - { - g_autoptr(GError) local_error = NULL; - guint n_retries_remaining = DEFAULT_N_NETWORK_RETRIES; -+ g_autoptr(GMainContextPopDefault) main_context = NULL; -+ -+ main_context = flatpak_main_context_new_default (); - - /* Ensure we handle file: uris always */ - if (g_ascii_strncasecmp (uri, "file:", 5) == 0) -@@ -788,6 +791,9 @@ flatpak_download_http_uri (SoupSession *soup_session, - { - g_autoptr(GError) local_error = NULL; - guint n_retries_remaining = DEFAULT_N_NETWORK_RETRIES; -+ g_autoptr(GMainContextPopDefault) main_context = NULL; -+ -+ main_context = flatpak_main_context_new_default (); - - do - { -@@ -1032,6 +1038,9 @@ flatpak_cache_http_uri (SoupSession *soup_session, - { - g_autoptr(GError) local_error = NULL; - guint n_retries_remaining = DEFAULT_N_NETWORK_RETRIES; -+ g_autoptr(GMainContextPopDefault) main_context = NULL; -+ -+ main_context = flatpak_main_context_new_default (); - - do - { --- -2.30.2 - diff --git a/0002-flatpak-custom-thread-mainloop-finish-pending-sources-when-r.patch b/0002-flatpak-custom-thread-mainloop-finish-pending-sources-when-r.patch deleted file mode 100644 index 8571e29905..0000000000 --- a/0002-flatpak-custom-thread-mainloop-finish-pending-sources-when-r.patch +++ /dev/null @@ -1,44 +0,0 @@ -From adfa816cd498597abde24a9e13df34fe30ac976e Mon Sep 17 00:00:00 2001 -From: Alexander Larsson -Date: Thu, 18 Mar 2021 10:20:27 +0100 -Subject: [PATCH 2/2] custom thread mainloop: finish pending sources when - removing - -We sometimes set a custom per-thread mainloop because and then spin it -manually to fake a sync call on a thread using async calls. Primarily -this happens with the soup streaming calls. In this case, eventually -we finish the main loop iteration (because, say, the download is done) -so we stop iterating the mainloop and return from the fake sync code. - -However, that might not necessarily be the only thing queued on the -main context. I ran into a situation where it seems like libsoup did -some call to a thread-pool during the async call, and the next time i -used soup aync everything froze. It looks like there is some threaded -soup service that returned a response on the old context, and since -that never got handled (since that context is now dead) it now doesn't -work. - -To solve this situation we're now iterating the main context until -there are no pending sources before killing the main context. ---- - common/flatpak-utils-private.h | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/common/flatpak-utils-private.h b/common/flatpak-utils-private.h -index 1a921547..84c458f5 100644 ---- a/common/flatpak-utils-private.h -+++ b/common/flatpak-utils-private.h -@@ -679,6 +679,10 @@ flatpak_main_context_pop_default_destroy (void *p) - - if (main_context) - { -+ /* Ensure we don't leave some cleanup callbacks unhandled as we will never iterate this context again. */ -+ while (g_main_context_pending (main_context)) -+ g_main_context_iteration (main_context, TRUE); -+ - g_main_context_pop_thread_default (main_context); - g_main_context_unref (main_context); - } --- -2.30.2 - diff --git a/fuse-2.9.2-namespace-conflict-fix.patch b/flatpak/fuse-2.9.2-namespace-conflict-fix.patch similarity index 100% rename from fuse-2.9.2-namespace-conflict-fix.patch rename to flatpak/fuse-2.9.2-namespace-conflict-fix.patch diff --git a/fuse-disable-sys-mount-under-flatpak.patch b/flatpak/fuse-disable-sys-mount-under-flatpak.patch similarity index 100% rename from fuse-disable-sys-mount-under-flatpak.patch rename to flatpak/fuse-disable-sys-mount-under-flatpak.patch diff --git a/fusermount-wrapper.sh b/flatpak/fusermount-wrapper.sh similarity index 100% rename from fusermount-wrapper.sh rename to flatpak/fusermount-wrapper.sh diff --git a/io.elementary.code.yml b/io.elementary.code.yml index 2d671a9dac..447366c5de 100644 --- a/io.elementary.code.yml +++ b/io.elementary.code.yml @@ -4,7 +4,10 @@ runtime-version: 'daily' sdk: io.elementary.Sdk command: io.elementary.code finish-args: + - '--require-version=1.0.0' - '--filesystem=host' + + # flatpak access - '--filesystem=/var/lib/flatpak' - '--filesystem=~/.local/share/flatpak' @@ -12,6 +15,7 @@ finish-args: - '--share=network' - '--socket=fallback-x11' - '--socket=wayland' + - '--allow=devel' - '--talk-name=org.gtk.vfs.*' - '--talk-name=org.gnome.SettingsDaemon' @@ -19,124 +23,21 @@ finish-args: - '--talk-name=org.freedesktop.Flatpak' - '--metadata=X-DConf=migrate-path=/io/elementary/code/' +build-options: + env: + MOUNT_FUSE_PATH: ../tmp/ + V: '1' cleanup: - '/include' - '/lib/pkgconfig' - '/lib/cmake' - '/lib/girepository-1.0' - '/share/gir-1.0' + - '/share/man' - '/share/vala' - '*.a' - '*.la' modules: - - name: flatpak-builder - sources: - - type: git - url: https://github.com/flatpak/flatpak-builder - tag: '1.0.12' - modules: - - name: flatpak - config-opts: - - '--disable-documentation' - - '--disable-seccomp' - - '--disable-sandboxed-triggers' - - '--disable-system-helper' - - '--with-system-install-dir=/var/lib/flatpak' - - '--sysconfdir=/var/run/host/etc' - cleanup: - - '/bin/flatpak-bisect' - - '/bin/flatpak-coredumpctl' - - '/etc/profile.d' - - '/libexec' - - '/lib/systemd' - - '/share/dbus-1/interfaces/org.freedesktop.*' - - '/share/dbus-1/services/org.freedesktop.*' - - '/share/flatpak/triggers' - - '/share/gdm' - - '/share/zsh' - post-install: - - 'cp /usr/bin/update-mime-database /app/bin' - - 'cp /usr/bin/update-desktop-database /app/bin' - sources: - - type: git - url: https://github.com/flatpak/flatpak - tag: '1.10.2' - - type: patch - path: 0001-flatpak-http-utils-push-custom-thread-local-main-context.patch - - type: patch - path: 0002-flatpak-custom-thread-mainloop-finish-pending-sources-when-r.patch - modules: - - name: libfuse - config-opts: - - 'UDEV_RULES_PATH=/app/etc/udev/rules.d' - - 'INIT_D_PATH=/app/etc/init.d' - cleanup: - - '/bin/ulockmgr_server' - post-install: - - 'install -m a+rx fusermount-wrapper.sh /app/bin/fusermount' - sources: - - type: archive - url: https://github.com/libfuse/libfuse/releases/download/fuse-2.9.9/fuse-2.9.9.tar.gz - sha256: d0e69d5d608cc22ff4843791ad097f554dd32540ddc9bed7638cc6fea7c1b4b5 - - type: patch - path: fuse-2.9.2-namespace-conflict-fix.patch - - type: patch - path: fuse-disable-sys-mount-under-flatpak.patch - - type: file - path: fusermount-wrapper.sh - - name: ostree - config-opts: - - '--disable-man' - - '--without-libsystemd' - cleanup: - - '/bin' - - '/etc/grub.d' - - '/etc/ostree' - - '/share/ostree' - - '/libexec' - sources: - - type: git - url: https://github.com/ostreedev/ostree.git - branch: v2021.1 - - name: polkit - config-opts: - - '--disable-polkitd' - - '--disable-man-pages' - - '--disable-introspection' - - '--disable-examples' - - '--disable-gtk-doc' - - '--disable-libelogind' - - '--disable-libsystemd-login' - - '--with-systemdsystemunitdir=no' - - '--with-authdb=dummy' - - '--with-authfw=none' - rm-configure: true - cleanup: - - '/bin/*' - - '/etc/pam.d' - - '/etc/dbus-1' - - '/share/dbus-1/system-services/*' - - '/share/polkit-1' - - '/lib/polkit-1' - sources: - - type: archive - url: https://www.freedesktop.org/software/polkit/releases/polkit-0.116.tar.gz - sha256: 88170c9e711e8db305a12fdb8234fac5706c61969b94e084d0f117d8ec5d34b1 - - type: patch - path: polkit-build-Add-option-to-build-without-polkitd.patch - - type: file - path: polkit-autogen - dest-filename: autogen.sh - modules: - - name: intltool - buildsystem: autotools - sources: - - type: archive - url: https://launchpad.net/intltool/trunk/0.51.0/+download/intltool-0.51.0.tar.gz - sha256: 67c74d94196b153b774ab9f89b2fa6c6ba79352407037c8c14d5aeb334e959cd - cleanup: - - '*' - - name: gtksourceview buildsystem: meson sources: @@ -173,7 +74,6 @@ modules: - '-DBUILD_TESTING:BOOL=OFF' - '-DCMAKE_INSTALL_LIBDIR:PATH=/app/lib' cleanup: - - '/share/man' - '/share/doc' sources: - type: git @@ -231,6 +131,87 @@ modules: url: https://github.com/universal-ctags/ctags.git tag: p5.9.20201101.0 + - name: flatpak + config-opts: + - '--disable-documentation' + - '--disable-seccomp' + - '--disable-sandboxed-triggers' + - '--disable-system-helper' + - '--with-system-install-dir=/var/lib/flatpak' + - '--sysconfdir=/var/run/host/etc' + cleanup: + - '/bin/flatpak-bisect' + - '/bin/flatpak-coredumpctl' + - '/etc/profile.d' + - '/libexec' + - '/lib/systemd' + - '/share/dbus-1/interfaces/org.freedesktop.*' + - '/share/dbus-1/services/org.freedesktop.*' + - '/share/fish' + - '/share/flatpak/triggers' + - '/share/gdm' + - '/share/zsh' + post-install: + - 'cp /usr/bin/update-mime-database /app/bin' + - 'cp /usr/bin/update-desktop-database /app/bin' + sources: + - type: git + url: https://github.com/flatpak/flatpak + tag: '1.11.2' + modules: + - name: libfuse + config-opts: + - 'UDEV_RULES_PATH=/app/etc/udev/rules.d' + - 'INIT_D_PATH=/app/etc/init.d' + cleanup: + - '/bin/ulockmgr_server' + post-install: + - 'install -m a+rx fusermount-wrapper.sh /app/bin/fusermount' + sources: + - type: archive + url: https://github.com/libfuse/libfuse/releases/download/fuse-2.9.9/fuse-2.9.9.tar.gz + sha256: d0e69d5d608cc22ff4843791ad097f554dd32540ddc9bed7638cc6fea7c1b4b5 + - type: patch + path: flatpak/fuse-2.9.2-namespace-conflict-fix.patch + - type: patch + path: flatpak/fuse-disable-sys-mount-under-flatpak.patch + - type: file + path: flatpak/fusermount-wrapper.sh + - name: ostree + config-opts: + - '--disable-man' + - '--without-libsystemd' + cleanup: + - /bin + - /etc/grub.d + - /etc/ostree + - /libexec + - /share/ostree + sources: + - type: git + url: https://github.com/ostreedev/ostree + branch: v2021.1 + - name: pyparsing + buildsystem: simple + build-commands: + - 'pip3 install --no-index --find-links="file://${PWD}" --prefix=${FLATPAK_DEST} pyparsing' + sources: + - type: file + url: https://files.pythonhosted.org/packages/b9/b8/6b32b3e84014148dcd60dd05795e35c2e7f4b72f918616c61fdce83d27fc/pyparsing-2.3.1.tar.gz + sha256: 66c9268862641abcac4a96ba74506e594c884e3f57690a696d21ad8210ed667a + + - name: flatpak-builder + sources: + - type: git + url: https://github.com/flatpak/flatpak-builder + tag: '1.0.14' + modules: + - name: yaml + sources: + - type: git + url: https://github.com/yaml/libyaml + tag: '0.2.5' + - name: code buildsystem: meson config-opts: diff --git a/polkit-autogen b/polkit-autogen deleted file mode 100755 index 3ba457e5a8..0000000000 --- a/polkit-autogen +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -gtkdocize --flavour no-tmpl -autoreconf -if diff --git a/polkit-build-Add-option-to-build-without-polkitd.patch b/polkit-build-Add-option-to-build-without-polkitd.patch deleted file mode 100644 index 9b1a56d8f3..0000000000 --- a/polkit-build-Add-option-to-build-without-polkitd.patch +++ /dev/null @@ -1,131 +0,0 @@ -From 1073a44277316348d40d86ecec908f1d4812f360 Mon Sep 17 00:00:00 2001 -From: Christian Hergert -Date: Mon, 27 May 2019 11:49:09 -0700 -Subject: [PATCH] flatpak: make polkit suitable for use within flatpak - -This is based on patches from Patrick Griffis with additional fixes -to allow us to disable use of PAM within Flaptak. ---- - configure.ac | 20 ++++++++++++++++---- - src/Makefile.am | 6 +++++- - src/polkitagent/Makefile.am | 5 +++++ - test/Makefile.am | 6 +++++- - 4 files changed, 31 insertions(+), 6 deletions(-) - -diff --git a/configure.ac b/configure.ac -index 5cedb4e..729d78d 100644 ---- a/configure.ac -+++ b/configure.ac -@@ -79,11 +79,13 @@ PKG_CHECK_MODULES(GLIB, [gmodule-2.0 gio-unix-2.0 >= 2.30.0]) - AC_SUBST(GLIB_CFLAGS) - AC_SUBST(GLIB_LIBS) - --PKG_CHECK_MODULES(LIBJS, [mozjs-60]) -+AS_IF([test x${enable_polkitd} = yes], [ -+ PKG_CHECK_MODULES(LIBJS, [mozjs-60]) - --AC_SUBST(LIBJS_CFLAGS) --AC_SUBST(LIBJS_CXXFLAGS) --AC_SUBST(LIBJS_LIBS) -+ AC_SUBST(LIBJS_CFLAGS) -+ AC_SUBST(LIBJS_CXXFLAGS) -+ AC_SUBST(LIBJS_LIBS) -+]) - - EXPAT_LIB="" - AC_ARG_WITH(expat, [ --with-expat= Use expat from here], -@@ -236,6 +238,15 @@ if test "x$with_systemdsystemunitdir" != "xno"; then - fi - AM_CONDITIONAL(HAVE_SYSTEMD, [test -n "$systemdsystemunitdir"]) - -+dnl --------------------------------------------------------------------------- -+dnl - Disable polkitd when using library alone -+dnl --------------------------------------------------------------------------- -+ -+AC_ARG_ENABLE([polkitd], -+ [AS_HELP_STRING([--disable-polkitd], [Do not build polkitd])], -+ [enable_polkitd=$enableval], [enable_polkitd=yes]) -+AM_CONDITIONAL(BUILD_POLKITD, [test x${enable_polkitd} = yes]) -+ - dnl --------------------------------------------------------------------------- - dnl - User for running polkitd - dnl --------------------------------------------------------------------------- -@@ -579,6 +590,7 @@ echo " - Session tracking: ${SESSION_TRACKING} - PAM support: ${have_pam} - systemdsystemunitdir: ${systemdsystemunitdir} -+ polkitd: ${enable_polkitd} - polkitd user: ${POLKITD_USER}" - - if test "$have_pam" = yes ; then -diff --git a/src/Makefile.am b/src/Makefile.am -index 09fc7b3..c6fe91b 100644 ---- a/src/Makefile.am -+++ b/src/Makefile.am -@@ -1,5 +1,9 @@ - --SUBDIRS = polkit polkitbackend polkitagent programs -+SUBDIRS = polkit polkitagent programs -+ -+if BUILD_POLKITD -+SUBDIRS += polkitbackend -+endif - - if BUILD_EXAMPLES - SUBDIRS += examples -diff --git a/src/polkitagent/Makefile.am b/src/polkitagent/Makefile.am -index 49720db..633f9d4 100644 ---- a/src/polkitagent/Makefile.am -+++ b/src/polkitagent/Makefile.am -@@ -79,6 +79,7 @@ libpolkit_agent_1_la_LIBADD = \ - - libpolkit_agent_1_la_LDFLAGS = -export-symbols-regex '(^polkit_.*)' - -+if !POLKIT_AUTHFW_NONE - libprivdir = $(prefix)/lib/polkit-1 - libpriv_PROGRAMS = polkit-agent-helper-1 - -@@ -113,6 +114,8 @@ polkit_agent_helper_1_LDFLAGS = \ - $(AM_LDFLAGS) \ - $(NULL) - -+endif # !POLKIT_AUTHFW_NONE -+ - if HAVE_INTROSPECTION - - girdir = $(INTROSPECTION_GIRDIR) -@@ -142,6 +145,7 @@ include $(INTROSPECTION_MAKEFILE) - - endif # HAVE_INTROSPECTION - -+if !POLKIT_AUTHFW_NONE - # polkit-agent-helper-1 need to be setuid root because it's used to - # authenticate not only the invoking user, but possibly also root - # and/or other users. -@@ -149,6 +153,7 @@ endif # HAVE_INTROSPECTION - install-data-hook: - -chown root $(DESTDIR)$(libprivdir)/polkit-agent-helper-1 - -chmod 4755 $(DESTDIR)$(libprivdir)/polkit-agent-helper-1 -+endif # !POLKIT_AUTHFW_NONE - - EXTRA_DIST = polkitagentmarshal.list polkitagentenumtypes.h.template polkitagentenumtypes.c.template - CLEANFILES = $(gir_DATA) $(typelibs_DATA) -diff --git a/test/Makefile.am b/test/Makefile.am -index 59d0680..d43b0fe 100644 ---- a/test/Makefile.am -+++ b/test/Makefile.am -@@ -1,7 +1,11 @@ - --SUBDIRS = mocklibc . polkit polkitbackend -+SUBDIRS = mocklibc . polkit - AM_CFLAGS = $(GLIB_CFLAGS) - -+if BUILD_POLKITD -+SUBDIRS += polkitbackend -+endif -+ - noinst_LTLIBRARIES = libpolkit-test-helper.la - libpolkit_test_helper_la_SOURCES = polkittesthelper.c polkittesthelper.h - libpolkit_test_helper_la_LIBADD = $(GLIB_LIBS) --- -2.21.0 From 78f461aa76c2a4eede316434afed5fc5be3da76c Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Thu, 14 Oct 2021 09:53:50 +0200 Subject: [PATCH 38/48] Check if dependencies are installed and if running flatpaked --- src/MainWindow.vala | 7 ++- src/Services/ProjectManager.vala | 99 +++++++++++++++++++++++++++----- 2 files changed, 89 insertions(+), 17 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 68bed3fb02..a814582b2b 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -582,12 +582,13 @@ namespace Scratch { } private void set_build_run_widgets_sensitive () { + bool has_dependencies_installed = project_manager.has_dependencies_installed; bool is_project_selected = (project_manager.project_path != null) && (project_manager.get_flatpak_manifest () != null); bool is_running = project_manager.is_running; - Utils.action_from_group (ACTION_BUILD, actions).set_enabled (is_project_selected && !is_running); - Utils.action_from_group (ACTION_RUN, actions).set_enabled (is_project_selected && !is_running); - Utils.action_from_group (ACTION_STOP, actions).set_enabled (is_project_selected && is_running); + Utils.action_from_group (ACTION_BUILD, actions).set_enabled (has_dependencies_installed && is_project_selected && !is_running); + Utils.action_from_group (ACTION_RUN, actions).set_enabled (has_dependencies_installed && is_project_selected && !is_running); + Utils.action_from_group (ACTION_STOP, actions).set_enabled (has_dependencies_installed && is_project_selected && is_running); if (is_project_selected) { var project_name = Path.get_basename (project_manager.project_path); diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 693e30f968..610eb70741 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -29,6 +29,30 @@ public class Scratch.Services.ProjectManager : Object { public bool is_running { get; set; } public bool was_stopped { get; set; } + public bool is_running_flatpaked { + private get { + return FileUtils.test ("/.flatpak-info", FileTest.IS_REGULAR); + } + } + + public bool has_dependencies_installed { + get { + if (is_running_flatpaked) { + return run_command_sync ({ + "flatpak-spawn", + "--host", + "flatpak-builder", + "--version" + }); + } else { + return run_command_sync ({ + "flatpak-builder", + "--version" + }); + } + } + } + public signal void on_standard_output (string line); public signal void on_standard_error (string line); public signal void on_clear (); @@ -139,7 +163,7 @@ public class Scratch.Services.ProjectManager : Object { return true; } - private async bool run_command (string[] cmd) { + private async bool run_command_async (string[] cmd) { MainLoop loop = new MainLoop (); bool exit_status = false; @@ -192,15 +216,50 @@ public class Scratch.Services.ProjectManager : Object { } } + private bool run_command_sync (string[] cmd) { + try { + string[] spawn_args = cmd; + string[] spawn_env = Environ.get (); + + int status; + + Process.spawn_sync (project_path, + spawn_args, + spawn_env, + SpawnFlags.SEARCH_PATH, + null, + null, + null, + out status); + + return status == 0; + } catch (SpawnError e) { + print ("Error: %s\n", e.message); + } + + return false; + } + private async bool build_project () { var flatpak_manifest = get_flatpak_manifest (); if (flatpak_manifest != null) { - return yield run_command ({ - "flatpak-builder", - "--force-clean", - flatpak_manifest.build_dir, - flatpak_manifest.manifest - }); + if (is_running_flatpaked) { + return yield run_command_async ({ + "flatpak-spawn", + "--host", + "flatpak-builder", + "--force-clean", + flatpak_manifest.build_dir, + flatpak_manifest.manifest + }); + } else { + return yield run_command_async ({ + "flatpak-builder", + "--force-clean", + flatpak_manifest.build_dir, + flatpak_manifest.manifest + }); + } } return false; @@ -209,13 +268,25 @@ public class Scratch.Services.ProjectManager : Object { private async bool run_project () { var flatpak_manifest = get_flatpak_manifest (); if (flatpak_manifest != null) { - return yield run_command ({ - "flatpak-builder", - "--run", - flatpak_manifest.build_dir, - flatpak_manifest.manifest, - flatpak_manifest.command - }); + if (is_running_flatpaked) { + return yield run_command_async ({ + "flatpak-spawn", + "--host", + "flatpak-builder", + "--run", + flatpak_manifest.build_dir, + flatpak_manifest.manifest, + flatpak_manifest.command + }); + } else { + return yield run_command_async ({ + "flatpak-builder", + "--run", + flatpak_manifest.build_dir, + flatpak_manifest.manifest, + flatpak_manifest.command + }); + } } return false; From 830fd5391fb069d857cc09f252e5035b10bf44a7 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Thu, 14 Oct 2021 09:55:38 +0200 Subject: [PATCH 39/48] Satisfy linter --- src/Services/ProjectManager.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 610eb70741..6ca6c9bc72 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -222,7 +222,7 @@ public class Scratch.Services.ProjectManager : Object { string[] spawn_env = Environ.get (); int status; - + Process.spawn_sync (project_path, spawn_args, spawn_env, @@ -231,7 +231,7 @@ public class Scratch.Services.ProjectManager : Object { null, null, out status); - + return status == 0; } catch (SpawnError e) { print ("Error: %s\n", e.message); From 6c1eaae405f39d8e761cd8d4dc9565206bcce9b7 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Thu, 14 Oct 2021 13:27:41 +0200 Subject: [PATCH 40/48] ChooseProjectButton: Set path for ProjectManager --- src/MainWindow.vala | 2 +- src/Services/ProjectManager.vala | 10 ++++++++++ src/Widgets/ChooseProjectButton.vala | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index a814582b2b..1f8e1d84a9 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -272,7 +272,7 @@ namespace Scratch { // Show/Hide widgets show_all (); - project_manager = new Services.ProjectManager (); + project_manager = Services.ProjectManager.get_instance (); project_output = new Gee.ArrayList (); project_manager.on_standard_output.connect ((line) => { diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 6ca6c9bc72..dd22c58ba7 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -57,8 +57,18 @@ public class Scratch.Services.ProjectManager : Object { public signal void on_standard_error (string line); public signal void on_clear (); + static ProjectManager? instance; + private Pid command_pid; + public static ProjectManager get_instance () { + if (instance == null) { + instance = new ProjectManager (); + } + + return instance; + } + public FlatpakManifest? get_flatpak_manifest () { Dir dir; try { diff --git a/src/Widgets/ChooseProjectButton.vala b/src/Widgets/ChooseProjectButton.vala index 4b4759ecdf..f2b260d903 100644 --- a/src/Widgets/ChooseProjectButton.vala +++ b/src/Widgets/ChooseProjectButton.vala @@ -99,6 +99,7 @@ public class Code.ChooseProjectButton : Gtk.MenuButton { label_widget.label = _(NO_PROJECT_SELECTED); label_widget.tooltip_text = _("Active Git project: %s").printf (_(NO_PROJECT_SELECTED)); Scratch.Services.GitManager.get_instance ().active_project_path = ""; + Scratch.Services.ProjectManager.get_instance ().project_path = null; } }); @@ -137,6 +138,7 @@ public class Code.ChooseProjectButton : Gtk.MenuButton { label_widget.tooltip_text = _("Active Git project: %s").printf (project_entry.project_path); project_entry.active = true; Scratch.Services.GitManager.get_instance ().active_project_path = project_entry.project_path; + Scratch.Services.ProjectManager.get_instance ().project_path = project_entry.project_path; } public void set_document (Scratch.Services.Document doc) { From 7c3d7dc20d2f69799e4dd54cb68a1ccbf8031806 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 16 Oct 2021 06:58:32 +0200 Subject: [PATCH 41/48] ProjectManager: Refactor access to is_running_flatpaked --- src/Services/ProjectManager.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index dd22c58ba7..664404e058 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -30,7 +30,7 @@ public class Scratch.Services.ProjectManager : Object { public bool was_stopped { get; set; } public bool is_running_flatpaked { - private get { + get { return FileUtils.test ("/.flatpak-info", FileTest.IS_REGULAR); } } From 4f4c6677930ccc0bd176942556a4ffbcf40e1341 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 16 Oct 2021 07:38:29 +0200 Subject: [PATCH 42/48] MainWindow: Stop build process when closing Code --- src/MainWindow.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 1f8e1d84a9..d30e1628d9 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -695,6 +695,7 @@ namespace Scratch { private void handle_quit () { document_view.save_opened_files (); update_saved_state (); + action_stop (); } public void set_default_zoom () { From 69aa4dd527ab37a70c1c21a5ad0fd71d403a5888 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sat, 16 Oct 2021 07:52:05 +0200 Subject: [PATCH 43/48] ProjectManager: Hide output of run_command_sync --- src/Services/ProjectManager.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index 664404e058..e5596ebebe 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -236,7 +236,7 @@ public class Scratch.Services.ProjectManager : Object { Process.spawn_sync (project_path, spawn_args, spawn_env, - SpawnFlags.SEARCH_PATH, + SpawnFlags.SEARCH_PATH | SpawnFlags.STDERR_TO_DEV_NULL | SpawnFlags.STDOUT_TO_DEV_NULL , null, null, null, From 2fe9d2a7beda8c04347478a53e50d3613164294b Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 17 Oct 2021 09:18:17 +0200 Subject: [PATCH 44/48] Add Terminal widget from Installer --- src/Widgets/Terminal.vala | 73 +++++++++++++++++++++++++++++++++++++++ src/meson.build | 1 + 2 files changed, 74 insertions(+) create mode 100644 src/Widgets/Terminal.vala diff --git a/src/Widgets/Terminal.vala b/src/Widgets/Terminal.vala new file mode 100644 index 0000000000..44b5908c4c --- /dev/null +++ b/src/Widgets/Terminal.vala @@ -0,0 +1,73 @@ +/*- + * Copyright 2019-2021 elementary, Inc. (https://elementary.io) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authored by: Michael Aaron Murphy + */ + +public class Scratch.Widgets.Terminal : Gtk.ScrolledWindow { + public signal void toggled (bool active); + public Gtk.TextBuffer buffer { get; construct; } + + private Gtk.TextView view; + private double prev_upper_adj = 0; + + public string log { + owned get { + return view.buffer.text; + } + } + + public Terminal (Gtk.TextBuffer buffer) { + Object (buffer: buffer); + } + + construct { + view = new Gtk.TextView.with_buffer (buffer) { + cursor_visible = true, + editable = false, + margin_end = 6, + margin_start = 6, + monospace = true, + pixels_below_lines = 3, + wrap_mode = Gtk.WrapMode.WORD + }; + view.get_style_context ().remove_class (Gtk.STYLE_CLASS_VIEW); + + hscrollbar_policy = Gtk.PolicyType.NEVER; + expand = true; + min_content_height = 120; + add (view); + get_style_context ().add_class (Granite.STYLE_CLASS_TERMINAL); + + view.size_allocate.connect (() => attempt_scroll ()); + } + + public void attempt_scroll () { + var adj = vadjustment; + + var units_from_end = prev_upper_adj - adj.page_size - adj.value; + var view_size_difference = adj.upper - prev_upper_adj; + if (view_size_difference < 0) { + view_size_difference = 0; + } + + if (prev_upper_adj <= adj.page_size || units_from_end <= 50) { + adj.value = adj.upper; + } + + prev_upper_adj = adj.upper; + } +} diff --git a/src/meson.build b/src/meson.build index 3636c61d07..af7ac0dc9d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -45,6 +45,7 @@ code_files = files( 'Widgets/PaneSwitcher.vala', 'Widgets/SearchBar.vala', 'Widgets/SourceView.vala', + 'Widgets/Terminal.vala', 'Widgets/WelcomeView.vala', ) From 242fc1108fb277bbb756ad5755ef812c54f61b01 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 17 Oct 2021 09:18:59 +0200 Subject: [PATCH 45/48] MainWindow: Add Terminal to show output of ProjectManager --- src/MainWindow.vala | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index d30e1628d9..b44d554d00 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -37,6 +37,8 @@ namespace Scratch { public Scratch.Widgets.SearchBar search_bar; private Code.WelcomeView welcome_view; private FolderManager.FileView folder_manager_view; + private Gtk.Revealer terminal_revealer; + private Scratch.Widgets.Terminal terminal; // Plugins private Scratch.Services.PluginsManager plugins; @@ -277,14 +279,20 @@ namespace Scratch { project_manager.on_standard_output.connect ((line) => { project_output.add (line); + terminal.buffer.text += line; + terminal.attempt_scroll (); }); project_manager.on_standard_error.connect ((line) => { project_output.add (line); + terminal.buffer.text += line; + terminal.attempt_scroll (); }); project_manager.on_clear.connect ((line) => { project_output.clear (); + terminal.buffer.text = ""; + terminal.attempt_scroll (); }); set_build_run_widgets_sensitive (); @@ -390,6 +398,11 @@ namespace Scratch { on_plugin_toggled (bottombar); }); + // Terminal + terminal = new Scratch.Widgets.Terminal (new Gtk.TextBuffer (null)); + terminal_revealer = new Gtk.Revealer (); + terminal_revealer.add (terminal); + var view_grid = new Gtk.Grid () { orientation = Gtk.Orientation.VERTICAL }; @@ -397,21 +410,26 @@ namespace Scratch { view_grid.add (document_view); content_stack = new Gtk.Stack () { - expand = true, - width_request = 200 + expand = true }; content_stack.add (view_grid); // Must be added first to avoid terminal warnings content_stack.add (welcome_view); content_stack.visible_child = view_grid; // Must be visible while restoring + var content_grid = new Gtk.Grid () { + orientation = Gtk.Orientation.VERTICAL + }; + content_grid.add (content_stack); + content_grid.add (terminal_revealer); + // Set a proper position for ThinPaned widgets int width, height; get_size (out width, out height); vp = new Gtk.Paned (Gtk.Orientation.VERTICAL); vp.position = (height - 150); - vp.pack1 (content_stack, true, false); + vp.pack1 (content_grid, true, false); vp.pack2 (bottombar, false, false); hp1 = new Gtk.Paned (Gtk.Orientation.HORIZONTAL); @@ -426,6 +444,7 @@ namespace Scratch { add (grid); search_revealer.set_reveal_child (false); + terminal_revealer.set_reveal_child (false); realize.connect (() => { Scratch.saved_state.bind ("sidebar-visible", sidebar, "visible", SettingsBindFlags.DEFAULT); @@ -600,6 +619,8 @@ namespace Scratch { toolbar.run_button.tooltip_markup = _("Run"); toolbar.stop_button.tooltip_markup = _("Stop"); } + + terminal_revealer.set_reveal_child (is_running); } // Get current document From 71bef7cbb3b95a62c8824f332703cfa45db2c27a Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 17 Oct 2021 11:35:20 +0200 Subject: [PATCH 46/48] MainWindow: Set visibility of terminal revealer --- src/MainWindow.vala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index b44d554d00..15812656df 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -445,6 +445,7 @@ namespace Scratch { search_revealer.set_reveal_child (false); terminal_revealer.set_reveal_child (false); + terminal_revealer.visible = false; realize.connect (() => { Scratch.saved_state.bind ("sidebar-visible", sidebar, "visible", SettingsBindFlags.DEFAULT); @@ -621,6 +622,7 @@ namespace Scratch { } terminal_revealer.set_reveal_child (is_running); + terminal_revealer.visible = is_running; } // Get current document From 13c6b9fe2aa07daebe71dc7e044a2e7c2d08b5bb Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 17 Oct 2021 11:39:04 +0200 Subject: [PATCH 47/48] MainWindow: Use Gtk.Paned to enable resize of terminal output --- src/MainWindow.vala | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 15812656df..032f3df386 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -417,11 +417,9 @@ namespace Scratch { content_stack.add (welcome_view); content_stack.visible_child = view_grid; // Must be visible while restoring - var content_grid = new Gtk.Grid () { - orientation = Gtk.Orientation.VERTICAL - }; - content_grid.add (content_stack); - content_grid.add (terminal_revealer); + var content_paned = new Gtk.Paned (Gtk.Orientation.VERTICAL); + content_paned.add (content_stack); + content_paned.add (terminal_revealer); // Set a proper position for ThinPaned widgets int width, height; @@ -429,7 +427,7 @@ namespace Scratch { vp = new Gtk.Paned (Gtk.Orientation.VERTICAL); vp.position = (height - 150); - vp.pack1 (content_grid, true, false); + vp.pack1 (content_paned, true, false); vp.pack2 (bottombar, false, false); hp1 = new Gtk.Paned (Gtk.Orientation.HORIZONTAL); From 2842bfa50f4a2d95e402adf5f9f20e3b919f8427 Mon Sep 17 00:00:00 2001 From: Marius Meisenzahl Date: Sun, 17 Oct 2021 11:41:54 +0200 Subject: [PATCH 48/48] Refactor --- src/MainWindow.vala | 3 ++- src/Services/ProjectManager.vala | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 032f3df386..9c13564a27 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -410,7 +410,8 @@ namespace Scratch { view_grid.add (document_view); content_stack = new Gtk.Stack () { - expand = true + expand = true, + width_request = 200 }; content_stack.add (view_grid); // Must be added first to avoid terminal warnings diff --git a/src/Services/ProjectManager.vala b/src/Services/ProjectManager.vala index e5596ebebe..e6a83b3877 100644 --- a/src/Services/ProjectManager.vala +++ b/src/Services/ProjectManager.vala @@ -209,7 +209,6 @@ public class Scratch.Services.ProjectManager : Object { return process_line (channel, condition, "stderr"); }); - ChildWatch.add (command_pid, (pid, status) => { // Triggered when the child indicated by command_pid exits Process.close_pid (pid);