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

Contributor update #2652

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Contributor update #2652

wants to merge 5 commits into from

Conversation

theofficialgman
Copy link
Collaborator

@theofficialgman theofficialgman commented Oct 3, 2024

@Botspot this is by no means final. I have created this PR so we can start to discuss the exact wording and the presentation of the information that we discussed in #dev-chat on the discord. The wording can (and likely should) fully change and was kept brief so as to not waste my time on something that we didn't agree on.

manage Outdated Show resolved Hide resolved
@@ -420,6 +420,7 @@ $app"
[ -z "$geometry2" ] && geometry2='--center'

tail -f --retry "${DIRECTORY}/data/manage-daemon/yadlist" 2>/dev/null | yad --class Pi-Apps --name "Pi-Apps" --width=330 --height=400 "$geometry2" --title='Monitor Progress' \
--text="We are always looking for fresh ideas and new contributors to join our team: <a href="\""https://pi-apps.io/#get-involved"\"">https://pi-apps.io/#get-involved</a>" \
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this I want to make a dedicated webpage for "new contributors" to link to that goes over the things we discussed in the discord, attempting to welcome users into the "family" of pi-apps contributors.

… completed applications from the manage-daemon
@theofficialgman
Copy link
Collaborator Author

theofficialgman commented Oct 22, 2024

Current generate_splashscreen output

image

Particular placement of icons and text is not necessarily final but this is the idea I had in mind.

@theofficialgman
Copy link
Collaborator Author

theofficialgman commented Oct 22, 2024

