Skip to content

Commit

Permalink
feat: update to v4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Oct 2, 2024
1 parent e62761f commit 10b540d
Show file tree
Hide file tree
Showing 24 changed files with 355 additions and 180 deletions.
16 changes: 12 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.21)
project(saucer-bindings LANGUAGES CXX VERSION 3.0.0)
project(saucer-bindings LANGUAGES CXX VERSION 4.0.0)

# --------------------------------------------------------------------------------------------------------
# CMake options
Expand All @@ -9,7 +9,7 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)

set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)

# --------------------------------------------------------------------------------------------------------
# Create executable
Expand All @@ -25,6 +25,10 @@ if (PROJECT_IS_TOP_LEVEL AND NOT MSVC AND NOT CMAKE_CXX_SIMULATE_ID MATCHES "MSV
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror -pedantic -pedantic-errors -Wfatal-errors)
endif()

if (NOT MSVC)
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-unknown-warning-option -Wno-missing-field-initializers -Wno-cast-function-type)
endif()

# --------------------------------------------------------------------------------------------------------
# Export header
# --------------------------------------------------------------------------------------------------------
Expand All @@ -49,13 +53,17 @@ target_include_directories(${PROJECT_NAME} PRIVATE "include/saucer" "private" "u
# --------------------------------------------------------------------------------------------------------

target_sources(${PROJECT_NAME} PRIVATE
"src/app.cpp"

"src/icon.cpp"
"src/memory.cpp"

"src/stash.cpp"
"src/script.cpp"
"src/scheme.cpp"
"src/options.cpp"

"src/navigation.cpp"
"src/preferences.cpp"

"src/window.cpp"
"src/webview.cpp"
Expand All @@ -69,7 +77,7 @@ include("cmake/cpm.cmake")

CPMFindPackage(
NAME saucer
GIT_TAG v3.0.0
VERSION 4.0.0
GIT_REPOSITORY "https://github.com/saucer/saucer"
)

Expand Down
27 changes: 27 additions & 0 deletions include/saucer/app.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#ifdef __cplusplus
extern "C"
{
#endif

#include "export.h"

struct saucer_application;

SAUCER_EXPORT saucer_application *saucer_application_acquire(const char *id);
SAUCER_EXPORT void saucer_application_free(saucer_application *);

SAUCER_EXPORT bool saucer_application_thread_safe(saucer_application *);

typedef void (*saucer_post_callback)();
SAUCER_EXPORT void saucer_application_post(saucer_application *, saucer_post_callback callback);

SAUCER_EXPORT void saucer_application_quit(saucer_application *);

SAUCER_EXPORT void saucer_application_run(saucer_application *);
SAUCER_EXPORT void saucer_application_run_once(saucer_application *);

#ifdef __cplusplus
}
#endif
14 changes: 14 additions & 0 deletions include/saucer/desktop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#ifdef __cplusplus
extern "C"
{
#endif

#include "export.h"

SAUCER_EXPORT void saucer_desktop_open(const char *uri);

#ifdef __cplusplus
}
#endif
24 changes: 24 additions & 0 deletions include/saucer/navigation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#ifdef __cplusplus
extern "C"
{
#endif

#include "export.h"

#include <stdbool.h>

struct saucer_navigation;

SAUCER_EXPORT void saucer_navigation_free(saucer_navigation *);

SAUCER_EXPORT char *saucer_navigation_url(saucer_navigation *);

SAUCER_EXPORT bool saucer_navigation_new_window(saucer_navigation *);
SAUCER_EXPORT bool saucer_navigation_redirection(saucer_navigation *);
SAUCER_EXPORT bool saucer_navigation_user_initiated(saucer_navigation *);

#ifdef __cplusplus
}
#endif
25 changes: 0 additions & 25 deletions include/saucer/options.h

This file was deleted.

28 changes: 28 additions & 0 deletions include/saucer/preferences.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#ifdef __cplusplus
extern "C"
{
#endif

#include "export.h"

#include "app.h"

#include <stddef.h>

struct saucer_preferences;

SAUCER_EXPORT saucer_preferences *saucer_preferences_new(saucer_application *app);
SAUCER_EXPORT void saucer_preferences_free(saucer_preferences *);

SAUCER_EXPORT void saucer_preferences_set_persistent_cookies(saucer_preferences *, bool enabled);
SAUCER_EXPORT void saucer_preferences_set_hardware_acceleration(saucer_preferences *, bool enabled);

SAUCER_EXPORT void saucer_preferences_set_storage_path(saucer_preferences *, const char *path);
SAUCER_EXPORT void saucer_preferences_add_browser_flag(saucer_preferences *, const char *flag);
SAUCER_EXPORT void saucer_preferences_set_user_agent(saucer_preferences *, const char *user_agent);

#ifdef __cplusplus
}
#endif
28 changes: 15 additions & 13 deletions include/saucer/scheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern "C"
#include "stash.h"
#include "window.h"

enum SAUCER_REQUEST_ERROR
enum SAUCER_SCHEME_ERROR
{
SAUCER_REQUEST_ERROR_NOT_FOUND,
SAUCER_REQUEST_ERROR_INVALID,
Expand All @@ -19,27 +19,28 @@ extern "C"
SAUCER_REQUEST_ERROR_FAILED,
};

struct saucer_response;
struct saucer_scheme_response;

SAUCER_EXPORT saucer_response *saucer_response_new(saucer_stash *data, const char *mime);
SAUCER_EXPORT saucer_response *saucer_response_unexpected(SAUCER_REQUEST_ERROR error);
SAUCER_EXPORT saucer_scheme_response *saucer_scheme_response_new(saucer_stash *data, const char *mime);
SAUCER_EXPORT saucer_scheme_response *saucer_scheme_response_unexpected(SAUCER_SCHEME_ERROR error);

/**
* @note Under normal circumstances this function should not be used. Once a saucer_response is
* returned from within a saucer_scheme_handler it is automatically deleted.
* You may use this function to free the response in case of an exception.
*/
SAUCER_EXPORT void saucer_response_free(saucer_response *);
SAUCER_EXPORT void saucer_scheme_response_free(saucer_scheme_response *);

SAUCER_EXPORT void saucer_response_set_status(saucer_response *, int status);
SAUCER_EXPORT void saucer_response_add_header(saucer_response *, const char *header, const char *value);
SAUCER_EXPORT void saucer_scheme_response_set_status(saucer_scheme_response *, int status);
SAUCER_EXPORT void saucer_scheme_response_add_header(saucer_scheme_response *, const char *header,
const char *value);

struct saucer_request;
struct saucer_scheme_request;

/*[[sc::requires_free]]*/ SAUCER_EXPORT char *saucer_request_url(saucer_request *);
/*[[sc::requires_free]]*/ SAUCER_EXPORT char *saucer_request_method(saucer_request *);
/*[[sc::requires_free]]*/ SAUCER_EXPORT char *saucer_scheme_request_url(saucer_scheme_request *);
/*[[sc::requires_free]]*/ SAUCER_EXPORT char *saucer_scheme_request_method(saucer_scheme_request *);

/*[[sc::requires_free]]*/ SAUCER_EXPORT saucer_stash *saucer_request_content(saucer_request *);
/*[[sc::requires_free]]*/ SAUCER_EXPORT saucer_stash *saucer_scheme_request_content(saucer_scheme_request *);

/**
* @note The arrays pointed to by @param headers and @param values will be populated with strings which are
Expand All @@ -49,9 +50,10 @@ extern "C"
* - Free all strings within the headers and values array
* - Free the array itself
*/
SAUCER_EXPORT void saucer_request_headers(saucer_request *, char ***headers, char ***values, size_t *count);
SAUCER_EXPORT void saucer_scheme_request_headers(saucer_scheme_request *, char ***headers, char ***values,
size_t *count);

typedef saucer_response *(*saucer_scheme_handler)(saucer_handle *, saucer_request *);
typedef saucer_scheme_response *(*saucer_scheme_handler)(saucer_handle *, saucer_scheme_request *);

#ifdef __cplusplus
}
Expand Down
24 changes: 13 additions & 11 deletions include/saucer/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,37 @@ extern "C"
#include "scheme.h"

#include "script.h"
#include "options.h"
#include "preferences.h"

#include <stdbool.h>

enum SAUCER_WEB_EVENT
{
SAUCER_WEB_EVENT_TITLE_CHANGED,
SAUCER_WEB_EVENT_LOAD_FINISHED,
SAUCER_WEB_EVENT_ICON_CHANGED,
SAUCER_WEB_EVENT_LOAD_STARTED,
SAUCER_WEB_EVENT_URL_CHANGED,
SAUCER_WEB_EVENT_DOM_READY,
SAUCER_WEB_EVENT_NAVIGATED,
SAUCER_WEB_EVENT_NAVIGATE,
SAUCER_WEB_EVENT_FAVICON,
SAUCER_WEB_EVENT_TITLE,
SAUCER_WEB_EVENT_LOAD,
};

enum SAUCER_STATE
{
SAUCER_STATE_STARTED,
SAUCER_STATE_FINISHED,
};

struct saucer_natives;
struct saucer_embedded_file;

/*[[sc::requires_free]]*/ SAUCER_EXPORT saucer_embedded_file *saucer_embed(saucer_stash *content, const char *mime);
SAUCER_EXPORT void saucer_embed_free(saucer_embedded_file *);

/*[[sc::requires_free]]*/ SAUCER_EXPORT saucer_handle *saucer_new(saucer_options *options);
/*[[sc::requires_free]]*/ SAUCER_EXPORT saucer_handle *saucer_new(saucer_preferences *prefs);
SAUCER_EXPORT void saucer_free(saucer_handle *);

typedef bool (*saucer_on_message)(const char *);
SAUCER_EXPORT void saucer_webview_on_message(saucer_handle *, saucer_on_message callback);

/*[[sc::requires_free]]*/ SAUCER_EXPORT saucer_natives *saucer_webview_natives(saucer_handle *);
SAUCER_EXPORT void saucer_natives_free(saucer_natives *);

/*[[sc::requires_free]]*/ SAUCER_EXPORT saucer_icon *saucer_webview_favicon(saucer_handle *);
/*[[sc::requires_free]]*/ SAUCER_EXPORT char *saucer_webview_page_title(saucer_handle *);

Expand Down
6 changes: 0 additions & 6 deletions include/saucer/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ extern "C"
SAUCER_EXPORT void saucer_window_once(saucer_handle *, SAUCER_WINDOW_EVENT event, void *callback);
SAUCER_EXPORT uint64_t saucer_window_on(saucer_handle *, SAUCER_WINDOW_EVENT event, void *callback);

typedef void (*saucer_window_callback)();
SAUCER_EXPORT void saucer_window_dispatch(saucer_handle *, saucer_window_callback callback);

SAUCER_EXPORT void saucer_window_run();
SAUCER_EXPORT void saucer_window_run_once();

#ifdef __cplusplus
}
#endif
8 changes: 8 additions & 0 deletions private/app.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include "utils/handle.hpp"
#include <saucer/app.hpp>

