Skip to content

Commit

Permalink
feat: add wails example (#56)
Browse files Browse the repository at this point in the history
* first commit

* works for me

* fix EOF

* add proper wails example

* ci: install go and wails cli

* fix deno example

* install webkit2gtk-4.0 for wails

* try with a 32x32 png

* Update examples/wails/Packager.toml

Co-authored-by: Fabian-Lars <[email protected]>

---------

Co-authored-by: amr-crabnebula <[email protected]>
Co-authored-by: Fabian-Lars <[email protected]>
  • Loading branch information
3 people committed Nov 15, 2023
1 parent 20027d0 commit 64f57f7
Show file tree
Hide file tree
Showing 35 changed files with 1,324 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ jobs:
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y webkit2gtk-4.1 libayatana-appindicator3-dev
sudo apt-get install -y webkit2gtk-4.1 webkit2gtk-4.0 libayatana-appindicator3-dev
- uses: dtolnay/rust-toolchain@stable
- uses: actions/setup-go@v4
- uses: denoland/setup-deno@v1
with:
deno-version: v1.36 # lock this for now until `deno compile --output` is fixed
- uses: Swatinem/rust-cache@v2
- run: go install github.com/wailsapp/wails/v2/cmd/wails@latest
- run: cargo install tauri-cli --version "2.0.0-alpha.10" --locked
- run: cargo install dioxus-cli --locked
- run: cargo r --package cargo-packager -- signer generate --password '123' --path ./signing-key -vvv
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y webkit2gtk-4.1 libayatana-appindicator3-dev
sudo apt-get install -y webkit2gtk-4.1 libayatana-appindicator3-dev
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: cargo test --workspace --lib --bins --tests --benches --all-features --no-fail-fast
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target
.idea
.idea
.DS_Store
/node_modules
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = ["crates/*", "examples/*"]
exclude = ["examples/deno"]
exclude = ["examples/deno", "examples/wails"]
resolver = "2"

[workspace.package]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Examples list (non-exhaustive):
- [`egui`](./examples/egui/)
- [`deno`](./examples/deno/)
- [`slint`](./examples/slint/)
- [`wails`](./examples/wails)

## Library

Expand Down
4 changes: 2 additions & 2 deletions examples/deno/packager.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"$schema": "../../crates/config/schema.json",
"$schema": "../../crates/packager/schema.json",
"name": "deno-example",
"outDir": "./dist",
"beforePackagingCommand": "deno compile deno-example.js --output dist/deno-example",
"beforePackagingCommand": "deno compile --output dist/deno-example deno-example.js",
"productName": "Deno example",
"version": "0.0.0",
"identifier": "com.deno.example",
Expand Down
3 changes: 3 additions & 0 deletions examples/wails/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/bin
node_modules
frontend/dist
Binary file added examples/wails/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions examples/wails/Packager.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name = "wails-example"
before-packaging-command = "wails build -noPackage"
out-dir = "./build/bin"
version = "0.0.0"
product-name = "Wails example"
identifier = "com.wails.example"
resources = ["Cargo.toml", "src", "32x32.png"]
icons = ["32x32.png"]
binaries = [{ filename = "wails_example", main = true }]

[deb]
depends = ["libgtk-3-0", "libwebkit2gtk-4.1-0"]

[appimage]
libs = [
"WebKitNetworkProcess",
"WebKitWebProcess",
"libwebkit2gtkinjectedbundle.so",
]

[appimage.linuxdeploy-plugins]
"gtk" = "https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh"

[nsis]
appdata-paths = ["$LOCALAPPDATA/$IDENTIFIER"]
preinstall-section = """
; Setup messages
; English
LangString webview2AbortError ${LANG_ENGLISH} "Failed to install WebView2! The app can't run without it. Try restarting the installer."
LangString webview2DownloadError ${LANG_ENGLISH} "Error: Downloading WebView2 Failed - $0"
LangString webview2DownloadSuccess ${LANG_ENGLISH} "WebView2 bootstrapper downloaded successfully"
LangString webview2Downloading ${LANG_ENGLISH} "Downloading WebView2 bootstrapper..."
LangString webview2InstallError ${LANG_ENGLISH} "Error: Installing WebView2 failed with exit code $1"
LangString webview2InstallSuccess ${LANG_ENGLISH} "WebView2 installed successfully"
Section PreInstall
; Check if Webview2 is already installed and skip this section
${If} ${RunningX64}
ReadRegStr $4 HKLM "SOFTWARE\\WOW6432Node\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
${Else}
ReadRegStr $4 HKLM "SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
${EndIf}
ReadRegStr $5 HKCU "SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}" "pv"
StrCmp $4 "" 0 webview2_done
StrCmp $5 "" 0 webview2_done
Delete "$TEMP\\MicrosoftEdgeWebview2Setup.exe"
DetailPrint "$(webview2Downloading)"
nsis_tauri_utils::download "https://go.microsoft.com/fwlink/p/?LinkId=2124703" "$TEMP\\MicrosoftEdgeWebview2Setup.exe"
Pop $0
${If} $0 == 0
DetailPrint "$(webview2DownloadSuccess)"
${Else}
DetailPrint "$(webview2DownloadError)"
Abort "$(webview2AbortError)"
${EndIf}
StrCpy $6 "$TEMP\\MicrosoftEdgeWebview2Setup.exe"
DetailPrint "$(installingWebview2)"
; $6 holds the path to the webview2 installer
ExecWait "$6 /install" $1
${If} $1 == 0
DetailPrint "$(webview2InstallSuccess)"
${Else}
DetailPrint "$(webview2InstallError)"
Abort "$(webview2AbortError)"
${EndIf}
webview2_done:
SectionEnd
"""
14 changes: 14 additions & 0 deletions examples/wails/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Wails example

1. install The Go programming language: https://go.dev/dl/
2. install `wails` CLI first

```sh
go install github.com/wailsapp/wails/v2/cmd/wails@latest
```

3. package the app

```sh
cargo r -p cargo-packager -- -p wails-example --release
```
27 changes: 27 additions & 0 deletions examples/wails/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"context"
"fmt"
)

