go-astilectron

使用GO和HTML/JS/CSS构建跨平台的GUI应用程序(由Electron提供支持)。「Build cross platform GUI apps with GO and HTML/JS/CSS (powered by Electron)」

Github星跟蹤圖

go-astilectron

感谢 go-astilectron 使用 GO 和 HTML/JS/CSS 构建跨平台 GUI 应用。它是 astilectron 的官方 GO 绑定,由 Electron 提供支持。

演示

要查看一个最小的 Astilectron 应用,请查看 演示

它使用了 bootstrapbundler

如果你正在寻找一个最小化的例子,请运行 go run example/main.go -v。

真实的例子

这里有一个使用 go-astilectron 的项目列表(如果你正在使用 go-astilectron,并且希望你的项目被列在这里,请提交一个 PR)。

Bootstrap

为了方便起见,我们实现了一个 bootstrap

Bootstrap 允许你快速创建一个单窗口应用程序。

没有义务使用它,但强烈建议使用它。

如果您决定使用它,请仔细阅读文档,因为您必须以特定的方式构建您的项目。

绑定程序(Bundler)

为了方便起见,我们还是实现了一个 bundler

绑定程序允许你为每一个操作系统/体系结构组合捆绑你的应用程序,并获得一组漂亮的文件发送给你的用户。

快速启动

警告:下面的代码不处理错误的可读性。然而你应该这样做!

Import go-astilectron

要 import go-astilectron 运行:

$ go get -u github.com/asticode/go-astilectron

启动 go-astilectron

// Initialize astilectron
var a, _ = astilectron.New(log.New(os.Stderr, "", 0), astilectron.Options{
    AppName: "<your app name>",
    AppIconDefaultPath: "<your .png icon>", // If path is relative, it must be relative to the data directory
    AppIconDarwinPath:  "<your .icns icon>", // Same here
    BaseDirectoryPath: "<where you want the provisioner to install the dependencies>",
    VersionAstilectron: "<version of Astilectron to utilize such as `0.33.0`>",
    VersionElectron: "<version of Electron to utilize such as `4.0.1` | `6.1.2`>",
})
defer a.Close()
// Start astilectron
a.Start()
// Blocking pattern
a.Wait()

为了使一切正常工作,我们需要获取两个依赖关系: astilectron 和 Electron。.Start() 通过下载源码和正确设置来解决这个问题。

如果你想在二进制中嵌入源以保持一个独特的二进制,你可以使用 NewDisembedderProvisioner 函数来获取合适的 Provisioner,并通过 .SetProvisioner(p Provisioner) 将其附加到 go-astilectron 中。或者你可以使用 bootstrap 和 bundler。查看演示以了解如何使用它们。

当你试图添加你自己的应用程序图标时要注意,因为你需要2个图标:一个与 MacOSX 兼容(.icns),另一个与其他应用程序兼容(例如.png)。
如果没有提供 BaseDirectoryPath,它默认为可执行文件的目录路径。

大多数方法都是异步的,这意味着当执行这些方法时,go-astilectron 会阻塞,直到它收到一个特定的 Electron 事件或直到整体上下文被取消。这就是 .Start() 的情况,它将阻塞直到收到 app.event.ready astilectron 事件或直到整体上下文被取消。

创建一个窗口

// Create a new window
var w, _ = a.NewWindow("http://127.0.0.1:4000", &astilectron.WindowOptions{
    Center: astikit.BoolPtr(true),
    Height: astikit.IntPtr(600),
    Width:  astikit.IntPtr(600),
})
w.Create()

当创建一个窗口时,你需要指明一个URL以及位置、大小等选项。

除了 astilectron.Ptr* 方法之外,这是很直接的,所以让我解释一下。GO 在 json 编码时不做可选字段,除非你使用指针,而 Electron 可以处理可选字段。因此我添加了帮助方法来将 int、bool 和 string 转换为指针,并在发送给 Electron 的结构中使用指针。

