Browse Source

Initial Commit

master
Arsen Musayelyan 8 months ago
commit
b3cd52a8c7
  1. 3
      .gitignore
  2. 4
      .gitm.toml
  3. 9
      Makefile
  4. 4
      README.md
  5. 44
      cmd/webview-permafrost/main.go
  6. 243
      create.go
  7. BIN
      default.png
  8. 12
      go.mod
  9. 102
      go.sum
  10. 38
      logging.go
  11. 94
      main.go
  12. 7
      permafrost.desktop
  13. 98
      remove.go
  14. 10
      tmpl.go

3
.gitignore

@ -0,0 +1,3 @@
.idea/
/webview-permafrost
/permafrost

4
.gitm.toml

@ -0,0 +1,4 @@
[repos]
origin = "ssh://git@192.168.100.62:2222/Arsen6331/permafrost.git"
gitlab = "git@gitlab.com:moussaelianarsen/permafrost.git"
github = "git@github.com:Arsen6331/permafrost.git"

9
Makefile

@ -0,0 +1,9 @@
all:
go build
go build ./cmd/webview-permafrost
install:
install -Dm755 permafrost $(PREFIX)/usr/bin/permafrost
install -Dm755 webview-permafrost $(PREFIX)/usr/bin/webview-permafrost
install -Dm644 permafrost.desktop $(PREFIX)/usr/share/applications/permafrost.desktop
install -Dm644 default.png $(PREFIX)/usr/share/pixmaps/permafrost.png

4
README.md

@ -0,0 +1,4 @@
# Permafrost
Lightweight single-site browser generator using Webview or Chrome/Chromium.
### Usage

44
cmd/webview-permafrost/main.go

@ -0,0 +1,44 @@
package main
import (
flag "github.com/spf13/pflag"
"github.com/webview/webview"
"github.com/zserge/lorca"
"os"
)
func main() {
url := flag.StringP("url", "u", "https://www.arsenm.dev", "URL to open in webview")
debug := flag.BoolP("debug", "d", false, "Enable webview debug mode")
width := flag.IntP("width", "w", 800, "Width of webview window")
height := flag.IntP("height", "h", 600, "Height of webview window")
chrome := flag.Bool("chrome", false, "Use chrome devtools protocol via lorca instead of webview")
flag.Parse()
if *chrome {
// If chrome does not exist
if lorca.LocateChrome() == "" {
// Display download prompt
lorca.PromptDownload()
// Exit with code 1
os.Exit(1)
}
// Create new lorca UI
l, _ := lorca.New(*url, "", *width, *height)
defer l.Close()
// Wait until window closed
<-l.Done()
} else {
// Create new webview
w := webview.New(*debug)
defer w.Destroy()
// Set title of webview window
w.SetTitle("WebView SSB")
// Set window size
w.SetSize(*width, *height, webview.HintNone)
// Navigate to specified URL
w.Navigate(*url)
// Run app
w.Run()
}
}

243
create.go

