mirror of
https://github.com/webui-dev/webui.git
synced 2024-09-11 22:17:13 +03:00
Adding webui_delete_all_profiles
- Adding webui_delete_all_profiles() - Adding webui_delete_profile() - Adding webui_clean() - Now. webui_wait() simply means no more windows are running. And app can create and show windows. And of program is now become webui_clean(). - Updating Civetweb (Server close faster now)
This commit is contained in:
parent
2f694d1a3f
commit
62030156e5
@ -89,6 +89,11 @@ int main() {
|
||||
|
||||
// Wait until all windows get closed
|
||||
webui_wait();
|
||||
webui_show(my_window, my_html);
|
||||
webui_wait();
|
||||
|
||||
// Free all memory resources (Optional)
|
||||
webui_clean();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -417,7 +417,7 @@ WEBUI_EXPORT void webui_set_position(size_t window, unsigned int x, unsigned int
|
||||
WEBUI_EXPORT void webui_set_profile(size_t window, const char* name, const char* path);
|
||||
|
||||
/**
|
||||
* @brief Get the full current URL
|
||||
* @brief Get the full current URL.
|
||||
*
|
||||
* @param window The window number
|
||||
*
|
||||
@ -438,12 +438,38 @@ WEBUI_EXPORT const char* webui_get_url(size_t window);
|
||||
WEBUI_EXPORT void webui_navigate(size_t window, const char* url);
|
||||
|
||||
/**
|
||||
* @brief Delete all local web browser profile's folder
|
||||
* @brief Free all memory resources. Should be called only at the end.
|
||||
*
|
||||
* @example webui_clean();
|
||||
* @example
|
||||
* webui_wait();
|
||||
* webui_clean();
|
||||
*/
|
||||
WEBUI_EXPORT void webui_clean();
|
||||
|
||||
/**
|
||||
* @brief Delete all local web-browser profile's folder. Should be called at the end.
|
||||
*
|
||||
* @example
|
||||
* webui_wait();
|
||||
* webui_delete_all_profiles();
|
||||
* webui_clean();
|
||||
*/
|
||||
WEBUI_EXPORT void webui_delete_all_profiles();
|
||||
|
||||
/**
|
||||
* @brief Delete a specific window web-browser local folder profile.
|
||||
*
|
||||
* @param window The window number
|
||||
*
|
||||
* @example
|
||||
* webui_wait();
|
||||
* webui_delete_profile(myWindow);
|
||||
* webui_clean();
|
||||
*
|
||||
* @note This can break functionality of other windows if using the same web-browser.
|
||||
*/
|
||||
WEBUI_EXPORT void webui_delete_profile(size_t window);
|
||||
|
||||
// -- JavaScript ----------------------
|
||||
|
||||
// Run JavaScript without waiting for the response.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -47,8 +47,8 @@ mg_match_impl(const char *pat,
|
||||
/* Advance as long as there are ? */
|
||||
i_pat++;
|
||||
i_str++;
|
||||
} while ((pat[i_pat] == '?') && (str[i_str] != '\0')
|
||||
&& (str[i_str] != '/') && (i_pat < pat_len));
|
||||
} while ((i_pat < pat_len) && (pat[i_pat] == '?')
|
||||
&& (str[i_str] != '\0') && (str[i_str] != '/'));
|
||||
|
||||
/* If we have a match context, add the substring we just found */
|
||||
if (mcx) {
|
||||
@ -72,7 +72,7 @@ mg_match_impl(const char *pat,
|
||||
ptrdiff_t ret;
|
||||
|
||||
i_pat++;
|
||||
if ((pat[i_pat] == '*') && (i_pat < pat_len)) {
|
||||
if ((i_pat < pat_len) && (pat[i_pat] == '*')) {
|
||||
/* Pattern ** matches all */
|
||||
i_pat++;
|
||||
len = strlen(str + i_str);
|
||||
|
113
src/webui.c
113
src/webui.c
@ -745,43 +745,74 @@ void webui_clean() {
|
||||
printf("[User] webui_clean()...\n");
|
||||
#endif
|
||||
|
||||
// Initialization
|
||||
_webui_init();
|
||||
|
||||
// Final memory cleaning
|
||||
_webui_clean();
|
||||
}
|
||||
|
||||
void webui_delete_all_profiles() {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_delete_all_profiles()...\n");
|
||||
#endif
|
||||
|
||||
// Initialization
|
||||
_webui_init();
|
||||
|
||||
// Loop trough windows
|
||||
for(size_t i = 1; i <= _webui_core.last_win_number; i++) {
|
||||
if(_webui_core.wins[i] != NULL) {
|
||||
webui_delete_profile(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_webui_window_t* win = _webui_core.wins[i];
|
||||
if(_webui_folder_exist(win->profile_path)) {
|
||||
if(win->current_browser == Firefox) {
|
||||
|
||||
// Delete Firefox profile
|
||||
void webui_delete_profile(size_t window) {
|
||||
|
||||
// TODO:
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[User] webui_delete_profile([%zu])...\n", window);
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
// Windows
|
||||
// Initialization
|
||||
_webui_init();
|
||||
|
||||
// Dereference
|
||||
if(_webui_core.wins[window] == NULL) return;
|
||||
_webui_window_t* win = _webui_core.wins[window];
|
||||
|
||||
// 1. Read "%APPDATA%\Mozilla\Firefox\profiles.ini"
|
||||
// 2. Delete the section that contain { "Path=" + win->profile_path }
|
||||
// 3. _webui_delete_folder(win->profile_path);
|
||||
if(_webui_folder_exist(win->profile_path)) {
|
||||
|
||||
// win->profile_path: Full path to profile
|
||||
// win->browser_path: Full path to firefox browser
|
||||
#elif __linux__
|
||||
// Linux
|
||||
if(win->current_browser == Firefox) {
|
||||
|
||||
// Delete Firefox profile
|
||||
|
||||
// TODO: ...
|
||||
#else
|
||||
// macOS
|
||||
// TODO:
|
||||
|
||||
// TODO: ...
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#ifdef _WIN32
|
||||
// Windows
|
||||
|
||||
// Delete Chromium based profile
|
||||
_webui_delete_folder(win->profile_path);
|
||||
}
|
||||
}
|
||||
// 1. Read "%APPDATA%\Mozilla\Firefox\profiles.ini"
|
||||
// 2. Delete the section that contain { "Path=" + win->profile_path }
|
||||
// 3. _webui_delete_folder(win->profile_path);
|
||||
|
||||
// win->profile_path: Full path to profile
|
||||
// win->browser_path: Full path to firefox browser
|
||||
#elif __linux__
|
||||
// Linux
|
||||
|
||||
// TODO: ...
|
||||
#else
|
||||
// macOS
|
||||
|
||||
// TODO: ...
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
|
||||
// Delete Chromium-based profile
|
||||
_webui_delete_folder(win->profile_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1515,11 +1546,10 @@ void webui_wait(void) {
|
||||
// is running. Otherwise the mutex condition
|
||||
// signal will never come
|
||||
if(!_webui_core.ui) {
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[Loop] webui_wait() -> No window is found. Stop.\n");
|
||||
#endif
|
||||
|
||||
_webui_clean();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1552,9 +1582,6 @@ void webui_wait(void) {
|
||||
#endif
|
||||
|
||||
_webui_mutex_unlock(&_webui_core.mutex_wait);
|
||||
|
||||
// Final cleaning
|
||||
_webui_clean();
|
||||
}
|
||||
|
||||
void webui_set_timeout(size_t second) {
|
||||
@ -1767,13 +1794,10 @@ bool webui_interface_is_app_running(void) {
|
||||
app_is_running = false;
|
||||
}
|
||||
|
||||
// Final cleaning
|
||||
if(!app_is_running) {
|
||||
#ifdef WEBUI_LOG
|
||||
#ifdef WEBUI_LOG
|
||||
if(!app_is_running)
|
||||
printf("[User] webui_is_app_running() -> App Stopped.\n");
|
||||
#endif
|
||||
_webui_clean();
|
||||
}
|
||||
#endif
|
||||
|
||||
return app_is_running;
|
||||
}
|
||||
@ -2980,9 +3004,13 @@ static void _webui_delete_folder(char* folder) {
|
||||
|
||||
char command[1024];
|
||||
#if defined(_WIN32)
|
||||
snprintf(command, sizeof(command), "rmdir /s /q \"%s\"", folder);
|
||||
snprintf(command, sizeof(command), "rmdir /s /q \"%s\" > nul 2>&1", folder);
|
||||
#else
|
||||
snprintf(command, sizeof(command), "rm -rf \"%s\"", folder);
|
||||
snprintf(command, sizeof(command), "rm -rf \"%s\" >>/dev/null 2>>/dev/null", folder);
|
||||
#endif
|
||||
|
||||
#ifdef WEBUI_LOG
|
||||
printf("[Core]\t\t_webui_delete_folder() -> Running [%s] \n", command);
|
||||
#endif
|
||||
system(command);
|
||||
}
|
||||
@ -5877,8 +5905,11 @@ static WEBUI_SERVER_START
|
||||
mg_stop(http_ctx);
|
||||
|
||||
// Fire the mutex condition wait
|
||||
if(_webui_core.startup_timeout > 0 && _webui_core.servers < 1)
|
||||
_webui_condition_signal(&_webui_core.condition_wait);
|
||||
if(_webui_core.startup_timeout > 0 && _webui_core.servers < 1) {
|
||||
|
||||
_webui_core.ui = false;
|
||||
_webui_condition_signal(&_webui_core.condition_wait);
|
||||
}
|
||||
|
||||
THREAD_RETURN
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user