Skip to content

Commit

Permalink
Merge pull request #17 from savaughn/10-bug-development-cleanup
Browse files Browse the repository at this point in the history
10 bug development cleanup
  • Loading branch information
savaughn authored Nov 1, 2024
2 parents b3d796c + ac3f5b5 commit 6e4e9fa
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 81 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified assets/.DS_Store
Binary file not shown.
52 changes: 0 additions & 52 deletions draw_circle.c

This file was deleted.

3 changes: 0 additions & 3 deletions include/actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
#include "common.h"
#include "connection.h"

// Callback function for the start button click
void on_start_button_clicked(GtkButton *button, gpointer data);
// Callback function for the terminate button click
void on_terminate_button_clicked(GtkButton *button, gpointer data);
// Callback function for the restart button click
void on_restart_button_clicked(GtkButton *button, gpointer data);
void on_dark_mode_button_clicked(GtkButton *button, gpointer data);
int read_options_from_application_support(Options *options);
Expand Down
3 changes: 1 addition & 2 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ typedef struct {
gboolean dark_mode;
} Options;

// Struct to hold label, button widgets, and port entry
typedef struct {
GtkLabel *port_label;
GtkButton *start_button;
Expand All @@ -41,7 +40,7 @@ typedef enum

void LOG(const char *restrict fmt, ...);

#define DEFAULT_PORT 8080 // Define the default port
#define DEFAULT_PORT 8080

typedef enum
{
Expand Down
29 changes: 10 additions & 19 deletions src/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,11 @@ void validate_entry_widget(GtkWidget *entry, gpointer data)
!is_valid_directory(gtk_editable_get_text(GTK_EDITABLE(entry))))
{
gtk_widget_add_css_class(entry, "error");

// Disable the start button if the entry is empty
update_widget_ui_state(widgets, STATE_ERROR);
}
else
{
// Remove the error class from the entry widget
gtk_widget_remove_css_class(entry, "error");

// Enable the start button if the entry is not empty
update_widget_ui_state(widgets, STATE_IDLE);
}

Expand All @@ -100,7 +95,7 @@ static int update_single_option_to_application_support(const char *key, json_t *
}

// Create the path to the options file
char *options_path = g_strdup_printf("%s/Library/Application Support/metro-launcher/options.json", home);
char *options_path = g_strdup_printf("%s/Library/Application Support/MetroBundlerLauncher/options.json", home);

// Read the JSON object from the file
json_error_t error;
Expand All @@ -112,10 +107,8 @@ static int update_single_option_to_application_support(const char *key, json_t *
return -1;
}

// Set the value of the key in the JSON object
json_object_set_new(root, key, value);

// Write the JSON object to the file
FILE *fp = fopen(options_path, "w");
if (fp == NULL)
{
Expand All @@ -128,7 +121,6 @@ static int update_single_option_to_application_support(const char *key, json_t *
json_dumpf(root, fp, JSON_INDENT(4));
fclose(fp);

// Free the allocated memory
g_free(options_path);
json_decref(root);

Expand All @@ -145,7 +137,7 @@ int read_options_from_application_support(Options *options)
}

// Create the path to the options file
char *options_path = g_strdup_printf("%s/Library/Application Support/metro-launcher/options.json", home);
char *options_path = g_strdup_printf("%s/Library/Application Support/MetroBundlerLauncher/options.json", home);

// Read the JSON object from the file
json_error_t error;
Expand All @@ -157,21 +149,18 @@ int read_options_from_application_support(Options *options)
return -1;
}

// Get the port, prefix, and file values from the JSON object
json_t *port_json = json_object_get(root, "port");
json_t *prefix_json = json_object_get(root, "prefix");
json_t *file_json = json_object_get(root, "file");
json_t *debugger_enabled_json = json_object_get(root, "debugger_enabled");
json_t *dark_mode_json = json_object_get(root, "dark_mode");

// Set the port, prefix, and file values
options->port = g_strdup(json_string_value(port_json));
options->prefix = g_strdup(json_string_value(prefix_json));
options->file = g_strdup(json_string_value(file_json));
options->debugger_enabled = json_boolean_value(debugger_enabled_json);
options->dark_mode = json_boolean_value(dark_mode_json);

// Free the allocated memory
g_free(options_path);
json_decref(root);

Expand All @@ -188,19 +177,16 @@ int save_options_to_application_support(const Options *options)
}

// Create the path to the application support directory
char *app_support_path = g_strdup_printf("%s/Library/Application Support/metro-launcher", home);
char *app_support_path = g_strdup_printf("%s/Library/Application Support/MetroBundlerLauncher", home);

// Create the directory if it doesn't exist
struct stat st = {0};
if (stat(app_support_path, &st) == -1)
{
mkdir(app_support_path, 0700);
}

// Create the path to the options file
char *options_path = g_strdup_printf("%s/options.json", app_support_path);

// Create the JSON object
json_t *root = json_object();
json_object_set_new(root, "port", json_string(options->port));
json_object_set_new(root, "prefix", json_string(options->prefix));
Expand Down Expand Up @@ -231,7 +217,6 @@ int save_options_to_application_support(const Options *options)
return 0;
}

// Callback function for the start button click
void on_start_button_clicked(GtkButton *button, gpointer data)
{
Widgets *widgets = (Widgets *)data;
Expand Down Expand Up @@ -272,7 +257,13 @@ void on_start_button_clicked(GtkButton *button, gpointer data)
}

// Execute the osascript command to open a new Terminal window and run the command
system(osascript_cmd);
GError *error = NULL;
g_spawn_command_line_async(osascript_cmd, &error);
if (error != NULL)
{
g_printerr("Error spawning command: %s\n", error->message);
g_error_free(error);
}

g_free(osascript_cmd);

Expand Down
1 change: 0 additions & 1 deletion src/content.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ void init_button_box(GtkWidget *button_box, Widgets *widgets, Options *options)
gtk_widget_set_halign(drawing_area, GTK_ALIGN_START);
gtk_widget_set_vexpand(drawing_area, TRUE);

// Define the color (e.g., red)
GdkRGBA *circle_color = g_malloc(sizeof(GdkRGBA));
circle_color->red = RED.red;
circle_color->green = RED.green;
Expand Down
7 changes: 3 additions & 4 deletions src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

void draw_circle(GtkDrawingArea *area, cairo_t *cr, int width, int height, gpointer user_data)
{
// Cast user_data to GdkRGBA
GdkRGBA *color = (GdkRGBA *)user_data;

// Set the background color to transparent
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
cairo_paint(cr);

// Calculate the center and radius of the circle
double radius = MIN(width, height) / 10.0; // Calculate the radius
double center_x = width / 2.0; // Center X position
double center_y = height / 2.0; // Center Y position
double radius = MIN(width, height) / 10.0;
double center_x = width / 2.0;
double center_y = height / 2.0;

// Draw a dark outline around the entire circle
cairo_set_source_rgba(cr, 0.1, 0.1, 0.1, 0.75); // Dark color for the outline
Expand Down

0 comments on commit 6e4e9fa

Please sign in to comment.