Skip to content

Commit

Permalink
feat(webview): wrap natives
Browse files Browse the repository at this point in the history
  • Loading branch information
Curve committed Aug 27, 2024
1 parent c9b7198 commit 6ecfd18
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/saucer/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extern "C"
SAUCER_WEB_EVENT_DOM_READY,
};

struct saucer_natives;
struct saucer_embedded_file;

/*[[sc::requires_free]]*/ SAUCER_EXPORT saucer_embedded_file *saucer_embed(saucer_stash *content, const char *mime);
Expand All @@ -36,6 +37,9 @@ extern "C"
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: 6 additions & 0 deletions private/webview.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once

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

#include <saucer/webview.hpp>

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

struct saucer_natives : bindings::handle<saucer_natives, saucer::natives>
{
};
10 changes: 10 additions & 0 deletions src/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ extern "C"
handle->m_on_message = callback;
}

saucer_natives *saucer_webview_natives(saucer_handle *handle)
{
return saucer_natives::from(handle->natives());
}

void saucer_natives_free(saucer_natives *handle)
{
delete handle;
}

saucer_icon *saucer_webview_favicon(saucer_handle *handle)
{
return saucer_icon::from(handle->favicon());
Expand Down

0 comments on commit 6ecfd18

Please sign in to comment.