// App struct
type App struct {
ctx context.Context
}

// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}

// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}

// Greet returns a greeting for the given name
func (a *App) Greet(name string) string {
return fmt.Sprintf("Hello %s, It's show time!", name)
}
29 changes: 29 additions & 0 deletions examples/wails/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env -S pkgx +npm +go +gum +jq zsh
# ^^ curl https://pkgx.sh | sh
# ^^ pkgx makes all those tools (including bash!) available to the script
# no packages are installed; your system remains pristine

go install github.com/wailsapp/wails/v2/cmd/wails@latest

# works on mac
export PATH="$HOME/go/bin:$PATH"

if [ -d wails_example ]; then
cd wails_example
elif [ ! -d .git ] && gum confirm 'Create new wails app?'; then
wails init -n wails_example -t vanilla
cd wails_example
fi

# probably not resilient if wails changes
wails build | grep "Built" | cut -d " " -f 2 | read buildpath

echo "Your binary is available at ${buildpath}"
mkdir -p ./dist

# I am stupid why doesn't this work
# cp ${buildpath} ./dist/
cp ./build/bin/wails_example.app/Contents/MacOS/wails_example ./dist

# also doesn't work here, sadly
# cargo r -p cargo-packager -- -p wails-example --release -c packager.json
35 changes: 35 additions & 0 deletions examples/wails/build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Build Directory

The build directory is used to house all the build files and assets for your application.

The structure is:

* bin - Output directory
* darwin - macOS specific files
* windows - Windows specific files

## Mac

The `darwin` directory holds files specific to Mac builds.
These may be customised and used as part of the build. To return these files to the default state, simply delete them
and
build with `wails build`.

The directory contains the following files:

- `Info.plist` - the main plist file used for Mac builds. It is used when building using `wails build`.
- `Info.dev.plist` - same as the main plist file but used when building using `wails dev`.

## Windows

The `windows` directory contains the manifest and rc files used when building with `wails build`.
These may be customised for your application. To return these files to the default state, simply delete them and
build with `wails build`.

- `icon.ico` - The icon used for the application. This is used when building using `wails build`. If you wish to
use a different icon, simply replace this file with your own. If it is missing, a new `icon.ico` file
will be created using the `appicon.png` file in the build directory.
- `installer/*` - The files used to create the Windows installer. These are used when building using `wails build`.
- `info.json` - Application details used for Windows builds. The data here will be used by the Windows installer,
as well as the application itself (right click the exe -> properties -> details)
- `wails.exe.manifest` - The main application manifest file.
Binary file added examples/wails/build/appicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions examples/wails/build/darwin/Info.dev.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleName</key>
<string>{{.Info.ProductName}}</string>
<key>CFBundleExecutable</key>
<string>{{.Name}}</string>
<key>CFBundleIdentifier</key>
<string>com.wails.{{.Name}}</string>
<key>CFBundleVersion</key>
<string>{{.Info.ProductVersion}}</string>
<key>CFBundleGetInfoString</key>
<string>{{.Info.Comments}}</string>
<key>CFBundleShortVersionString</key>
<string>{{.Info.ProductVersion}}</string>
<key>CFBundleIconFile</key>
<string>iconfile</string>
<key>LSMinimumSystemVersion</key>
<string>10.13.0</string>
<key>NSHighResolutionCapable</key>
<string>true</string>
<key>NSHumanReadableCopyright</key>
<string>{{.Info.Copyright}}</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
</dict>
</plist>
27 changes: 27 additions & 0 deletions examples/wails/build/darwin/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleName</key>
<string>{{.Info.ProductName}}</string>
<key>CFBundleExecutable</key>
<string>{{.Name}}</string>
<key>CFBundleIdentifier</key>
<string>com.wails.{{.Name}}</string>
<key>CFBundleVersion</key>
<string>{{.Info.ProductVersion}}</string>
<key>CFBundleGetInfoString</key>
<string>{{.Info.Comments}}</string>
<key>CFBundleShortVersionString</key>
<string>{{.Info.ProductVersion}}</string>
<key>CFBundleIconFile</key>
<string>iconfile</string>
<key>LSMinimumSystemVersion</key>
<string>10.13.0</string>
<key>NSHighResolutionCapable</key>
<string>true</string>
<key>NSHumanReadableCopyright</key>
<string>{{.Info.Copyright}}</string>
</dict>
</plist>
Binary file added examples/wails/build/windows/icon.ico
Binary file not shown.
15 changes: 15 additions & 0 deletions examples/wails/build/windows/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"fixed": {
"file_version": "{{.Info.ProductVersion}}"
},
"info": {
"0000": {
"ProductVersion": "{{.Info.ProductVersion}}",
"CompanyName": "{{.Info.CompanyName}}",
"FileDescription": "{{.Info.ProductName}}",
"LegalCopyright": "{{.Info.Copyright}}",
"ProductName": "{{.Info.ProductName}}",
"Comments": "{{.Info.Comments}}"
}
}
}
Loading

0 comments on commit 64f57f7

Please sign in to comment.