Skip to content

Commit 719dd0e

Browse files
committed
add Linux support
1 parent b53aaba commit 719dd0e

File tree

8 files changed

+107
-29
lines changed

8 files changed

+107
-29
lines changed

.github/workflows/release.yml

+56-2
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,65 @@ jobs:
5252
- name: Upload artifact
5353
uses: actions/upload-artifact@v3
5454
with:
55-
name: build
55+
name: win
5656
path: httptoolkit-desktop-go.exe
57+
58+
build-linux:
59+
runs-on: ubuntu-22.04
60+
61+
steps:
62+
- name: Install Go
63+
uses: actions/setup-go@v3
64+
with:
65+
go-version: "1.20.4"
66+
67+
- name: Checkout code
68+
uses: actions/checkout@v3
69+
70+
- uses: actions/cache@v3
71+
with:
72+
path: |
73+
~/.cache/go-build
74+
~/go/pkg/mod
75+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
76+
restore-keys: |
77+
${{ runner.os }}-go-
78+
79+
- name: Install Linux dependencies
80+
run: |
81+
sudo apt update
82+
sudo apt install libgtk-3-dev libwebkit2gtk-4.0-dev
83+
84+
- name: Build
85+
run: |
86+
go build -v -ldflags "-s -w" -o httptoolkit-desktop-go .
87+
chmod +x httptoolkit-desktop-go
88+
89+
- name: Upload artifact
90+
uses: actions/upload-artifact@v3
91+
with:
92+
name: linux
93+
path: httptoolkit-desktop-go
94+
95+
release:
96+
runs-on: ubuntu-latest
97+
needs: [build-windows, build-linux]
98+
99+
steps:
100+
- uses: actions/download-artifact@v3
101+
with:
102+
name: win
103+
path: win
57104

105+
- uses: actions/download-artifact@v3
106+
with:
107+
name: linux
108+
path: linux
109+
58110
- name: Release
59111
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v1
60112
with:
61113
name: ${{ github.ref_name }}
62-
files: httptoolkit-desktop-go.exe
114+
files: |
115+
win/httptoolkit-desktop-go.exe
116+
linux/httptoolkit-desktop-go

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# HTTP Toolkit Desktop Go
22
Unofficial desktop app for HTTP Toolkit in Go.
33

