Skip to content

Commit

Permalink
Revert "Revert "ID in DisplayOptions is now an int64""
Browse files Browse the repository at this point in the history
This reverts commit a33bbfa.
  • Loading branch information
asticode committed May 28, 2017
1 parent 14126f7 commit c748c0f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions astilectron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ func TestAstilectron_ExecuteCmd(t *testing.T) {
a.executeCmd(cmd)
wg.Done()
}()
a.dispatcher.Dispatch(Event{Name: EventNameAppEventReady, Displays: &EventDisplays{All: []*DisplayOptions{{ID: PtrInt(1)}}, Primary: &DisplayOptions{ID: PtrInt(1)}}, TargetID: mainTargetID})
a.dispatcher.Dispatch(Event{Name: EventNameAppEventReady, Displays: &EventDisplays{All: []*DisplayOptions{{ID: PtrInt64(1)}}, Primary: &DisplayOptions{ID: PtrInt64(1)}}, TargetID: mainTargetID})
wg.Wait()
assert.Len(t, a.Displays(), 1)
assert.Equal(t, 1, *a.PrimaryDisplay().o.ID)
assert.Equal(t, int64(1), *a.PrimaryDisplay().o.ID)
}

func TestIsValidOS(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion display.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Display struct {
// https://github.com/electron/electron/blob/v1.6.5/docs/api/structures/display.md
type DisplayOptions struct {
Bounds *RectangleOptions `json:"bounds,omitempty"`
ID *int `json:"id,omitempty"`
ID *int64 `json:"id,omitempty"`
Rotation *int `json:"rotation,omitempty"` // 0, 90, 180 or 270
ScaleFactor *float64 `json:"scaleFactor,omitempty"`
Size *SizeOptions `json:"size,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions display_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import "sync"

// displayPool represents a display pool
type displayPool struct {
d map[int]*Display
d map[int64]*Display
m *sync.Mutex
}

// newDisplayPool creates a new display pool
func newDisplayPool() *displayPool {
return &displayPool{
d: make(map[int]*Display),
d: make(map[int64]*Display),
m: &sync.Mutex{},
}
}
Expand Down Expand Up @@ -44,7 +44,7 @@ func (p *displayPool) primary() (d *Display) {
func (p *displayPool) update(e *EventDisplays) {
p.m.Lock()
defer p.m.Unlock()
var ids = make(map[int]bool)
var ids = make(map[int64]bool)
for _, o := range e.All {
ids[*o.ID] = true
var primary bool
Expand Down
22 changes: 11 additions & 11 deletions display_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@ func TestDisplayPool(t *testing.T) {
// Test update
dp.update(&EventDisplays{
All: []*DisplayOptions{
{ID: PtrInt(1), Rotation: PtrInt(1)},
{ID: PtrInt(2)},
{ID: PtrInt64(1), Rotation: PtrInt(1)},
{ID: PtrInt64(2)},
},
Primary: &DisplayOptions{ID: PtrInt(2)},
Primary: &DisplayOptions{ID: PtrInt64(2)},
})
assert.Len(t, dp.all(), 2)
assert.Equal(t, 2, *dp.primary().o.ID)
assert.Equal(t, int64(2), *dp.primary().o.ID)

// Test removing one display
dp.update(&EventDisplays{
All: []*DisplayOptions{
{ID: PtrInt(1), Rotation: PtrInt(2)},
{ID: PtrInt64(1), Rotation: PtrInt(2)},
},
Primary: &DisplayOptions{ID: PtrInt(1)},
Primary: &DisplayOptions{ID: PtrInt64(1)},
})
assert.Len(t, dp.all(), 1)
assert.Equal(t, 2, dp.all()[0].Rotation())
assert.Equal(t, 1, *dp.primary().o.ID)
assert.Equal(t, int64(1), *dp.primary().o.ID)

// Test adding a new one
dp.update(&EventDisplays{
All: []*DisplayOptions{
{ID: PtrInt(1)},
{ID: PtrInt(3)},
{ID: PtrInt64(1)},
{ID: PtrInt64(3)},
},
Primary: &DisplayOptions{ID: PtrInt(1)},
Primary: &DisplayOptions{ID: PtrInt64(1)},
})
assert.Len(t, dp.all(), 2)
assert.Equal(t, 1, *dp.primary().o.ID)
assert.Equal(t, int64(1), *dp.primary().o.ID)
}
5 changes: 5 additions & 0 deletions helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ func PtrInt(i int) *int {
return &i
}

// PtrInt64 transforms an int64 into an *int64
func PtrInt64(i int64) *int64 {
return &i
}

// PtrStr transforms a string into a *string
func PtrStr(i string) *string {
return &i
Expand Down

0 comments on commit c748c0f

Please sign in to comment.