railgun/main.go
2025-05-22 20:32:03 +01:00

127 lines
2.7 KiB
Go

package main
import (
"embed"
"fmt"
"io/ioutil"
"log"
"os"
"strings"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/linux"
)
//go:embed all:frontend/dist
var assets embed.FS
func main() {
if len(os.Args) > 1 {
if os.Args[1] == "--remeber" {
path, err := os.Getwd()
if err != nil {
log.Fatal("Could not get working directory", err)
return
}
remeber_path, err := GetRemeberPath()
if err != nil {
log.Fatal("Could not create/open the remeber file")
return
}
data, err := ioutil.ReadFile(remeber_path)
if err != nil {
log.Fatal("Could not read the remeber file")
return
}
if strings.Contains(string(data), fmt.Sprintf("%s\n", path)) {
log.Fatal("This path is already remebered")
return
}
f, err := os.OpenFile(remeber_path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
log.Fatal("Could not create/open the remeber file")
return
}
defer f.Close()
if _, err = f.WriteString(fmt.Sprintf("%s\n", path)); err != nil {
log.Fatal("Could not remeber", err)
}
fmt.Printf("Remebered: %s\n", path)
} else if os.Args[1] == "--forget" {
path, err := os.Getwd()
if err != nil {
log.Fatal("Could not get working directory", err)
return
}
remeber_path, err := GetRemeberPath()
if err != nil {
log.Fatal("Could not create/open the remeber file")
return
}
data, err := ioutil.ReadFile(remeber_path)
if err != nil {
log.Fatal("Could not read the remeber file")
return
}
if !strings.Contains(string(data), fmt.Sprintf("%s\n", path)) {
fmt.Printf("Forgotten*: %s\n", path)
return
}
base := strings.Split(string(data), "\n")
n_list := []string{}
for _, elm := range base {
if elm != path {
n_list = append(n_list, elm)
}
}
os.WriteFile(remeber_path, []byte(strings.Join(n_list, "\n")), 0666)
fmt.Printf("Forgotten: %s\n", path)
} else {
log.Fatal("Unkown option")
return
}
return
}
// Create an instance of the app structure
app := NewApp()
// Create application with options
err := wails.Run(&options.App{
Title: "Railgun",
Width: 800,
Height: 600,
AssetServer: &assetserver.Options{
Assets: assets,
},
BackgroundColour: &options.RGBA{R: 0, G: 0, B: 0, A: 0},
OnStartup: app.startup,
Bind: []interface{}{
app,
},
DisableResize: true,
Frameless: true,
AlwaysOnTop: true,
Linux: &linux.Options{
WindowIsTranslucent: true,
ProgramName: "Railgun",
},
})
if err != nil {
println("Error:", err.Error())
}
}