(更多内容请参见自述文件)

特性和路线图

  • 自定义品牌(自定义应用名称、应用图标等)。
  • 窗口的基本方法(创建、显示、关闭、调整大小、最小化、最大化......)。
  • 窗口基本事件(关闭、模糊、聚焦、无响应、崩溃...)。
  • 远程消息传递(GO 和 Javascript 之间的消息)。
  • single binary distribution
  • 多屏/显示器
  • 菜单方法和事件(创建、插入、追加、弹出、点击...)。
  • bootstrap
  • 对话框(打开或保存文件,警报,...)。
  • 托盘
  • bundler
  • session
  • accelerators (shortcuts)
  • dock
  • notifications
  • loader
  • 文件方法(拖放,...)
  • 剪贴板方法
  • 电源监控事件(暂停、恢复...)。
  • 桌面捕捉器(音频和视频)
  • 窗口高级选项(添加缺少的选项)
  • 窗口高级方法(添加缺失的方法)
  • 窗口高级事件(添加缺失的事件)
  • 子窗(child windows)

掌声送给......

go-thrust,这是真棒,但不幸的是不再维护了。它启发了这个项目。


(The first version translated by vz on 2020.08.22)

主要指標

概覽
名稱與所有者asticode/go-astilectron
主編程語言Go
編程語言Go (語言數: 2)
平台Linux, Mac, Windows
許可證MIT License
所有者活动
創建於2017-04-22 07:59:15
推送於2024-02-16 13:49:55
最后一次提交2024-02-16 14:49:42
發布數48
最新版本名稱v0.30.0 (發布於 )
第一版名稱v0.1.0 (發布於 )
用户参与
星數4.9k
關注者數132
派生數342
提交數218
已啟用問題?
問題數336
打開的問題數50
拉請求數47
打開的拉請求數4
關閉的拉請求數15
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

GoReportCard
GoDoc
Travis
Coveralls

Thanks to go-astilectron build cross platform GUI apps with GO and HTML/JS/CSS. It is the official GO bindings of astilectron and is powered by Electron.

Demo

To see a minimal Astilectron app, checkout out the demo.

It uses the bootstrap and the bundler.

If you're looking for a minimalistic example, run go run example/main.go -v.

Real-life examples

Here's a list of awesome projects using go-astilectron (if you're using go-astilectron and want your project to be listed here please submit a PR):

  • go-astivid Video tools written in GO
  • GroupMatcher Program to allocate persons to groups while trying to fulfill all the given wishes as good as possible
  • ipeye-onvif ONVIF Search Tool
  • Stellite GUI Miner An easy to use GUI cryptocurrency miner for Stellite

Bootstrap

For convenience purposes, a bootstrap has been implemented.

The bootstrap allows you to quickly create a one-window application.

There's no obligation to use it, but it's strongly recommended.

If you decide to use it, read thoroughly the documentation as you'll have to structure your project in a specific way.

Bundler

Still for convenience purposes, a bundler has been implemented.

The bundler allows you to bundle your app for every os/arch combinations and get a nice set of files to send your users.

Quick start

WARNING: the code below doesn't handle errors for readibility purposes. However you SHOULD!

Import go-astilectron

To import go-astilectron run:

$ go get -u github.com/asticode/go-astilectron

Start go-astilectron

// Initialize astilectron
var a, _ = astilectron.New(log.New(os.StdErr, "", 0), astilectron.Options{
    AppName: "<your app name>",
    AppIconDefaultPath: "<your .png icon>", // If path is relative, it must be relative to the data directory
    AppIconDarwinPath:  "<your .icns icon>", // Same here
    BaseDirectoryPath: "<where you want the provisioner to install the dependencies>",
    VersionAstilectron: "<version of Astilectron to utilize such as `0.33.0`>",
    VersionElectron: "<version of Electron to utilize such as `4.0.1`