Skip to content

Commit

Permalink
Reorganise Go code into utils package
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Nov 24, 2023
1 parent 765898a commit 035f1d3
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

_ "embed"

"github.com/retrixe/writer/utils"
"github.com/sqweek/dialog"
"github.com/webview/webview"
)
Expand Down Expand Up @@ -53,16 +54,16 @@ func main() {
println("Invalid usage: writer flash <file> <destination> (--use-system-dd)")
os.Exit(1)
}
if err := UnmountDevice(os.Args[3]); err != nil {
if err := utils.UnmountDevice(os.Args[3]); err != nil {
log.Println(err)
if !strings.HasSuffix(os.Args[3], "debug.iso") {
os.Exit(1)
}
}
if len(os.Args) > 4 && os.Args[4] == "--use-system-dd" {
RunDd(os.Args[2], os.Args[3])
utils.RunDd(os.Args[2], os.Args[3])
} else {
FlashFileToBlockDevice(os.Args[2], os.Args[3])
utils.FlashFileToBlockDevice(os.Args[2], os.Args[3])
}
return
}
Expand All @@ -83,15 +84,15 @@ func main() {

// Bind a function to request refresh of devices attached.
w.Bind("refreshDevices", func() {
devices, err := GetDevices()
devices, err := utils.GetDevices()
if err != nil {
w.Eval("setDialogReact(" + ParseToJsString("Error: "+err.Error()) + ")")
return
}
if os.Getenv("DEBUG") == "true" {
homedir, err := os.UserHomeDir()
if err == nil {
devices = append(devices, Device{
devices = append(devices, utils.Device{
Name: filepath.Join(homedir, "debug.iso"),
Model: "Write to debug ISO in home dir",
Bytes: 10000000000,
Expand Down Expand Up @@ -154,7 +155,7 @@ func main() {
} else {
w.Eval("setFileSizeReact(" + strconv.Itoa(int(stat.Size())) + ")")
}
channel, stdin, err := CopyConvert(file, selectedDevice)
channel, stdin, err := utils.CopyConvert(file, selectedDevice)
inputPipe = stdin
if err != nil {
w.Eval("setDialogReact(" + ParseToJsString("Error: "+err.Error()) + ")")
Expand Down
2 changes: 1 addition & 1 deletion dd.go → utils/dd.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package utils

import (
"bufio"
Expand Down
2 changes: 1 addition & 1 deletion devices_darwin.go → utils/devices_darwin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package utils

import (
"io/fs"
Expand Down
2 changes: 1 addition & 1 deletion devices_unix.go → utils/devices_unix.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build !darwin && !windows

package main
package utils

import (
"io/fs"
Expand Down
2 changes: 1 addition & 1 deletion devices_windows.go → utils/devices_windows.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package utils

import (
"io/fs"
Expand Down
2 changes: 1 addition & 1 deletion flash.go → utils/flash.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package utils

import (
"bufio"
Expand Down
2 changes: 1 addition & 1 deletion utils.go → utils/misc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package utils

import "strconv"

Expand Down
2 changes: 1 addition & 1 deletion sudo.go → utils/sudo.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package utils

import (
"errors"
Expand Down

0 comments on commit 035f1d3

Please sign in to comment.