struct saucer_application : bindings::handle<saucer_application, std::shared_ptr<saucer::application>>
{
};
8 changes: 8 additions & 0 deletions private/navigation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include "utils/handle.hpp"
#include <saucer/navigation.hpp>

struct saucer_navigation : bindings::handle<saucer_navigation, saucer::navigation>
{
};
8 changes: 0 additions & 8 deletions private/options.hpp

This file was deleted.

8 changes: 8 additions & 0 deletions private/preferences.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include "utils/handle.hpp"
#include <saucer/window.hpp>

struct saucer_preferences : bindings::handle<saucer_preferences, saucer::preferences>
{
};
4 changes: 2 additions & 2 deletions private/scheme.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#include "utils/handle.hpp"
#include <saucer/scheme.hpp>

struct saucer_response : bindings::handle<saucer_response, saucer::scheme_handler::result_type>
struct saucer_scheme_response : bindings::handle<saucer_scheme_response, saucer::scheme::handler::result_type>
{
};

struct saucer_request : bindings::handle<saucer_request, const saucer::request *>
struct saucer_scheme_request : bindings::handle<saucer_scheme_request, const saucer::scheme::request *>
{
};
14 changes: 14 additions & 0 deletions private/utils/wrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "icon.hpp"
#include "webview.hpp"
#include "navigation.hpp"

namespace bindings
{
Expand Down Expand Up @@ -42,6 +43,19 @@ namespace bindings
};
};

template <>
struct wrap<const saucer::navigation &>
{
using type = saucer_navigation *;

template <typename U>
static auto convert(U &&data)
{
// ! User is responsible for freeing this!
return saucer_navigation::make(std::forward<U>(data));
};
};

template <typename R, typename... Ts>
struct wrap<std::function<R(Ts...)>>
{
Expand Down
5 changes: 0 additions & 5 deletions private/webview.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "webview.h"
#include "utils/handle.hpp"

#include <saucer/webview.hpp>

Expand All @@ -28,7 +27,3 @@ struct saucer_handle : saucer::webview
return m_on_message(message.c_str());
}
};

struct saucer_natives : bindings::handle<saucer_natives, saucer::natives>
{
};
Loading

0 comments on commit 10b540d

Please sign in to comment.