Skip to content

Commit

Permalink
feat: custom addons via python bindings #65
Browse files Browse the repository at this point in the history
  • Loading branch information
leukipp committed Aug 14, 2024
1 parent 7fd1080 commit 785ee6c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
2 changes: 2 additions & 0 deletions input/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ func Exit(tr *desktop.Tracker) bool {

log.Info("Exit")

// Communicate application exit
Disconnect()
os.Exit(0)

return true
Expand Down
48 changes: 48 additions & 0 deletions input/addonbinding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package input

import (
"os"

"os/exec"
"path/filepath"

"github.com/leukipp/cortile/v2/common"
"github.com/leukipp/cortile/v2/desktop"

log "github.com/sirupsen/logrus"
)

func BindAddons(tr *desktop.Tracker) {
if common.HasFlag("disable-addons-folder") {
return
}

// check if addons folder exists
configFolderPath := common.ConfigFolderPath(common.Build.Name)
addonsFolderPath := filepath.Join(configFolderPath, "addons")
if _, err := os.Stat(addonsFolderPath); os.IsNotExist(err) {
return
}

// read files in addons folder
files, err := os.ReadDir(addonsFolderPath)
if err != nil {
log.Warn("Error reading addons: ", addonsFolderPath)
return
}

// run files in addons folder
for _, file := range files {
addonFilePath := filepath.Join(addonsFolderPath, file.Name())
log.Info("Execute addon ", addonFilePath)

// execute addon scripts
addon := exec.Command(addonFilePath)
addon.Stdout = os.Stdout
addon.Stderr = os.Stderr

if err = addon.Start(); err != nil {
log.Warn("Error executing addon: ", err)
}
}
}
13 changes: 12 additions & 1 deletion input/dbusbinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ func export(tr *desktop.Tracker) {
"Pointer": common.Map{},
"Action": common.Map{},
"Corner": common.Map{},
"Disconnect": common.Map{},
}
properties := map[string]*prop.Prop{}
for name, value := range mapping {
Expand Down Expand Up @@ -481,6 +482,14 @@ func Listen(args []string) {
}
}

func Disconnect() {
SetProperty("Disconnect", struct {
Event string
}{
Event: "exit",
})
}

func GetProperty(name string) common.Map {
if props == nil {
return common.Map{}
Expand Down Expand Up @@ -536,5 +545,7 @@ func print(typ string, name string, data common.Map) {

func fatal(msg string, err error) {
print("Error", "Fatal", common.Map{"Message": fmt.Sprintf("%s: %s", msg, err)})
os.Exit(1)

// exit with success error code
os.Exit(0)
}
2 changes: 1 addition & 1 deletion input/signalbinding.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func BindSignal(tr *desktop.Tracker) {
ch := make(chan os.Signal, 1)

// Bind signal channel
signal.Notify(ch, os.Interrupt, syscall.SIGTERM)
signal.Notify(ch, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
go exit(ch, tr)
}

Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func runMain() {
input.BindKeys(tracker)
input.BindTray(tracker)
input.BindDbus(tracker)
input.BindAddons(tracker)

// Run X event loop
xevent.Main(store.X)
Expand Down

0 comments on commit 785ee6c

Please sign in to comment.