Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Implement URI Handler + misc tweaks #278

Merged
merged 9 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion data/com.mattjakeman.ExtensionManager.desktop.in.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[Desktop Entry]
Name=@app_title@
Exec=extension-manager
Exec=extension-manager %U
Icon=@app_id@
Terminal=false
Type=Application
Categories=GTK;Utility
StartupNotify=true
MimeType=x-scheme-handler/gnome-extensions;
2 changes: 1 addition & 1 deletion data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ appconf.set('app_id', app_id)
appconf.set('app_title', app_title)
appstream_file_in = configure_file(
input: 'com.mattjakeman.ExtensionManager.metainfo.xml.in.in',
output: '@0@.metainfo.xml.in'.format(app_id),
output: 'com.mattjakeman.ExtensionManager.metainfo.xml.in',
configuration: appconf,
)

Expand Down
87 changes: 69 additions & 18 deletions src/exm-application.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ exm_application_finalize (GObject *object)
G_OBJECT_CLASS (exm_application_parent_class)->finalize (object);
}

static ExmWindow *
get_current_window (GApplication *app)
{
GtkWindow *window;

/* Get the current window or create one if necessary. */
window = gtk_application_get_active_window (GTK_APPLICATION (app));
if (window == NULL)
window = g_object_new (EXM_TYPE_WINDOW,
"application", app,
NULL);

return EXM_WINDOW (window);
}

static void
exm_application_activate (GApplication *app)
{
Expand All @@ -73,33 +88,69 @@ exm_application_activate (GApplication *app)
icon_theme = gtk_icon_theme_get_for_display (display);
gtk_icon_theme_add_resource_path (icon_theme, "/com/mattjakeman/ExtensionManager/icons");

/* Get the current window or create one if necessary. */
window = gtk_application_get_active_window (GTK_APPLICATION (app));
if (window == NULL)
window = g_object_new (EXM_TYPE_WINDOW,
"application", app,
NULL);
window = GTK_WINDOW (get_current_window (app));

/* Ask the window manager/compositor to present the window. */
gtk_window_present (window);
}

static void
exm_application_open (GApplication *app,
GFile **files,
gint n_files,
const gchar *hint)
{
ExmWindow *window;
const char *scheme;
const char *uuid;
GUri *uri;
GError *error = NULL;

// Activate the application first
exm_application_activate (app);

// Now open the provided extension
window = get_current_window (app);

if (n_files <= 0)
return;

uri = g_uri_parse (g_file_get_uri (files[0]), G_URI_FLAGS_NONE, &error);
if (error)
{
g_critical ("Error parsing URI: %s\n", error->message);
return;
}

scheme = g_uri_get_scheme (uri);
if (!g_str_equal (scheme, "gnome-extensions"))
{
g_critical ("Invalid URI scheme: '%s'\n", scheme);
return;
}

uuid = g_uri_get_host (uri);
g_print ("Opening extension with UUID: '%s'\n", uuid);
gtk_widget_activate_action (GTK_WIDGET (window), "win.show-detail", "s", uuid);
}


static void
exm_application_class_init (ExmApplicationClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GApplicationClass *app_class = G_APPLICATION_CLASS (klass);

object_class->finalize = exm_application_finalize;

/*
* We connect to the activate callback to create a window when the application
* has been launched. Additionally, this callback notifies us when the user
* tries to launch a "second instance" of the application. When they try
* to do that, we'll just present any existing window.
*/
app_class->activate = exm_application_activate;
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GApplicationClass *app_class = G_APPLICATION_CLASS (klass);

object_class->finalize = exm_application_finalize;

/*
* We connect to the activate callback to create a window when the application
* has been launched. Additionally, this callback notifies us when the user
* tries to launch a "second instance" of the application. When they try
* to do that, we'll just present any existing window.
*/
app_class->activate = exm_application_activate;
app_class->open = exm_application_open;
}

static void
Expand Down
4 changes: 4 additions & 0 deletions src/exm-browse-page.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ exm_browse_page_new (void)
static void
exm_browse_page_finalize (GObject *object)
{
GtkWidget *child;
ExmBrowsePage *self = (ExmBrowsePage *)object;

child = gtk_widget_get_first_child (GTK_WIDGET (self));
gtk_widget_unparent (child);

G_OBJECT_CLASS (exm_browse_page_parent_class)->finalize (object);
}

Expand Down
4 changes: 4 additions & 0 deletions src/exm-installed-page.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ exm_installed_page_new (void)
static void
exm_installed_page_finalize (GObject *object)
{
GtkWidget *child;
ExmInstalledPage *self = (ExmInstalledPage *)object;

child = gtk_widget_get_first_child (GTK_WIDGET (self));
gtk_widget_unparent (child);

G_OBJECT_CLASS (exm_installed_page_parent_class)->finalize (object);
}

Expand Down
4 changes: 4 additions & 0 deletions src/exm-screenshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ exm_screenshot_new (void)
static void
exm_screenshot_finalize (GObject *object)
{
GtkWidget *child;
ExmScreenshot *self = (ExmScreenshot *)object;

child = gtk_widget_get_first_child (GTK_WIDGET (self));
gtk_widget_unparent (child);

G_OBJECT_CLASS (exm_screenshot_parent_class)->finalize (object);
}

Expand Down
4 changes: 4 additions & 0 deletions src/exm-zoom-picture.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,13 @@ compute_scaled_dimensions (ExmZoomPicture *self)
// Apply offset and constrain to image borders
if (scaled_width > width)
x += self->image_x;
else
self->image_x = 0.0f;

if (scaled_height > height)
y += self->image_y;
else
self->image_y = 0.0f;

// Update for drawing
self->scaled_width = scaled_width;
Expand Down
4 changes: 2 additions & 2 deletions src/local/exm-extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ exm_extension_set_property (GObject *object,
case PROP_DISPLAY_NAME:
if (self->display_name)
g_free (self->display_name);
self->display_name = g_markup_escape_text (g_value_dup_string (value), -1);
self->display_name = g_value_dup_string (value);
break;
case PROP_DESCRIPTION:
if (self->description)
g_free (self->description);
self->description = g_markup_escape_text (g_value_dup_string (value), -1);
self->description = g_value_dup_string (value);
break;
case PROP_STATE:
self->state = g_value_get_enum (value);
Expand Down
5 changes: 5 additions & 0 deletions src/local/exm-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ create_callback_data (ExmManager *manager,

data->manager = g_object_ref (manager);
data->extension = g_object_ref (extension);

return data;
}

static void
free_callback_data (ExmCallbackData *data)
{
if (!data)
return;

g_clear_object (&data->manager);
g_clear_object (&data->extension);

Expand Down
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ run_app (int argc,
* application windows, integration with the window manager/compositor, and
* desktop features such as file opening and single-instance applications.
*/
app = exm_application_new (APP_ID, G_APPLICATION_FLAGS_NONE);
app = exm_application_new (APP_ID, G_APPLICATION_HANDLES_OPEN);

/*
* Run the application. This function will block until the application
Expand Down Expand Up @@ -165,7 +165,7 @@ main (int argc,
g_string_append_c (string_builder, ch);

// Wait for child to finish
waitpid(pid, 0, 0);
waitpid (pid, 0, 0);
close (pipe_fd[0]);

error_text = g_string_free (string_builder, FALSE);
Expand Down