Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-ha committed Mar 12, 2024
1 parent 4f336bf commit 5f24b81
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions copier/blockcopier.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ func (copier BlockCopier) Copy(source discovery.FileInformation, destination dis
}

func (copier BlockCopier) CopyWithProgress(source discovery.FileInformation, destination discovery.FileInformation, state CopierState, progress chan<- CopierProgress) CopierState {
if !IsCopyRequired(source, destination) {
completedState := BlockCopierState{Size: uint64(source.Info.Size()), BytesTransferred: uint64(source.Info.Size())}
reportProgress(progress, source, destination, completedState, io.EOF)
return CopierState{State: state.State, Error: io.EOF}
}

concreteState, castOK := state.State.(BlockCopierState)
if !castOK && state.State != nil {
castErr := fmt.Errorf("converting to BlockCopierState failed")
Expand Down
8 changes: 8 additions & 0 deletions copier/copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ type CopierProgress struct {
Error error
OpaqueState any
}

func IsCopyRequired(source discovery.FileInformation, destination discovery.FileInformation) bool {
if source.Info == nil || destination.Info == nil {
return true
}

return source.Info.Size() != destination.Info.Size()
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.1
require (
github.com/charmbracelet/bubbles v0.18.0
github.com/charmbracelet/bubbletea v0.25.0
github.com/godbus/dbus/v5 v5.1.0
github.com/stretchr/testify v1.9.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
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/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"

"github.com/ben-ha/jcp/logic"
"github.com/ben-ha/jcp/sleepless"
"github.com/ben-ha/jcp/state"
"github.com/ben-ha/jcp/tui"
tea "github.com/charmbracelet/bubbletea"
Expand Down Expand Up @@ -58,6 +59,9 @@ func main() {
uiComplete := sync.WaitGroup{}
uiComplete.Add(1)

sleepEnabler, _ := sleepless.PreventSleep("jcp", "copy in progress")
defer sleepEnabler()

go StartUI(ui, &uiComplete)

go updaterFunc(jcp, ui, state)
Expand Down
23 changes: 23 additions & 0 deletions sleepless/sleepless_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package sleepless

import (
dbus "github.com/godbus/dbus/v5"
)

func PreventSleep(appName string, reason string) (func(), error) {
conn, err := dbus.ConnectSessionBus()
if err != nil {
return func() {}, err
}

var cookie uint
err = conn.BusObject().Call("org.gnome.SessionManager.Inhibit", 0, appName, 0, reason, 0).Store(&cookie)
if err != nil {
return func() {}, err
}

return func() {
conn.BusObject().Call("org.gnome.SessionManager.Uninhibit", 0, cookie)
conn.Close()
}, nil
}

0 comments on commit 5f24b81

Please sign in to comment.