@ -0,0 +1,243 @@
package main
import (
"bytes"
_ "embed"
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/storage"
"fyne.io/fyne/v2/widget"
"github.com/mat/besticon/ico"
"image"
"image/color"
"image/png"
"io"
"net/http"
"net/url"
"os"
"path/filepath"
"strings"
)
//go:embed default.png
var defLogo []byte
func createTab(window fyne.Window) *fyne.Container {
// Create entry field for name of SSB
ssbName := widget.NewEntry()
ssbName.SetPlaceHolder("App Name")
// Create entry field for URL of SSB
ssbURL := widget.NewEntry()
ssbURL.SetPlaceHolder("App URL")
// Create dropdown menu for category in desktop file
category := widget.NewSelectEntry([]string{
"AudioVideo",
"Audio",
"Video",
"Development",
"Education",
"Game",
"Graphics",
"Network",
"Office",
"Settings",
"System",
"Utility",
})
category.PlaceHolder = "Category"
// Get default logo and decode as png
img, err := png.Decode(bytes.NewReader(defLogo))
if err != nil {
errDisp(true, err, "Error decoding default logo", window)
}
// Get canvas image from png
defaultIcon := canvas.NewImageFromImage(img)
// Create new container for icon with placeholder line
iconContainer := container.NewMax(canvas.NewLine(color.Black))
// Set default icon in container
setIcon(defaultIcon, iconContainer)
// Create image selection dialog
selectImg := dialog.NewFileOpen(func(file fyne.URIReadCloser, err error) {
// Close file at end of function
defer file.Close()
if err != nil {
errDisp(true, err, "Error opening file", window)
}
// If no file selected, stop further execution of function
if file == nil {
return
}
// Get image from file reader
icon := canvas.NewImageFromReader(file, file.URI().Name())
setIcon(icon, iconContainer)
}, window)
// Create filter constrained to images
selectImg.SetFilter(storage.NewMimeTypeFileFilter([]string{"image/*"}))
// Create button to use favicon as icon
faviconBtn := widget.NewButton("Use favicon", func() {
// Attempt to parse URL
uri, err := url.ParseRequestURI(ssbURL.Text)
if err != nil {
errDisp(true, err, "Error parsing URL. Note that the scheme (https://) is required.", window)
return
}
// Attempt to get favicon using DuckDuckGo API
res, err := http.Get(fmt.Sprintf("https://external-content.duckduckgo.com/ip3/%s.ico", uri.Host))
if err != nil {
errDisp(true, err, "Error getting favicon via DuckDuckGo API", window)
return
}
defer res.Body.Close()
// Attempt to decode data as ico file
favicon, err := ico.Decode(res.Body)
if err != nil {
errDisp(true, err, "Error decoding ico file", window)
return
}
// Get new image from decoded data
icon := canvas.NewImageFromImage(favicon)
setIcon(icon, iconContainer)
})
// Create vertical container
col := container.NewVBox(
category,
widget.NewButton("Select icon", selectImg.Show),
faviconBtn,
)
// Use home directory to get icon path
iconDir := filepath.Join(home, ".config", name, "icons")
useChrome := widget.NewCheck("Use Chrome (not isolated)", nil)
// Create new button that creates SSB
createBtn := widget.NewButton("Create", func() {
// Attempt to create SSB
err := createSSB(ssbName.Text, ssbURL.Text, category.Text, useChrome.Checked, iconContainer.Objects[0].(*canvas.Image).Image)
if err != nil {
errDisp(true, err, "Error creating SSB", window)
}
refreshRmBtns(window, iconDir, rmBtns)
ssbName.SetText("")
ssbURL.SetText("")
category.SetText("")
useChrome.SetChecked(false)
setIcon(defaultIcon, iconContainer)
})
// Create new vertical container
content := container.New(layout.NewVBoxLayout(),
ssbName,
ssbURL,
// Create dual-column container to house icon and fields
container.NewGridWithColumns(2,
container.NewVBox(
container.NewCenter(widget.NewLabel("Icon")),
iconContainer,
useChrome,
),
col,
),
// Add expanding spacer
layout.NewSpacer(),
createBtn,
)
// Return base container
return content
}
func setIcon(img *canvas.Image, logoLayout *fyne.Container) {
// Expand image keeping aspect ratio
img.FillMode = canvas.ImageFillContain
// Set minimum image size to 50x50
img.SetMinSize(fyne.NewSize(50, 50))
// Replace image in layout
logoLayout.Objects[0] = img
// Refresh layout (update changes)
logoLayout.Refresh()
}
func createSSB(ssbName, uri, category string, useChrome bool, icon image.Image) error {
// Parse provided URL for validity
_, err := url.ParseRequestURI(uri)
if err != nil {
return err
}
// Use home directory to get various paths
configDir := filepath.Join(home, ".config", name)
iconDir := filepath.Join(configDir, "icons", ssbName)
desktopDir := filepath.Join(home, ".local", "share", "applications")
// Create paths if nonexistent
err = makeDirs(configDir, iconDir, desktopDir)
if err != nil {
return err
}
// Get paths to resources
iconPath := filepath.Join(iconDir, "icon.png")
desktopPath := filepath.Join(desktopDir, ssbName+".desktop")
// Create icon file
iconFile, err := os.Create(iconPath)
if err != nil {
return err
}
// Encode icon as png, writing to file
err = png.Encode(iconFile, icon)
if err != nil {
return err
}
iconFile.Close()
if useChrome {
uri += " --chrome"
}
// Expand desktop file template with provided data
desktopStr := fmt.Sprintf(DesktopTemplate,
ssbName,
iconPath,
uri,
category,
)
// Create new executable desktop file
desktopFile, err := os.OpenFile(desktopPath, os.O_CREATE|os.O_RDWR, 0755)
if err != nil {
return err
}
// Copy expanded desktop file template to file
_, err = io.Copy(desktopFile, strings.NewReader(desktopStr))
if err != nil {
return err
}
desktopFile.Close()
return nil
}
// Make all directories provided if they do not exist
func makeDirs(dirs ...string) error {
// For each directory
for _, dir := range dirs {
// Create directory and parents if required
err := os.MkdirAll(dir, 0755)
if err != nil {
return err
}
}
return nil
}

