├── .gitignore
├── LICENSE
├── README.md
├── config.m4
├── config.w32
├── examples
├── basic.php
├── binding.php
├── console.php
├── control-js.php
├── fixed-window.php
├── full_screen.php
├── multi-thread.php
└── remote-website.php
├── php_webview.h
├── tests
├── 001.phpt
├── 002.phpt
└── 003.phpt
├── webview.c
├── webview.ini
├── webview.stub.php
└── webview_arginfo.h
/.gitignore:
--------------------------------------------------------------------------------
1 | *.lo
2 | *.la
3 | .libs
4 | acinclude.m4
5 | aclocal.m4
6 | autom4te.cache
7 | build
8 | config.guess
9 | config.h
10 | config.h.in
11 | config.log
12 | config.nice
13 | config.status
14 | config.sub
15 | configure
16 | configure.ac
17 | configure.in
18 | include
19 | install-sh
20 | libtool
21 | ltmain.sh
22 | Makefile
23 | Makefile.fragments
24 | Makefile.global
25 | Makefile.objects
26 | missing
27 | mkinstalldirs
28 | modules
29 | php_test_results_*.txt
30 | phpt.*
31 | run-test-info.php
32 | run-tests.php
33 | tests/**/*.diff
34 | tests/**/*.out
35 | tests/**/*.php
36 | tests/**/*.exp
37 | tests/**/*.log
38 | tests/**/*.sh
39 | tests/**/*.db
40 | tests/**/*.mem
41 | tmp-php.ini
42 | *.dep
43 | .idea
44 | .vscode
45 | configure~
46 | config.h.in~
47 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Nazmul Alam
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # php-webview
2 |
3 | This is a simple PHP extension for writing simple, cross-platform GUI applications using PHP. It uses the webview library to create a small, lightweight, cross-platform application that can be used to create simple GUI applications.
4 |
5 | Internally, it uses the [webview](https://github.com/webview/webview) library.
6 |
7 | # Supported Platforms
8 |
9 | In theory, this extension should work on windows, mac & linux but only tested on linux & mac so far.
10 |
11 | # Before you start
12 | You'll need basic tools for C compilation. On mac, the gnu compiler is recommended. On windows, you can use the Visual Studio compiler.
13 |
14 | Before compiling the extension, you'll need to install the webview library. Example commands for mac are:
15 |
16 | ```bash
17 | brew install gcc git
18 | git clone https://github.com/webview/webview.git
19 | cd webview
20 | ./script/build.sh build
21 | cp build/library/libwebview.dylib /usr/local/lib
22 | cp webview.h /usr/local/include
23 | ```
24 |
25 | For linux, you can use the following commands:
26 |
27 | ```bash
28 | sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev
29 | git clone https://github.com/webview/webview.git
30 | cd webview
31 | ./script/build.sh build
32 | sudo cp build/library/libwebview.so /usr/lib
33 | sudo cp webview.h /usr/include
34 | ```
35 |
36 | If you face any issue, or you want to work in windows, please consult the [Getting Started](https://github.com/webview/webview?tab=readme-ov-file#getting-started) section of the webview library.
37 |
38 | # Installation
39 |
40 | ## Linux
41 |
42 | ```bash
43 | phpize
44 | ./configure
45 | make
46 | sudo make install
47 | ```
48 |
49 | ## Mac
50 |
51 | ```bash
52 | phpize
53 | ./configure CC=gcc-13 CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib -lwebview"
54 | make
55 | make install
56 | ```
57 |
58 | # Usage
59 |
60 | See the [webview.stub.php](webview.stub.php) file for the class signature. Also, checkout the [examples](examples) directory for some examples.
61 |
62 | # Known Issues
63 | ~~There's a few issues like some random crashes especially during the creation and destruction of the webview object.~~ When using with the [parallel](https://www.php.net/manual/en/book.parallel.php) php extension, in linux sometime it crashes while quitting the threads and in mac, it doesn't work at all with multi threading support.
64 | The installation process should also be improved. In theory, it should be possible to skip the installation of the webview library.
65 | If you face any issue, please open an issue in the repository. If you can fix it, please open a pull request.
66 |
67 | # License
68 |
69 | MIT
70 |
--------------------------------------------------------------------------------
/config.m4:
--------------------------------------------------------------------------------
1 | dnl config.m4 for extension webview
2 |
3 | dnl Comments in this file start with the string 'dnl'.
4 | dnl Remove where necessary.
5 |
6 | dnl If your extension references something external, use 'with':
7 |
8 | dnl PHP_ARG_WITH([webview],
9 | dnl [for webview support],
10 | dnl [AS_HELP_STRING([--with-webview],
11 | dnl [Include webview support])])
12 |
13 | dnl Otherwise use 'enable':
14 |
15 | PHP_ARG_ENABLE([webview],
16 | [whether to enable webview support],
17 | [AS_HELP_STRING([--enable-webview],
18 | [Enable webview support])],
19 | [no])
20 |
21 | if test "$PHP_WEBVIEW" != "no"; then
22 | dnl Write more examples of tests here...
23 |
24 | dnl Remove this code block if the library does not support pkg-config.
25 | dnl PKG_CHECK_MODULES([LIBFOO], [foo])
26 | dnl PHP_EVAL_INCLINE($LIBFOO_CFLAGS)
27 | dnl PHP_EVAL_LIBLINE($LIBFOO_LIBS, WEBVIEW_SHARED_LIBADD)
28 |
29 | dnl If you need to check for a particular library version using PKG_CHECK_MODULES,
30 | dnl you can use comparison operators. For example:
31 | dnl PKG_CHECK_MODULES([LIBFOO], [foo >= 1.2.3])
32 | dnl PKG_CHECK_MODULES([LIBFOO], [foo < 3.4])
33 | dnl PKG_CHECK_MODULES([LIBFOO], [foo = 1.2.3])
34 |
35 | dnl Remove this code block if the library supports pkg-config.
36 | dnl --with-webview -> check with-path
37 | dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
38 | dnl SEARCH_FOR="/include/webview.h" # you most likely want to change this
39 | dnl if test -r $PHP_WEBVIEW/$SEARCH_FOR; then # path given as parameter
40 | dnl WEBVIEW_DIR=$PHP_WEBVIEW
41 | dnl else # search default path list
42 | dnl AC_MSG_CHECKING([for webview files in default path])
43 | dnl for i in $SEARCH_PATH ; do
44 | dnl if test -r $i/$SEARCH_FOR; then
45 | dnl WEBVIEW_DIR=$i
46 | dnl AC_MSG_RESULT(found in $i)
47 | dnl fi
48 | dnl done
49 | dnl fi
50 | dnl
51 | dnl if test -z "$WEBVIEW_DIR"; then
52 | dnl AC_MSG_RESULT([not found])
53 | dnl AC_MSG_ERROR([Please reinstall the webview distribution])
54 | dnl fi
55 |
56 | dnl Remove this code block if the library supports pkg-config.
57 | dnl --with-webview -> add include path
58 | dnl PHP_ADD_INCLUDE($WEBVIEW_DIR/include)
59 |
60 | dnl Remove this code block if the library supports pkg-config.
61 | dnl --with-webview -> check for lib and symbol presence
62 | LIBNAME=webview # you may want to change this
63 | LIBSYMBOL=webview_create # you most likely want to change this
64 |
65 | dnl If you need to check for a particular library function (e.g. a conditional
66 | dnl or version-dependent feature) and you are using pkg-config:
67 | dnl PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL,
68 | dnl [
69 | dnl AC_DEFINE(HAVE_WEBVIEW_FEATURE, 1, [ ])
70 | dnl ],[
71 | dnl AC_MSG_ERROR([FEATURE not supported by your webview library.])
72 | dnl ], [
73 | dnl $LIBFOO_LIBS
74 | dnl ])
75 |
76 | dnl If you need to check for a particular library function (e.g. a conditional
77 | dnl or version-dependent feature) and you are not using pkg-config:
78 | PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL,
79 | [
80 | PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $WEBVIEW_DIR/$PHP_LIBDIR, WEBVIEW_SHARED_LIBADD)
81 | AC_DEFINE(HAVE_WEBVIEW_FEATURE, 1, [ ])
82 | ],[
83 | AC_MSG_ERROR([FEATURE not supported by your webview library.])
84 | ],[
85 | -L$WEBVIEW_DIR/$PHP_LIBDIR -lm
86 | ])
87 | PHP_SUBST(WEBVIEW_SHARED_LIBADD)
88 |
89 | dnl In case of no dependencies
90 | AC_DEFINE(HAVE_WEBVIEW, 1, [ Have webview support ])
91 |
92 | PHP_NEW_EXTENSION(webview, webview.c, $ext_shared)
93 | fi
94 |
--------------------------------------------------------------------------------
/config.w32:
--------------------------------------------------------------------------------
1 | ARG_ENABLE('webview', 'webview support', 'no');
2 |
3 | if (PHP_WEBVIEW != 'no') {
4 | AC_DEFINE('HAVE_WEBVIEW', 1, 'webview support enabled');
5 |
6 | EXTENSION('webview', 'webview.c', null, '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
7 | }
8 |
--------------------------------------------------------------------------------
/examples/basic.php:
--------------------------------------------------------------------------------
1 | set_title("Hello Webview");
10 | $webview->set_size(600, 450);
11 | $webview->set_html("
Hello World
");
12 |
13 | $webview->run();
14 | unset($webview); // must clear
15 |
--------------------------------------------------------------------------------
/examples/binding.php:
--------------------------------------------------------------------------------
1 | Tap me
9 |