Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dbus method for getting handler thumbnail #14

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
1442efb
Merge pull request #1 from unix-streamdeck/configStruct
The-Jonsey Jul 27, 2020
bdbf743
Updated streamdeck lib dep
The-Jonsey Jul 27, 2020
a19fcd3
Stopped text clearing image behind text
The-Jonsey Jul 27, 2020
6bafa7e
WIP
The-Jonsey Jul 30, 2020
b4af427
Added dbus interface
The-Jonsey Aug 11, 2020
54ba770
Added DBus to docs
The-Jonsey Aug 13, 2020
27e9350
Fixed for new packages, and PR gripes
The-Jonsey Aug 17, 2020
c15b932
Handled removing of pointers from and in config
The-Jonsey Aug 18, 2020
a88c0f1
Fixed build and returning error from dbus
The-Jonsey Aug 18, 2020
ec30b9d
removed duplicated deps in go.sum
The-Jonsey Aug 18, 2020
a112126
Fixed returning error in dbus
The-Jonsey Aug 18, 2020
1031ba4
Merge pull request #2 from unix-streamdeck/feat/handlers
The-Jonsey Aug 19, 2020
2eba53d
Fixed crash on image failing to open
The-Jonsey Aug 24, 2020
6ed53fc
WIP: Hotplug support
The-Jonsey Aug 24, 2020
8e9f444
Create LICENSE
The-Jonsey Aug 25, 2020
f7d731f
Refactored resizing of frames to happen before loop
The-Jonsey Aug 25, 2020
e3ceae0
Added semaphore lock around SetImage to prevent handlers running on o…
The-Jonsey Aug 25, 2020
40f83f8
Refactored SetPage so all keys on page are rendered on seperate threa…
The-Jonsey Aug 25, 2020
c7f9a0f
Update README.md
The-Jonsey Aug 25, 2020
ec65c18
Update README.md
The-Jonsey Aug 25, 2020
57294fe
added semaphores around disconnect and reconnect to prevent crash due…
The-Jonsey Aug 26, 2020
928b48d
Factor handlers out into their own package
okratitan Aug 27, 2020
510de49
Merge branch 'master' of github.com:unix-streamdeck/streamdeckd into …
The-Jonsey Aug 27, 2020
7c928d8
Merge pull request #4 from unix-streamdeck/handlerPackage
The-Jonsey Aug 27, 2020
88f86cb
Merge branch 'master' of github.com:unix-streamdeck/streamdeckd into …
The-Jonsey Aug 27, 2020
1c2a5bb
Merged origin master into feat/optimizations
The-Jonsey Aug 27, 2020
c97fe8f
Merge branch 'master' of github.com:unix-streamdeck/streamdeckd into …
The-Jonsey Aug 27, 2020
e5df054
Sorted imports
The-Jonsey Aug 27, 2020
22ebe71
Merge pull request #3 from unix-streamdeck/feat/optimizations
The-Jonsey Aug 27, 2020
6e32073
Merged origin staging into feat/hotplug
The-Jonsey Aug 27, 2020
2ea599d
Merge pull request #5 from unix-streamdeck/feat/hotplug
The-Jonsey Aug 27, 2020
250a249
Refactored handlers
The-Jonsey Aug 27, 2020
d67c565
Removed key pointer in handlers
The-Jonsey Aug 27, 2020
7737f25
Refactored remounting handlers
The-Jonsey Aug 27, 2020
1b17e17
Updated unix-streamdeck/api version
The-Jonsey Aug 28, 2020
4421242
Merge pull request #6 from unix-streamdeck/staging
The-Jonsey Aug 28, 2020
5e9da7d
Fixed dbus info not being set
The-Jonsey Aug 31, 2020
a254079
Refactored to use api text methods
The-Jonsey Sep 5, 2020
d60d045
Reverted pushing spotify handler
The-Jonsey Sep 6, 2020
eea7eec
Reverted pushing spotify handler
The-Jonsey Sep 6, 2020
c2ed21a
Updated unix-streamdeck/api version
The-Jonsey Sep 7, 2020
264a4ad
Merge pull request #7 from unix-streamdeck/feat/use-api-text-methods
The-Jonsey Sep 7, 2020
eec457a
Fixed bug with nil config on dbus config upload
The-Jonsey Oct 1, 2020
a45e482
Fixed bug with duplicated gif handler after suspend
The-Jonsey Nov 1, 2020
997361a
Added text alignment and size override
The-Jonsey Nov 7, 2020
e6dbd19
Modules loading, and dbus method for module info
The-Jonsey Nov 10, 2020
238ea9e
Merge pull request #9 from unix-streamdeck/feat/modules
The-Jonsey Dec 23, 2020
724cea9
Fixed const set streamdeckd icon size
The-Jonsey Dec 28, 2020
575e672
Updated fields on gif
The-Jonsey Dec 28, 2020
334aaca
Added support for multiple streamdecks
The-Jonsey May 13, 2021
b89d29e
Added config auto migrator
The-Jonsey May 15, 2021
fc899df
Fixed api version in go.mod
The-Jonsey May 17, 2021
3a7b55c
Added time delay in attemptConnection
The-Jonsey May 30, 2021
d51855c
Stopped child processes being killed when streamdeckd is stopped/rest…
The-Jonsey Jul 21, 2021
3432a18
Updated api
The-Jonsey Jul 21, 2021
35d8bfc
Enabled module stopping between pages
The-Jonsey Aug 23, 2021
54656a4
Fixed handlers on home page not restarting after disconnect on page o…
The-Jonsey Aug 29, 2021
81fb063
Added 'press button' dbus method'
The-Jonsey Sep 10, 2021
92e36a9
Updated README
The-Jonsey Sep 10, 2021
051e514
Updated README
The-Jonsey Sep 10, 2021
acfb945
Updated api version
The-Jonsey Sep 12, 2021
9868442
Prevented crash if deck not found on HandleInput
The-Jonsey Sep 12, 2021
48b6c61
Merge pull request #10 from unix-streamdeck/feat/multiple-deck-support
The-Jonsey Sep 12, 2021
f9761e9
Added dbus method for getting handler thumbnail
Louis-Jones-Evri Oct 9, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
added semaphores around disconnect and reconnect to prevent crash due…
… to double (dis)connect
  • Loading branch information