BIN
default.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

12
go.mod

@ -0,0 +1,12 @@
module permafrost
go 1.16
require (
fyne.io/fyne/v2 v2.0.3
github.com/mat/besticon v3.12.0+incompatible
github.com/rs/zerolog v1.22.0
github.com/spf13/pflag v1.0.3
github.com/webview/webview v0.0.0-20210330151455-f540d88dde4e
github.com/zserge/lorca v0.1.10
)

102
go.sum

@ -0,0 +1,102 @@
fyne.io/fyne/v2 v2.0.3 h1:qzd2uLLrAVrNeqnLY44QZCsMxZwjoo1my+lMzHicMXY=
fyne.io/fyne/v2 v2.0.3/go.mod h1:nNpgL7sZkDVLraGtQII2ArNRnnl6kHup/KfQRxIhbvs=
github.com/Kodeworks/golang-image-ico v0.0.0-20141118225523-73f0f4cfade9/go.mod h1:7uhhqiBaR4CpN0k9rMjOtjpcfGd6DG2m04zQxKnWQ0I=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3 h1:FDqhDm7pcsLhhWl1QtD8vlzI4mm59llRvNzrFg6/LAA=
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3/go.mod h1:CzM2G82Q9BDUvMTGHnXf/6OExw/Dz2ivDj48nVg7Lg8=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fyne-io/mobile v0.1.3-0.20210412090810-650a3139866a h1:3TAJhl8vXyli0tooKB0vd6gLCyBdWL4QEYbDoJpHEZk=
github.com/fyne-io/mobile v0.1.3-0.20210412090810-650a3139866a/go.mod h1:/kOrWrZB6sasLbEy2JIvr4arEzQTXBTZGb3Y96yWbHY=
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7 h1:SCYMcCJ89LjRGwEa0tRluNRiMjZHalQZrVrvTbPh+qw=
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7/go.mod h1:482civXOzJJCPzJ4ZOX/pwvXBWSnzD4OKMdH4ClKGbk=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb h1:T6gaWBvRzJjuOrdCtg8fXXjKai2xSDqWTcKFUPuw8Tw=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20210410170116-ea3d685f79fb/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/godbus/dbus/v5 v5.0.4 h1:9349emZab16e7zQvpmsbtjc18ykshndd8y2PG3sgJbA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff h1:W71vTCKoxtdXgnm1ECDFkfQnpdqAO00zzGXLA5yaEX8=
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff/go.mod h1:wfqRWLHRBsRgkp5dmbG56SA0DmVtwrF5N3oPdI8t+Aw=
github.com/jackmordaunt/icns v0.0.0-20181231085925-4f16af745526/go.mod h1:UQkeMHVoNcyXYq9otUupF7/h/2tmHlhrS2zw7ZVvUqc=
github.com/josephspurrier/goversioninfo v0.0.0-20200309025242-14b0ab84c6ca/go.mod h1:eJTEwMjXb7kZ633hO3Ln9mBUCOjX2+FlTljvpl9SYdE=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lucor/goinfo v0.0.0-20200401173949-526b5363a13a/go.mod h1:ORP3/rB5IsulLEBwQZCJyyV6niqmI7P4EWSmkug+1Ng=
github.com/mat/besticon v3.12.0+incompatible h1:1KTD6wisfjfnX+fk9Kx/6VEZL+MAW1LhCkL9Q47H9Bg=
github.com/mat/besticon v3.12.0+incompatible/go.mod h1:mA1auQYHt6CW5e7L9HJLmqVQC8SzNk2gVwouO0AbiEU=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.22.0 h1:XrVUjV4K+izZpKXZHlPrYQiDtmdGiCylnT4i43AAWxg=
github.com/rs/zerolog v1.22.0/go.mod h1:ZPhntP/xmq1nnND05hhpAh2QMhSsA4UN3MGZ6O2J3hM=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564 h1:HunZiaEKNGVdhTRQOVpMmj5MQnGnv+e8uZNu3xFLgyM=
github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564/go.mod h1:afMbS0qvv1m5tfENCwnOdZGOF8RGR/FsZ7bvBxQGZG4=
github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 h1:m59mIOBO4kfcNCEzJNy71UkeF4XIx2EVmL9KLwDQdmM=
github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9/go.mod h1:mvWM0+15UqyrFKqdRjY6LuAVJR0HOVhJlEgZ5JWtSWU=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/webview/webview v0.0.0-20210330151455-f540d88dde4e h1:z780M7mCrdt6KiICeW9SGirvQjxDlrVU+n99FO93nbI=
github.com/webview/webview v0.0.0-20210330151455-f540d88dde4e/go.mod h1:rpXAuuHgyEJb6kXcXldlkOjU6y4x+YcASKKXJNUhh0Y=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zserge/lorca v0.1.10 h1:f/xBJ3D3ipcVRCcvN8XqZnpoKcOXV8I4vwqlFyw7ruc=
github.com/zserge/lorca v0.1.10/go.mod h1:bVmnIbIRlOcoV285KIRSe4bUABKi7R7384Ycuum6e4A=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 h1:6WW6V3x1P/jokJBpRQYUJnMHRP6isStQwCozxnU7XQw=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200720211630-cb9d2d5c5666/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190808195139-e713427fea3f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200328031815-3db5fc6bac03/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

