Skip to content

Commit

Permalink
Allow sending files to the trashcan
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Mar 15, 2024
1 parent 4b6ec82 commit ef87672
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions trash/trash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Package trash lets sandboxed applications send files to the trashcan.
package trash

import "github.com/rymdport/portal"

const (
trashBaseName = portal.CallBaseName + ".Trash"
trashCallName = trashBaseName + ".TrashFile"
)
30 changes: 30 additions & 0 deletions trash/trashfile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package trash

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

// TrashFile sends a file to the trashcan. Applications are allowed to trash a file if they can open it in r/w mode.
func TrashFile(fd uintptr) (uint8, error) {
conn, err := dbus.SessionBus() // Shared connection, don't close.
if err != nil {
return 0, err
}

data := map[string]dbus.Variant{}

obj := conn.Object(portal.ObjectName, portal.ObjectPath)
call := obj.Call(trashCallName, 0, dbus.UnixFDIndex(fd), data)
if call.Err != nil {
return 0, err
}

var result uint8
err = call.Store(&result)
if err != nil {
return 0, err
}

return result, nil
}

0 comments on commit ef87672

Please sign in to comment.