forked from shreyassanthu77/webview_dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implemented basic dart bindings
- added webview repo - modified the wv repo to just its barebones - wrapped most of the api - Maybe not fully functional - works with example
- Loading branch information
1 parent
a5af077
commit 58bc47a
Showing
50 changed files
with
20,672 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Linux", | ||
"includePath": [ | ||
"${default}", | ||
"/usr/include/webkitgtk-4.0", | ||
"/usr/include/gtk-3.0", | ||
"/usr/include/glib-2.0", | ||
"/usr/include/libsoup-2.4", | ||
"/usr/include/cairo" | ||
], | ||
"compilerPath": "/usr/bin/gcc", | ||
"cStandard": "gnu17", | ||
"cppStandard": "gnu++14", | ||
"intelliSenseMode": "linux-gcc-x64" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import 'package:webview_dart/webview_dart.dart'; | ||
|
||
void main() { | ||
var awesome = Awesome(); | ||
print('awesome: ${awesome.isAwesome}'); | ||
final url = "https://www.google.com"; | ||
Webview(true) | ||
.setTitle("title") | ||
.setSize(1280, 800, SIzeHint.none) | ||
.navigate(url) | ||
.eval("setTimeout(() => console.log('hello'), 1000)") | ||
.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import 'dart:ffi'; | ||
import 'package:ffi/ffi.dart'; | ||
|
||
export 'dart:ffi' show nullptr; | ||
export 'package:ffi/ffi.dart' show StringUtf8Pointer; | ||
|
||
typedef WebviewLib = DynamicLibrary; | ||
typedef WindowHandle = Pointer<Void>; | ||
|
||
// Native Functions | ||
typedef NativeCreateFunction = WindowHandle Function(Int32, WindowHandle); | ||
typedef NativeDestroyFunction = Void Function(WindowHandle); | ||
typedef NativeRunFunction = Void Function(WindowHandle); | ||
typedef NativeTerminateFunction = Void Function(WindowHandle); | ||
typedef NativeSetTitleFunction = Void Function(WindowHandle, Pointer<Utf8>); | ||
typedef NativeSetSizeFunction = Void Function( | ||
WindowHandle, Int32, Int32, Int32); | ||
typedef NativeNavigateFunction = Void Function(WindowHandle, Pointer<Utf8>); | ||
typedef NativeInitFunction = Void Function(WindowHandle, Pointer<Utf8>); | ||
typedef NativeEvalFunction = Void Function(WindowHandle, Pointer<Utf8>); | ||
|
||
// darty functions | ||
typedef CreateFunction = WindowHandle Function(int, WindowHandle); | ||
typedef DestroyFunction = void Function(WindowHandle); | ||
typedef RunFunction = void Function(WindowHandle); | ||
typedef TerminateFunction = void Function(WindowHandle); | ||
typedef SetTitleFunction = void Function(WindowHandle, Pointer<Utf8>); | ||
typedef SetSizeFunction = void Function(WindowHandle, int, int, int); | ||
typedef NavigateFunction = void Function(WindowHandle, Pointer<Utf8>); | ||
typedef InitFunction = void Function(WindowHandle, Pointer<Utf8>); | ||
typedef EvalFunction = void Function(WindowHandle, Pointer<Utf8>); | ||
|
||
DynamicLibrary? _library; | ||
|
||
// lookups | ||
WebviewLib loadLibrary(String path) { | ||
try { | ||
_library ??= DynamicLibrary.open(path); | ||
} catch (e) { | ||
rethrow; | ||
} | ||
return _library!; | ||
} | ||
|
||
CreateFunction webviewCreate(DynamicLibrary webview) { | ||
return webview | ||
.lookupFunction<NativeCreateFunction, CreateFunction>("webview_create"); | ||
} | ||
|
||
DestroyFunction webviewDestroy(DynamicLibrary webview) { | ||
return webview.lookupFunction<NativeDestroyFunction, DestroyFunction>( | ||
"webview_destroy"); | ||
} | ||
|
||
RunFunction webviewRun(DynamicLibrary webview) { | ||
return webview.lookupFunction<NativeRunFunction, RunFunction>("webview_run"); | ||
} | ||
|
||
TerminateFunction webviewTerminate(DynamicLibrary webview) { | ||
return webview.lookupFunction<NativeTerminateFunction, TerminateFunction>( | ||
"webview_terminate"); | ||
} | ||
|
||
SetTitleFunction webviewSetTitle(DynamicLibrary webview) { | ||
return webview.lookupFunction<NativeSetTitleFunction, SetTitleFunction>( | ||
"webview_set_title"); | ||
} | ||
|
||
SetSizeFunction webviewSetSize(DynamicLibrary webview) { | ||
return webview.lookupFunction<NativeSetSizeFunction, SetSizeFunction>( | ||
"webview_set_size"); | ||
} | ||
|
||
NavigateFunction webviewNavigate(DynamicLibrary webview) { | ||
return webview.lookupFunction<NativeNavigateFunction, NavigateFunction>( | ||
"webview_navigate"); | ||
} | ||
|
||
InitFunction webviewInit(DynamicLibrary webview) { | ||
return webview | ||
.lookupFunction<NativeInitFunction, InitFunction>("webview_init"); | ||
} | ||
|
||
EvalFunction webviewEval(DynamicLibrary webview) { | ||
return webview | ||
.lookupFunction<NativeEvalFunction, EvalFunction>("webview_eval"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'dart:io'; | ||
|
||
import 'bindings.dart'; | ||
|
||
enum SIzeHint { none, min, max, fixed } | ||
|
||
class Webview { | ||
static final WebviewLib _lib = loadLibrary( | ||
Directory( | ||
Directory.current.path + | ||
"/webview.${Platform.isWindows ? 'dll' : Platform.isLinux ? 'so' : 'dylib'}", | ||
).absolute.path.replaceAll("\\", "/"), | ||
); | ||
static final CreateFunction _create = webviewCreate(_lib); | ||
static final DestroyFunction _destroy = webviewDestroy(_lib); | ||
static final RunFunction _run = webviewRun(_lib); | ||
static final TerminateFunction _terminate = webviewTerminate(_lib); | ||
static final SetTitleFunction _setTitle = webviewSetTitle(_lib); | ||
static final SetSizeFunction _setSize = webviewSetSize(_lib); | ||
static final NavigateFunction _navigate = webviewNavigate(_lib); | ||
static final InitFunction _init = webviewInit(_lib); | ||
static final EvalFunction _eval = webviewEval(_lib); | ||
|
||
late final WindowHandle _handle; | ||
|
||
Webview([bool debug = false]) { | ||
_handle = _create(debug ? 1 : 0, nullptr); | ||
} | ||
|
||
void terminate() { | ||
_terminate(_handle); | ||
} | ||
|
||
Webview setTitle(String title) { | ||
_setTitle(_handle, title.toNativeUtf8()); | ||
return this; | ||
} | ||
|
||
Webview setSize(final int width, final int height, | ||
[SIzeHint sIzeHint = SIzeHint.none]) { | ||
_setSize(_handle, width, height, sIzeHint.index); | ||
return this; | ||
} | ||
|
||
Webview navigate(String url) { | ||
_navigate(_handle, url.toNativeUtf8()); | ||
return this; | ||
} | ||
|
||
Webview init(String js) { | ||
_init(_handle, js.toNativeUtf8()); | ||
return this; | ||
} | ||
|
||
Webview eval(String js) { | ||
_eval(_handle, js.toNativeUtf8()); | ||
return this; | ||
} | ||
|
||
void run([bool autoDestroy = true]) { | ||
_run(_handle); | ||
if (autoDestroy) destroy(); | ||
} | ||
|
||
void destroy() { | ||
_destroy(_handle); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.h linguist-language=c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Build atrifacts | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Win32", | ||
"includePath": [ | ||
"${default}", | ||
"${workspaceFolder}/script" | ||
], | ||
"windowsSdkVersion": "10.0.19041.0", | ||
"compilerPath": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\Hostx64\\x64\\cl.exe", | ||
"cStandard": "c17", | ||
"cppStandard": "c++17", | ||
"intelliSenseMode": "windows-msvc-x64" | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Serge Zaitsev | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//bin/echo; [ $(uname) = "Darwin" ] && FLAGS="-framework Webkit" || FLAGS="$(pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0)" ; c++ "$0" $FLAGS -std=c++11 -g -o webview && ./webview ; exit | ||
// +build ignore | ||
|
||
#include "webview.h" | ||
#ifdef WIN32 | ||
int WINAPI WinMain(HINSTANCE hInt, HINSTANCE hPrevInst, LPSTR lpCmdLine, | ||
int nCmdShow) { | ||
#else | ||
int main() { | ||
#endif | ||
webview_t w = webview_create(0, NULL); | ||
webview_set_title(w, "Webview Example"); | ||
webview_set_size(w, 480, 320, WEBVIEW_HINT_NONE); | ||
webview_navigate(w, "https://en.m.wikipedia.org/wiki/Main_Page"); | ||
webview_run(w); | ||
webview_destroy(w); | ||
return 0; | ||
} |
Oops, something went wrong.