38
logging.go

@ -0,0 +1,38 @@
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
"github.com/rs/zerolog"
zlog "github.com/rs/zerolog/log"
"os"
)
// Set global logger to zerolog
var log = zlog.Output(zerolog.ConsoleWriter{Out: os.Stderr})
func errDisp(gui bool, err error, msg string, window ...fyne.Window) {
// If gui is being used
if gui {
// Create new container with message label
content := container.NewVBox(
widget.NewLabel(msg),
)
if err != nil {
// Add more details dropdown with error label
content.Add(widget.NewAccordion(
widget.NewAccordionItem("More Details", widget.NewLabel(err.Error())),
))
}
// Create and show new custom dialog with container
dialog.NewCustom("Error", "Ok", content, window[0]).Show()
} else {
if err != nil {
log.Warn().Err(err).Msg(msg)
} else {
log.Warn().Msg(msg)
}
}
}

94
main.go

@ -0,0 +1,94 @@
package main
import (
"fmt"
fyneApp "fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
flag "github.com/spf13/pflag"
"image"
"os"
"runtime"
)
const name = "wvssb"
var home string
func init() {
// If not on linux, fatally log
if runtime.GOOS != "linux" {
log.Fatal().Msg("This tool only supports Linux.")
}
var err error
// Get user home directory
home, err = os.UserHomeDir()
if err != nil {
errDisp(false, err, "Error getting user home directory")
}
}
func main() {
useGui := flag.BoolP("gui", "g", false, "Use GUI (ignores all other flags)")
create := flag.BoolP("create", "c", false, "Create new SSB")
remove := flag.BoolP("remove", "r", false, "Remove an existing SSB")
ssbName := flag.StringP("name", "n", "", "Name of SSB to create or remove")
url := flag.StringP("url", "u", "", "URL of new SSB")
category := flag.StringP("category", "C", "Network", "Category of new SSB")
iconPath := flag.StringP("icon", "i", "", "Path to icon for new SSB")
chrome := flag.Bool("chrome", false, "Use chrome via lorca instead of webview")
flag.ErrHelp = fmt.Errorf("help message for %s", name)
flag.Parse()
// If --gui provided
if *useGui {
// Start GUI
initGUI()
} else {
// If --create provided
if *create {
// Open icon path provided via --icon
iconFile, err := os.Open(*iconPath)
if err != nil {
errDisp(false, err, "Error opening icon file")
}
defer iconFile.Close()
// Decode icon file into image.Image
icon, _, err := image.Decode(iconFile)
if err != nil {
errDisp(false, err, "Error decoding image from file")
}
// Attempt to create SSB using flag-provided values
err = createSSB(*ssbName, *url, *category, *chrome, icon)
if err != nil {
errDisp(false, err, "Error creating SSB")
}
} else if *remove {
// Attempt to remove ssb of name provided via --name
err := removeSSB(*ssbName)
if err != nil {
errDisp(false, err, "Error removing SSB")
}
} else {
// Show help screen
flag.Usage()
log.Fatal().Msg("Must provide --gui, --create, or --remove")
}
}
}
func initGUI() {
app := fyneApp.New()
// Create new window with title
window := app.NewWindow("Webview SSB")
// Create tab container
tabs := container.NewAppTabs(
container.NewTabItem("Create", createTab(window)),
container.NewTabItem("Remove", removeTab(window)),
)
// Put tabs at the top of the window
tabs.SetTabLocation(container.TabLocationTop)
window.SetContent(tabs)
window.ShowAndRun()
}

