Fixed shutdown behavior
This commit is contained in:
parent
54a7372abf
commit
3e03b512e1
35
src/main.c
35
src/main.c
@ -5,6 +5,11 @@
|
||||
#include "mdiary.h"
|
||||
#include "settings.h"
|
||||
|
||||
struct app_state {
|
||||
struct mainWindow *mainWindow;
|
||||
struct mdiary_settings *settings;
|
||||
};
|
||||
|
||||
static void quit_cb(GSimpleAction *action, GVariant *parameter, gpointer user_data)
|
||||
{
|
||||
struct mainWindow *mainWindow = *((struct mainWindow **) user_data);
|
||||
@ -26,27 +31,38 @@ const GActionEntry app_actions[] = {
|
||||
|
||||
static void activate(GApplication *app, gpointer user_data)
|
||||
{
|
||||
struct mainWindow **mainWindow = (struct mainWindow **) user_data;
|
||||
struct mdiary_settings *settings;
|
||||
struct app_state *app_state = user_data;
|
||||
struct mainWindow **mainWindow = &(app_state->mainWindow);
|
||||
struct mdiary_settings **settings = &(app_state->settings);
|
||||
gchar *settings_path;
|
||||
|
||||
*mainWindow = mainWindow_new();
|
||||
gtk_application_add_window(GTK_APPLICATION(app), GTK_WINDOW((*mainWindow)->mainWindow));
|
||||
|
||||
settings_path = g_strdup_printf("%s/.mdiary.conf", g_get_home_dir());
|
||||
settings = mdiary_settings_new(*mainWindow);
|
||||
mdiary_load_settings(settings_path, settings);
|
||||
*settings = mdiary_settings_new(*mainWindow);
|
||||
mdiary_load_settings(settings_path, *settings);
|
||||
g_free(settings_path);
|
||||
|
||||
gtk_widget_show((*mainWindow)->mainWindow);
|
||||
}
|
||||
|
||||
mdiary_save_settings(settings_path, settings);
|
||||
mdiary_settings_free(settings);
|
||||
static void shutdown(GApplication *app, gpointer user_data)
|
||||
{
|
||||
struct app_state *app_state = user_data;
|
||||
struct mainWindow **mainWindow = &(app_state->mainWindow);
|
||||
struct mdiary_settings **settings = &(app_state->settings);
|
||||
gchar *settings_path;
|
||||
|
||||
settings_path = g_strdup_printf("%s/.mdiary.conf", g_get_home_dir());
|
||||
mdiary_save_settings(settings_path, *settings);
|
||||
mdiary_settings_free(*settings);
|
||||
g_free(settings_path);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct mainWindow *mainWindow;
|
||||
struct app_state app_state;
|
||||
GtkApplication *app;
|
||||
GMenu *app_menu;
|
||||
GMenu *p1;
|
||||
@ -55,7 +71,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
app = gtk_application_new("net.notsyncing.mdiary", G_APPLICATION_FLAGS_NONE);
|
||||
g_application_register(G_APPLICATION(app), NULL, NULL);
|
||||
g_signal_connect(app, "activate", G_CALLBACK(activate), &mainWindow);
|
||||
g_signal_connect(app, "activate", G_CALLBACK(activate), &app_state);
|
||||
g_signal_connect(app, "shutdown", G_CALLBACK(shutdown), &app_state);
|
||||
|
||||
app_menu = g_menu_new();
|
||||
p1 = g_menu_new();
|
||||
@ -65,7 +82,7 @@ int main(int argc, char *argv[])
|
||||
g_menu_append_section(app_menu, NULL, G_MENU_MODEL(p1));
|
||||
g_menu_append_section(app_menu, NULL, G_MENU_MODEL(p2));
|
||||
gtk_application_set_app_menu(app, G_MENU_MODEL(app_menu));
|
||||
g_action_map_add_action_entries(G_ACTION_MAP(app), app_actions, G_N_ELEMENTS(app_actions), &mainWindow);
|
||||
g_action_map_add_action_entries(G_ACTION_MAP(app), app_actions, G_N_ELEMENTS(app_actions), &app_state);
|
||||
gtk_application_set_app_menu(GTK_APPLICATION(app), G_MENU_MODEL(app_menu));
|
||||
g_object_unref(p1);
|
||||
g_object_unref(p2);
|
||||
|
Loading…
Reference in New Issue
Block a user