The-Jonsey committed Aug 26, 2020
commit 57294fe121e920976c8c7b4326752c36da4a135c
2 changes: 1 addition & 1 deletion dbus.go
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ func (StreamDeckDBus) ReloadConfig() *dbus.Error {
}

func (StreamDeckDBus) SetPage(page int) *dbus.Error {
SetPage(config, page, dev)
SetPage(config, page)
return nil
}

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -10,4 +10,5 @@ require (
github.com/unix-streamdeck/api v0.0.0-20200818180846-6942d99617b2
github.com/unix-streamdeck/driver v0.0.0-20200817173808-cdaf123c076b
golang.org/x/image v0.0.0-20200119044424-58c23975cae1
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -115,6 +115,7 @@ golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
26 changes: 10 additions & 16 deletions interface.go
Original file line number Diff line number Diff line change
@@ -35,15 +35,12 @@ func ResizeImage(img image.Image) image.Image {
return resize.Resize(dev.Pixels, dev.Pixels, img, resize.Lanczos3)
}

func SetImage(img image.Image, i int, page int, dev streamdeck.Device) {
func SetImage(img image.Image, i int, page int, _ streamdeck.Device) {
if p == page && isOpen {
err := dev.SetImage(uint8(i), img)
if err != nil {
if strings.Contains(err.Error(), "hidapi") {
log.Println("Device disconnected")
_ = dev.Close()
isOpen = false
unmountHandlers()
disconnect()
} else {
log.Println(err)
}
@@ -79,7 +76,7 @@ func SetKey(currentKey *api.Key, i int) {
}
}

func SetPage(config *api.Config, page int, dev streamdeck.Device) {
func SetPage(config *api.Config, page int) {
p = page
currentPage := config.Pages[page]
for i := 0; i < len(currentPage); i++ {
@@ -100,7 +97,7 @@ func SetPage(config *api.Config, page int, dev streamdeck.Device) {
if handler == nil {
continue
}
handler.Icon(page, i, currentKey, dev)
handler.Icon(page, i, currentKey, streamdeck.Device{})
currentKey.IconHandlerStruct = handler
}
} else {
@@ -110,7 +107,7 @@ func SetPage(config *api.Config, page int, dev streamdeck.Device) {
EmitPage(p)
}

func HandleInput(key *api.Key, page int, index int, dev streamdeck.Device) {
func HandleInput(key *api.Key, page int, index int) {
if key.Command != "" {
runCommand(key.Command)
}
@@ -119,7 +116,7 @@ func HandleInput(key *api.Key, page int, index int, dev streamdeck.Device) {
}
if key.SwitchPage != 0 {
page = key.SwitchPage - 1
SetPage(config, page, dev)
SetPage(config, page)
}
if key.Brightness != 0 {
_ = dev.SetBrightness(uint8(key.Brightness))
@@ -138,7 +135,7 @@ func HandleInput(key *api.Key, page int, index int, dev streamdeck.Device) {
}
key.KeyHandlerStruct = handler
}
key.KeyHandlerStruct.Key(page, index, key, dev)
key.KeyHandlerStruct.Key(page, index, key, streamdeck.Device{})
}
}

@@ -151,15 +148,12 @@ func Listen() {
select {
case k, ok := <-kch:
if !ok {
log.Println("Device disconnected")
_ = dev.Close()
isOpen = false
unmountHandlers()
continue
disconnect()
return
}
if k.Pressed == true {
if len(config.Pages)-1 >= p && len(config.Pages[p])-1 >= int(k.Index) {
HandleInput(&config.Pages[p][k.Index], p, int(k.Index), dev)
HandleInput(&config.Pages[p][k.Index], p, int(k.Index))
}
}
}
56 changes: 40 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package main

import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/unix-streamdeck/api"
"github.com/unix-streamdeck/driver"
"golang.org/x/sync/semaphore"
_ "image/gif"
_ "image/jpeg"
_ "image/png"
@@ -21,6 +23,8 @@ var dev streamdeck.Device
var config *api.Config
var configPath = os.Getenv("HOME") + string(os.PathSeparator) + ".streamdeck-config.json"
var isOpen = false
var disconnectSem = semaphore.NewWeighted(1)
var connectSem = semaphore.NewWeighted(1)

var basicConfig = api.Config{
Pages: []api.Page{
@@ -59,38 +63,58 @@ func main() {
}

func attemptConnection() {
for {
if !isOpen {
_ = openDevice()
if isOpen {
go Listen()
SetPage(config, p, dev)
if sDbus != nil {
sDbus.IconSize = int(dev.Pixels)
sDbus.Rows = int(dev.Rows)
sDbus.Cols = int(dev.Columns)
}
for !isOpen {
_ = openDevice()
if isOpen {
SetPage(config, p)
if sDbus != nil {
sDbus.IconSize = int(dev.Pixels)
sDbus.Rows = int(dev.Rows)
sDbus.Cols = int(dev.Columns)
}
Listen()
}
}
}

func disconnect() {
ctx := context.Background()
err := disconnectSem.Acquire(ctx, 1)
if err != nil {
return
}
defer disconnectSem.Release(1)
if !isOpen {
return
}
log.Println("Device disconnected")
_ = dev.Close()
isOpen = false
unmountHandlers()
}

func openDevice() error {
ctx := context.Background()
err := connectSem.Acquire(ctx, 1)
if err != nil {
return err
}
defer connectSem.Release(1)
d, err := streamdeck.Devices()
if err != nil {
return err
}
if len(d) == 0 {
return errors.New("No streamdeck devices found")
}
dev = d[0]
err = dev.Open()
err = d[0].Open()
if err != nil {
return err
}
dev = d[0]
isOpen = true
fmt.Println("Device (" + dev.Serial + ") connected")
return err
return nil
}

func readConfig() (*api.Config, error) {
@@ -139,7 +163,7 @@ func SetConfig(configString string) error {
if len(config.Pages) == 0 {
config.Pages = append(config.Pages, api.Page{})
}
SetPage(config, p, dev)
SetPage(config, p)
return nil
}

@@ -153,7 +177,7 @@ func ReloadConfig() error {
if len(config.Pages) == 0 {
config.Pages = append(config.Pages, api.Page{})
}
SetPage(config, p, dev)
SetPage(config, p)
return nil
}