4-
Supports only Windows, because of webkit/webview lib bug on Linux https://github.com/webview/webview/issues/241
4+
- On Windows uses [Microsoft Edge WebView2](https://developer.microsoft.com/en-us/microsoft-edge/webview2/)
5+
- On Linux uses [WebKitGTK](https://webkitgtk.org/)
6+
- Debian-based: `libwebkit2gtk-4.0-37`
7+
- Fedora-based: `webkit2gtk4.0`
8+
- Arch: `webkit2gtk`

go.mod

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ module httptoolkit-desktop-go
33
go 1.20
44

55
require (
6-
github.com/harry1453/go-common-file-dialog v1.2.0
6+
github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf
77
github.com/webview/webview v0.0.0-20230415172654-8387ff8945fc
88
)
99

10-
require (
11-
github.com/go-ole/go-ole v1.2.4 // indirect
12-
github.com/google/uuid v1.1.1 // indirect
13-
)
10+
require github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf // indirect

go.sum

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
2-
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
3-
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
4-
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5-
github.com/harry1453/go-common-file-dialog v1.2.0 h1:nGr9ZIpXrKb7IUY9Or6jqt4nuPEd/I+5sH1JPMsKhaM=
6-
github.com/harry1453/go-common-file-dialog v1.2.0/go.mod h1:3zwmbo7fy+uYGyaec74mu+Z9DPg0aEt10fSjjPwfyiY=
1+
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf h1:FPsprx82rdrX2jiKyS17BH6IrTmUBYqZa/CXT4uvb+I=
2+
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf/go.mod h1:peYoMncQljjNS6tZwI9WVyQB3qZS6u79/N3mBOcnd3I=
3+
github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf h1:pCxn3BCfu8n8VUhYl4zS1BftoZoYY0J4qVF3dqAQ4aU=
4+
github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf/go.mod h1:/qNPSY91qTz/8TgHEMioAUc6q7+3SOybeKczHMXFcXw=
75
github.com/webview/webview v0.0.0-20230415172654-8387ff8945fc h1:3LWOLV/SbVjPYCARWGcRpOKP30U/I6EP1v8PSIoh1aU=
86
github.com/webview/webview v0.0.0-20230415172654-8387ff8945fc/go.mod h1:rpXAuuHgyEJb6kXcXldlkOjU6y4x+YcASKKXJNUhh0Y=

main.go

+9-12
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
"strings"
99
"time"
1010

11-
"github.com/harry1453/go-common-file-dialog/cfd"
12-
"github.com/harry1453/go-common-file-dialog/cfdutil"
11+
"github.com/sqweek/dialog"
1312
"github.com/webview/webview"
1413
)
1514

@@ -24,6 +23,7 @@ func main() {
2423
w.SetTitle("HTTP Toolkit")
2524
w.SetSize(1366, 768, webview.HintNone)
2625
w.SetHtml("Setting up server..<script>window.onload=()=>_onload()</script>")
26+
webkitFixes(w.Window())
2727

2828
w.Bind("_onload", func() {
2929
go func() {
@@ -49,16 +49,13 @@ func main() {
4949
}()
5050
})
5151

52-
//goland:noinspection ALL
53-
if platform == "win32" {
54-
w.Bind("prompt", func(_ string) string {
55-
result, err := cfdutil.ShowOpenFileDialog(cfd.DialogConfig{})
56-
if err != cfd.ErrorCancelled {
57-
fmt.Println(err)
58-
}
59-
return result
60-
})
61-
}
52+
w.Bind("prompt", func(_ string) string {
53+
result, err := dialog.File().Load()
54+
if err != nil && err != dialog.ErrCancelled {
55+
fmt.Println(err)
56+
}
57+
return result
58+
})
6259

6360
w.Run()
6461

setup_server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func extract(gzipStream io.Reader) error {
8181
return fmt.Errorf("extract: Mkdir() failed: %w", err)
8282
}
8383
case tar.TypeReg:
84-
outFile, err := os.Create(header.Name)
84+
outFile, err := os.OpenFile(header.Name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
8585
if err != nil {
8686
return fmt.Errorf("extract: Create() failed: %w", err)
8787
}

utils.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,34 @@
22

33
package main
44

5-
import "runtime"
5+
/*
6+
#cgo pkg-config: gtk+-3.0 webkit2gtk-4.0
7+
8+
#include <gtk/gtk.h>
9+
#include <webkit2/webkit2.h>
10+
11+
void webkit_fixes(void *window) {
12+
GtkWidget *wv = gtk_bin_get_child((GtkBin *) window);
13+
WebKitWebContext *ctx = webkit_web_view_get_context(WEBKIT_WEB_VIEW(wv));
14+
WebKitSecurityManager *sm = webkit_web_context_get_security_manager(ctx);
15+
webkit_security_manager_register_uri_scheme_as_secure(sm, "http");
16+
webkit_security_manager_register_uri_scheme_as_secure(sm, "ws");
17+
}
18+
*/
19+
import "C"
20+
21+
import (
22+
"runtime"
23+
"unsafe"
24+
)
625

726
const (
827
binPath = "bin/httptoolkit-server"
928
platform = runtime.GOOS
1029
)
1130

1231
func hideWindow() {}
32+
33+
func webkitFixes(window unsafe.Pointer) {
34+
C.webkit_fixes(window)
35+
}

utils_windows.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
package main
44

5-
import "syscall"
5+
import (
6+
"syscall"
7+
"unsafe"
8+
)
69

710
const (
811
binPath = "bin/httptoolkit-server.cmd"
@@ -12,3 +15,5 @@ const (
1215
func hideWindow() {
1316
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
1417
}
18+
19+
func webkitFixes(_ unsafe.Pointer) {}

0 commit comments

Comments
 (0)