7
permafrost.desktop

@ -0,0 +1,7 @@
[Desktop Entry]
Name=Permafrost
Icon=/usr/share/pixmaps/permafrost.png
Type=Application
Terminal=false
Exec=permafrost --gui
Categories=Network;

98
remove.go

@ -0,0 +1,98 @@
package main
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
"os"
"path/filepath"
)
var rmBtns *fyne.Container
func removeTab(window fyne.Window) *fyne.Container {
// Use home directory to get various paths
configDir := filepath.Join(home, ".config", name)
iconDir := filepath.Join(configDir, "icons")
// Create directories if they do not exist
err := makeDirs(configDir, iconDir)
if err != nil {
errDisp(true, err, "Error creating required directories", window)
}
// Create new wrapping grid for remove buttons
rmBtns = container.NewGridWrap(fyne.NewSize(125, 75))
// Refresh remove buttons, adding any existing SSBs
refreshRmBtns(window, iconDir, rmBtns)
return rmBtns
}
func refreshRmBtns(window fyne.Window, iconDir string, rmBtns *fyne.Container) {
// Remove all objects from container
rmBtns.Objects = []fyne.CanvasObject{}
// List files in icon directory
ls, err := os.ReadDir(iconDir)
if err != nil {
errDisp(true, err, "Error listing icon directory", window)
}
for _, listing := range ls {
listingName := listing.Name()
// Get path for SSB icon
listingPath := filepath.Join(iconDir, listingName)
// Load icon from path
img, err := fyne.LoadResourceFromPath(filepath.Join(listingPath, "icon.png"))
if err != nil {
errDisp(true, err, "Error loading icon as resource", window)
}
// Create new button with icon
rmBtn := widget.NewButtonWithIcon(listingName, img, func() {
// Create and show new confirmation dialog
dialog.NewConfirm(
"Remove SSB",
fmt.Sprintf("Are you sure you want to remove %s?", listingName),
func(ok bool) {
if ok {
// Attempt to remove SSB
err = removeSSB(listingName)
if err != nil {
errDisp(true, err, "Error removing SSB", window)
}
refreshRmBtns(window, iconDir, rmBtns)
}
},
window,
).Show()
})
// Add button to container
rmBtns.Objects = append(rmBtns.Objects, rmBtn)
}
// Refresh container (update changes)
rmBtns.Refresh()
}
func removeSSB(ssbName string) error {
// Use home directory to get various paths
configDir := filepath.Join(home, ".config", name)
iconDir := filepath.Join(configDir, "icons", ssbName)
desktopDir := filepath.Join(home, ".local", "share", "applications")
// Remove icon directory
err := os.RemoveAll(iconDir)
if err != nil {
return err
}
// Remove desktop file
err = os.Remove(filepath.Join(desktopDir, ssbName+".desktop"))
if err != nil {
return err
}
return nil
}

10
tmpl.go

@ -0,0 +1,10 @@
package main
const DesktopTemplate = `#!/usr/bin/env xdg-open
[Desktop Entry]
Name=%s
Icon=%s
Type=Application
Terminal=false
Exec=webview-permafrost --url %s
Categories=%s;`
Loading…
Cancel
Save