Merge pull request #182 from kichikuou/msgskip

Android: Call msgskip_save() when app goes to the background
This commit is contained in:
Nunuhara Cabbage
2024-09-14 10:39:50 -07:00
committed by GitHub
+17 -1
View File
@@ -18,6 +18,7 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <SDL.h>
#include "system4.h"
#include "system4/ain.h"
@@ -49,9 +50,19 @@ static void msgskip_save(void)
fwrite(header, sizeof(header), 1, f);
fwrite(flags, (nr_flags + 7) / 8, 1, f);
fclose(f);
free(flags);
}
#ifdef __ANDROID__
static int msgskip_event_handler(possibly_unused void *user_data, SDL_Event *e) {
switch (e->type) {
case SDL_APP_WILLENTERBACKGROUND:
msgskip_save();
break;
}
return 0;
}
#endif
static int MsgSkip_Init(struct string *name)
{
if (flags)
@@ -93,6 +104,9 @@ static int MsgSkip_Init(struct string *name)
}
free(data);
}
#ifdef __ANDROID__
SDL_AddEventWatch(msgskip_event_handler, NULL);
#endif
atexit(msgskip_save);
return 1;
}
@@ -162,6 +176,8 @@ static int vmMsgSkip_Open(struct string *fname, possibly_unused int option)
static void vmMsgSkip_Close(possibly_unused int handle)
{
msgskip_save();
free(flags);
flags = NULL;
}
static int vmMsgSkip_Query(possibly_unused int handle, int msgnum)