Skip to content

Commit

Permalink
add Linux support
Browse files Browse the repository at this point in the history
  • Loading branch information
Juby210 committed May 24, 2023
1 parent b53aaba commit 719dd0e
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 29 deletions.
58 changes: 56 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,65 @@ jobs:
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: build
name: win
path: httptoolkit-desktop-go.exe

build-linux:
runs-on: ubuntu-22.04

steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: "1.20.4"

- name: Checkout code
uses: actions/checkout@v3

- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install Linux dependencies
run: |
sudo apt update
sudo apt install libgtk-3-dev libwebkit2gtk-4.0-dev
- name: Build
run: |
go build -v -ldflags "-s -w" -o httptoolkit-desktop-go .
chmod +x httptoolkit-desktop-go
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: linux
path: httptoolkit-desktop-go

release:
runs-on: ubuntu-latest
needs: [build-windows, build-linux]

steps:
- uses: actions/download-artifact@v3
with:
name: win
path: win

- uses: actions/download-artifact@v3
with:
name: linux
path: linux

- name: Release
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v1
with:
name: ${{ github.ref_name }}
files: httptoolkit-desktop-go.exe
files: |
win/httptoolkit-desktop-go.exe
linux/httptoolkit-desktop-go
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# HTTP Toolkit Desktop Go
Unofficial desktop app for HTTP Toolkit in Go.

Supports only Windows, because of webkit/webview lib bug on Linux https://github.com/webview/webview/issues/241
- On Windows uses [Microsoft Edge WebView2](https://developer.microsoft.com/en-us/microsoft-edge/webview2/)
- On Linux uses [WebKitGTK](https://webkitgtk.org/)
- Debian-based: `libwebkit2gtk-4.0-37`
- Fedora-based: `webkit2gtk4.0`
- Arch: `webkit2gtk`
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ module httptoolkit-desktop-go
go 1.20

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

require (
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/google/uuid v1.1.1 // indirect
)
require github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf // indirect
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
github.com/go-ole/go-ole v1.2.4 h1:nNBDSCOigTSiarFpYE9J/KtEA1IOW4CNeqT9TQDqCxI=
github.com/go-ole/go-ole v1.2.4/go.mod h1:XCwSNxSkXRo4vlyPy93sltvi/qJq0jqQhjqQNIwKuxM=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/harry1453/go-common-file-dialog v1.2.0 h1:nGr9ZIpXrKb7IUY9Or6jqt4nuPEd/I+5sH1JPMsKhaM=
github.com/harry1453/go-common-file-dialog v1.2.0/go.mod h1:3zwmbo7fy+uYGyaec74mu+Z9DPg0aEt10fSjjPwfyiY=
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf h1:FPsprx82rdrX2jiKyS17BH6IrTmUBYqZa/CXT4uvb+I=
github.com/TheTitanrain/w32 v0.0.0-20180517000239-4f5cfb03fabf/go.mod h1:peYoMncQljjNS6tZwI9WVyQB3qZS6u79/N3mBOcnd3I=
github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf h1:pCxn3BCfu8n8VUhYl4zS1BftoZoYY0J4qVF3dqAQ4aU=
github.com/sqweek/dialog v0.0.0-20220809060634-e981b270ebbf/go.mod h1:/qNPSY91qTz/8TgHEMioAUc6q7+3SOybeKczHMXFcXw=
github.com/webview/webview v0.0.0-20230415172654-8387ff8945fc h1:3LWOLV/SbVjPYCARWGcRpOKP30U/I6EP1v8PSIoh1aU=
github.com/webview/webview v0.0.0-20230415172654-8387ff8945fc/go.mod h1:rpXAuuHgyEJb6kXcXldlkOjU6y4x+YcASKKXJNUhh0Y=
21 changes: 9 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"strings"
"time"

"github.com/harry1453/go-common-file-dialog/cfd"
"github.com/harry1453/go-common-file-dialog/cfdutil"
"github.com/sqweek/dialog"
"github.com/webview/webview"
)

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

w.Bind("_onload", func() {
go func() {
Expand All @@ -49,16 +49,13 @@ func main() {
}()
})

//goland:noinspection ALL
if platform == "win32" {
w.Bind("prompt", func(_ string) string {
result, err := cfdutil.ShowOpenFileDialog(cfd.DialogConfig{})
if err != cfd.ErrorCancelled {
fmt.Println(err)
}
return result
})
}
w.Bind("prompt", func(_ string) string {
result, err := dialog.File().Load()
if err != nil && err != dialog.ErrCancelled {
fmt.Println(err)
}
return result
})

w.Run()

Expand Down
2 changes: 1 addition & 1 deletion setup_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func extract(gzipStream io.Reader) error {
return fmt.Errorf("extract: Mkdir() failed: %w", err)
}
case tar.TypeReg:
outFile, err := os.Create(header.Name)
outFile, err := os.OpenFile(header.Name, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
if err != nil {
return fmt.Errorf("extract: Create() failed: %w", err)
}
Expand Down
25 changes: 24 additions & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,34 @@

package main

import "runtime"
/*
#cgo pkg-config: gtk+-3.0 webkit2gtk-4.0
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>
void webkit_fixes(void *window) {
GtkWidget *wv = gtk_bin_get_child((GtkBin *) window);
WebKitWebContext *ctx = webkit_web_view_get_context(WEBKIT_WEB_VIEW(wv));
WebKitSecurityManager *sm = webkit_web_context_get_security_manager(ctx);
webkit_security_manager_register_uri_scheme_as_secure(sm, "http");
webkit_security_manager_register_uri_scheme_as_secure(sm, "ws");
}
*/
import "C"

import (
"runtime"
"unsafe"
)

const (
binPath = "bin/httptoolkit-server"
platform = runtime.GOOS
)

func hideWindow() {}

func webkitFixes(window unsafe.Pointer) {
C.webkit_fixes(window)
}
7 changes: 6 additions & 1 deletion utils_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

package main

import "syscall"
import (
"syscall"
"unsafe"
)

const (
binPath = "bin/httptoolkit-server.cmd"
Expand All @@ -12,3 +15,5 @@ const (
func hideWindow() {
cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
}

func webkitFixes(_ unsafe.Pointer) {}

0 comments on commit 719dd0e

Please sign in to comment.