# webview
[![Build Status](https://travis-ci.org/zserge/webview.svg?branch=master)](https://travis-ci.org/zserge/webview)
[![Build status](https://ci.appveyor.com/api/projects/status/ksii33qx18d94h6v?svg=true)](https://ci.appveyor.com/project/zserge/webview)
[![GoDoc](https://godoc.org/github.com/zserge/webview?status.svg)](https://godoc.org/github.com/zserge/webview)
[![Go Report Card](https://goreportcard.com/badge/github.com/zserge/webview)](https://goreportcard.com/report/github.com/zserge/webview)
A tiny cross-platform webview library for C/C++/Golang to build modern cross-platform GUI.
It supports two-way JavaScript bindings (to call JavaScript from C/C++/Go and to call C/C++/Go from JavaScript).
It uses Cocoa/WebKit on macOS, gtk-webkit on Linux and MSHTML (IE10/11) on Windows.
<p align="center"><img alt="linux" src="examples/todo-go/screenshots/screenshots.png"></p>
## Webview for Go developers
If you are interested in writing Webview apps in C/C++ - skip to the next section.
### Getting started
Install Webview library with `go get`:
```
$ go get github.com/zserge/webview
```
Import the package and start using it:
```go
package main
import "github.com/zserge/webview"
func main() {
// Open wikipedia in a 800x600 resizable window
webview.Open("Minimal webview example",
"https://en.m.wikipedia.org/wiki/Main_Page", 800, 600, true)
}
```
It is not recommended to use `go run` (although it works perfectly fine on Linux). Use `go build` instead:
```bash
# Linux
$ go build -o webview-example && ./webview-example
# MacOS uses app bundles for GUI apps
$ mkdir -p example.app/Contents/MacOS
$ go build -o example.app/Contents/MacOS/example
$ open example.app # Or click on the app in Finder
# Windows requires special linker flags for GUI apps.
# It's also recommended to use TDM-GCC-64 compiler for CGo.
# http://tdm-gcc.tdragon.net/download
$ go build -ldflags="-H windowsgui" -o webview-example.exe
```
### API
See [godoc](https://godoc.org/github.com/zserge/webview).
### How to serve or inject the initial HTML/CSS/JavaScript into the webview?
First of all, you probably want to embed your assets (HTML/CSS/JavaScript) into the binary to have a standalone executable. Consider using [go-bindata](https://github.com/jteeuwen/go-bindata) or any other similar tools.
Now there are two major approaches to deploy the content:
* Serve HTML/CSS/JS with an embedded HTTP server
* Injecting HTML/CSS/JS via JavaScript binding API
To serve the content it is recommended to use ephemeral ports:
```go
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
log.Fatal(err)
}
defer ln.Close()
go func() {
// Set up your http server here
log.Fatal(http.Serve(ln, nil))
}()
webview.Open("Hello", "http://"+ln.Addr().String(), 400, 300, false)
```
Injecting the content via JS bindings is a bit more complicated, but feels more solid and does not expose any additional open TCP ports.
Leave `webview.Settings.URL` empty to start with a bare minimal HTML5. It will open a webview with `<div id="app"></div>` in it. Alternatively, use data URI to inject custom HTML code (don't forget to URL-encode it):
```go
const myHTML = `<!doctype html><html>....</html>`
w := webview.New(webview.Settings{
URL: `data:text/html,` + url.PathEscape(myHTML),
})
```
Keep your initial HTML short (a few kilobytes maximum).
Now you can inject more JavaScrtipt once the webview becomes ready using `webview.Eval()`. You can also inject CSS styles using JavaScript:
```go
w.Dispatch(func() {
// Inject CSS
w.Eval(fmt.Sprintf(`(function(css){
var style = document.createElement('style');
var head = document.head || document.getElementsByTagName('head')[0];
style.setAttribute('type', 'text/css');
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
head.appendChild(style);
})("%s")`, template.JSEscapeString(myStylesCSS)))
// Inject JS
w.Eval(myJSFramework)
w.Eval(myAppJS)
})
```
This works fairly well across the platforms, see `counter-go` example for more details about how make a webview app with no web server. It also demonstrates how to use ReactJS, VueJS or Picodom with webview.
### How to communicate between native Go and web UI?
You already have seen how to use `w.Eval()` to run Javascript inside the webview. There is also a way to call Go code from JavaScript.
On the low level there is a special callback, `webview.Settings.ExternalInvokeCallback` that receives a string argument. This string can be passed from JavaScript using `window.external.invoke_(someString)`.
This might seem very inconvenient, and that is why there is a dedicated `webview.Bind()` API call. It binds an existing Go object (struct or struct pointer) and creates/injects JS API for it. Now you can call JS methods and they will result in calling native Go methods. Even more, if you modify the Go object - it can be automatically serialized to JSON and passed to the web UI to keep things in sync.
Please, see `counter-go` example for more details about how to bind Go controllers to the web UI.
## Debugging and development tips
If terminal output is unavailable (e.g. if you launch app bundle on MacOS or
GUI app on Windows) you may use `webview.Debug()` and `webview.Debugf()` to
print logs. On MacOS such logs will be printed via NSLog and can be seen in the
`Console` app. On Windows they use `OutputDebugString` and can be seen using
`DebugView` app. On Linux logging is done to stderr and can be seen in the
terminal or redirected to a file.
To debug the web part of your app you may use `webview.Settings.Debug` flag. It
enables Web Inspector in WebKit and work on Linux and MacOS (use popup menu to
open the web inspector). On Windows there is no easy to way to enable
debugging, but you may include Firebug in your HTML code:
```html
<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js"></script>
```
Even though Firebug browser extension development has been stopped, Firebug
Lite is still available and just works.
## Distributing webview apps
On Linux you get a standalone executable. It will depend on GTK3 and GtkWebkit, so if you distribute your app in DEB or RPM format include those dependencies. Application icon can be specified by providing a `.desktop` file.
On MacOS you are likely to ship an app bundle. Make the following directory structure and just zip it:
```
example.app
└── Contents
├── Info.plist
├── MacOS
| └── example
└── Resources
└── example.icns
```
Here, `Info.plist` is a [property list file](https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html) and `*.icns` is a special icon format. You may convert PNG to icns [online](iconverticons.com/online/).
On Windows you probably would like to have a custom icon for your executable. It can be done by providing a resource file, compiling it and and linking with it. Typically, `windres` utility is used to compile resources.
You may find some example build scripts for all three platforms [here](https://github.com/naivesound/glitch/tree/master/dist).
Also, if you want to cross-compile your webview app - use [xgo](https://github.com/karalabe/xgo).
## Webview for C/C++ developers
### Getting started
Download [webview.h](https://raw.githubusercontent.com/zserge/webview/master/webview.h) and include it in your C/C++ code:
```c
// main.c
#include "webview.h"
#ifdef WIN32
int WINAPI WinMain(HINSTANCE hInt, HINSTANCE hPrevInst, LPSTR lpCmdLine,
int nCmdShow) {
#else
int main() {
#endif
/* Open wikipedia in a 800x600 resizable window */
webview("Minimal webview example",
"https://en.m.wikipedia.org/wiki/Main_Page", 800, 600, 1);
return 0;
}
```
Build it:
```bash
# Linux
$ cc main.c -DWEBVIEW_GTK=1 $(shell pkg-config --cflags --libs gtk+-3.0 webkitgtk
没有合适的资源?快使用搜索试试~ 我知道了~
最小的算法 音乐作曲家和合成器_go语言_代码_下载
共262个文件
go:44个
cpp:24个
h:22个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 78 浏览量
2022-06-23
03:52:23
上传
评论
收藏 4.41MB ZIP 举报
温馨提示
Glitch 是用于创建算法音乐和实时编码的最小环境。 它使用算术表达式来合成乐器并创建音乐模式。 参考 故障语法是算术表达式,很可能你还记得数学课上的它。 算术:(+ - * / %模)**(幂) 按位:(& | ^异或或按位非)<< >> 比较:(== != < <= > >=返回 1 或 0) 分组:(( ) ,分隔表达式或函数参数) 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
最小的算法 音乐作曲家和合成器_go语言_代码_下载
(262个子文件)
configure.ac 9KB
configure.ac 7KB
Makefile.am 789B
Makefile.am 685B
Makefile.am 682B
Makefile.am 655B
Makefile.am 646B
Makefile.am 444B
test.asset 15B
test.asset 15B
test.asset 15B
test.asset 15B
release-windows.bat 925B
glitch.c 24KB
glitch_test.c 14KB
main.c 335B
main.cc 3KB
codepoints 16KB
RtAudio.cpp 347KB
RtMidi.cpp 94KB
iasiothiscallresolver.cpp 23KB
rtaudiomodule.cpp 21KB
teststops.cpp 8KB
rtmidi_c.cpp 8KB
asiolist.cpp 7KB
rtaudio_c.cpp 7KB
testall.cpp 6KB
playsaw.cpp 6KB
asio.cpp 5KB
midiclock.cpp 5KB
record.cpp 5KB
playraw.cpp 4KB
duplex.cpp 4KB
sysextest.cpp 4KB
asiodrivers.cpp 3KB
audioprobe.cpp 3KB
midiout.cpp 3KB
cmidiin.cpp 3KB
qmidiin.cpp 2KB
midiprobe.cpp 2KB
rtaudio_stub.cpp 97B
rtmidi_stub.cpp 94B
codemirror.css 8KB
styles.css 7KB
roboto-mono.css 3KB
material.css 3KB
styles.css 1KB
material-icons.css 970B
styles.css 213B
audioprobe.dsp 5KB
teststops.dsp 5KB
duplex.dsp 5KB
testall.dsp 5KB
playraw.dsp 5KB
playsaw.dsp 5KB
record.dsp 5KB
sysextest.dsp 4KB
midiprobe.dsp 4KB
cmidiin.dsp 4KB
midiout.dsp 4KB
qmidiin.dsp 4KB
rtaudio.dsw 2KB
RtMidi.dsw 1KB
MaterialIcons-Regular.eot 140KB
roboto-mono-v4-greek_cyrillic_latin-300.eot 58KB
roboto-mono-v4-greek_cyrillic_latin-500.eot 56KB
roboto-mono-v4-greek_cyrillic_latin-regular.eot 56KB
roboto-mono-v4-greek_cyrillic_latin-700.eot 56KB
mcgill.gif 5KB
mcgill.gif 5KB
ccrma.gif 3KB
ccrma.gif 3KB
.gitattributes 24B
.gitignore 156B
.gitignore 90B
get_yucky.glitch 878B
drums.glitch 860B
sur_la_planche.glitch 827B
das_model.glitch 668B
arp.glitch 172B
white.glitch 131B
saw.glitch 129B
drum.glitch 111B
poly.glitch 110B
nervous.glitch 99B
right.glitch 89B
sqr.glitch 88B
42.glitch 67B
dreamy.glitch 58B
assets.go 5.75MB
assets.go 18KB
rtaudio.go 15KB
webview.go 14KB
assets.go 12KB
rtmidi.go 9KB
config.go 6KB
release.go 6KB
doc.go 5KB
toc.go 4KB
app.go 4KB
共 262 条
- 1
- 2
- 3
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- ZPM vscode 插件
- 员工注册登录原型集(xmind书写)
- SM2302NSAC-TRG-VB一款SOT23封装N-Channel场效应MOS管
- 用于订阅 google reader 的 rss 的 Chrome 扩展程序
- 电脑端浏览器插件-车牌号自编助手
- 北京邮电大学计网实验-模拟数据链路层的滑动窗口协议源码+文档说明.zip
- Java经典面试 100问,可以给面试党们去背,里面答案都是经过反复查询和推敲的 希望能帮到你们
- [练习题+答案]Harmony OS应用开发者高级认证
- WPS2019专业增强版-v11.8.2.10972-中石油定制版
- SI9959DY-T1-E3-VB一款SOP8封装2个N-Channel场效应MOS管
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功