here is equivalent C code (which is GTK's native language, everything else is a wrapper ontop of the C library) if we don't want to use python (it could be precompiled or compiled in a runonce)

#include <gtk/gtk.h>
#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Function to create the splash screen
void generate_splashscreen(const gchar *apps, const gchar *message) {
    GtkWidget *window;
    GtkWidget *vbox;
    GtkWidget *label;
    GtkWidget *grid;
    GtkWidget *ok_button;
    GtkWidget *hbox;
    gchar **app_lines;
    int rows = 0;
    int cols = 0;
    int num_cols = 3; // Number of columns in the grid
    const char* DIRECTORY = getenv("DIRECTORY");

    // Initialize GTK
    gtk_init(NULL, NULL);

    // Create a new window
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Pi-Apps Actions Complete");
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);

    // Create a main vertical box to hold the label and grid
    vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
    gtk_container_add(GTK_CONTAINER(window), vbox);

    // Set border width for the main vertical box
    gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);

    // Create and add the label
    label = gtk_label_new(message);
    gtk_label_set_line_wrap(GTK_LABEL(label),TRUE);
    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);

    // Create a Grid to hold the images and labels
    grid = gtk_grid_new();
    gtk_box_pack_start(GTK_BOX(vbox), grid, TRUE, TRUE, 0);

    // Split the input apps string into lines
    app_lines = g_strsplit(apps, "\n", 0);

    // Add the images and app names to the grid
    for (int i = 0; app_lines[i] != NULL; i++) {
        gchar **app_data = g_strsplit(app_lines[i], ";", 0);  // Split into app name, action, and status
        if (g_strv_length(app_data) < 3) {
            g_strfreev(app_data);
            continue; // Skip if data is not complete
        }

        const gchar *app_name = g_strstrip(app_data[1]);
        const gchar *action = g_strstrip(app_data[0]);
        const gchar *status = g_strstrip(app_data[2]);

        // Generate the image path based on the app name
        gchar image_path[512];
        g_snprintf(image_path, sizeof(image_path), "%s/apps/%s/icon-64.png", DIRECTORY, app_name);

        // Determine the action icon path
        gchar action_icon_path[512];
        if (g_strcmp0(action, "install") == 0) {
            g_snprintf(action_icon_path, sizeof(action_icon_path), "%s/icons/install.png", DIRECTORY);
        } else if (g_strcmp0(action, "uninstall") == 0) {
            g_snprintf(action_icon_path, sizeof(action_icon_path), "%s/icons/uninstall.png", DIRECTORY);
        } else if (g_strcmp0(action, "update") == 0) {
            g_snprintf(action_icon_path, sizeof(action_icon_path), "%s/icons/update.png", DIRECTORY);
        } else {
            g_snprintf(action_icon_path, sizeof(action_icon_path), "%s/icons/exit.png", DIRECTORY);
        }

        // Determine the status icon path
        gchar status_icon_path[512];
        if (g_strcmp0(status, "0") == 0) {
            g_snprintf(status_icon_path, sizeof(status_icon_path), "%s/icons/success.png", DIRECTORY);
        } else {
            g_snprintf(status_icon_path, sizeof(status_icon_path), "%s/icons/failure.png", DIRECTORY);
        }

        // Create the app icon
        GtkWidget *app_image = gtk_image_new_from_file(image_path);
        gtk_widget_set_size_request(app_image, 128, 128); // Adjust size as needed

        // Create the action icon with specific size
        GdkPixbuf *action_pixbuf = gdk_pixbuf_new_from_file_at_size(action_icon_path, -1, 32, NULL);
        GtkWidget *action_image = gtk_image_new_from_pixbuf(action_pixbuf);

        // Create the status icon with specific size
        GdkPixbuf *status_pixbuf = gdk_pixbuf_new_from_file_at_size(status_icon_path, -1, 24, NULL);
        GtkWidget *status_image = gtk_image_new_from_pixbuf(status_pixbuf);

        // Create a fixed container to overlay action and status icons on top of the app icon
        GtkWidget *overlay = gtk_fixed_new();
        gtk_widget_set_size_request(overlay, 128, 128); // Match app icon size
        gtk_fixed_put(GTK_FIXED(overlay), app_image, 0, 0);  // Place app image in the overlay

        // Adjust the position of the action icon for more overlap
        gtk_fixed_put(GTK_FIXED(overlay), action_image, 6, 12);  // Position action icon

        // Get the width of the action image for positioning the status icon
        int action_image_width = gdk_pixbuf_get_width(action_pixbuf);

        // Position status icon next to the action icon based on the width of the action icon
        gtk_fixed_put(GTK_FIXED(overlay), status_image, 10 + action_image_width, 18); // Add some padding

        // Create a label for the app name
        GtkWidget *app_label = gtk_label_new(app_name);

        // Add overlay and label to the grid at the current row and column
        gtk_grid_attach(GTK_GRID(grid), overlay, cols, rows, 1, 1);
        gtk_grid_attach(GTK_GRID(grid), app_label, cols, rows + 1, 1, 1);  // Place label below the image

        // Increment columns, and start a new row if the column count reaches 3
        cols++;
        if (cols == num_cols) {
            cols = 0;
            rows += 2;  // Increment rows by 2 for the label
        }

        // Free the split app data
        g_strfreev(app_data);
        // Free the pixbufs
        g_object_unref(action_pixbuf);
        g_object_unref(status_pixbuf);
    }

    // Create an "Ok" button
    ok_button = gtk_button_new_with_label("Ok");
    g_signal_connect(ok_button, "clicked", G_CALLBACK(gtk_main_quit), NULL);  // Connect the button to close the window

    // Create a horizontal box to center the button
    hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
    gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(""), TRUE, TRUE, 0);  // Add a spacer
    gtk_box_pack_start(GTK_BOX(hbox), ok_button, FALSE, FALSE, 0);  // Add the button
    gtk_box_pack_start(GTK_BOX(hbox), gtk_label_new(""), TRUE, TRUE, 0);  // Add a spacer

    // Pack the button box at the bottom of the vertical box
    gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);

    // Connect the destroy signal to clean up and exit
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    // Show all widgets
    gtk_widget_show_all(window);

    // Start the GTK main loop
    gtk_main();

    // Free the app lines
    g_strfreev(app_lines);
}

// Main function
int main(int argc, char *argv[]) {
    if (argc != 3) {
        fprintf(stderr, "Usage: %s <app_string> <message_string>\n", argv[0]);
        return 1;
    }

    // Call the function with the input string
    generate_splashscreen(argv[1], argv[2]);

    return 0;
}
gcc `pkg-config --cflags gtk+-3.0` -o splashscreen splashscreen.c `pkg-config --libs gtk+-3.0`

example:

DIRECTORY=put/directory/path/in/environment ./splashscreen "install;USBImager;0
uninstall;Wine (x64);1
update;Zoom;0
update;Deluge;1" "Thanks for using Pi-Apps! The following apps completed:"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant