mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
fix initial image error & add cache max.
This commit is contained in:
parent
9c6c107ee0
commit
aefb367505
@ -17,6 +17,7 @@ func NewImage(desktop types.DesktopManager) *ImageCtx {
|
|||||||
desktop: desktop,
|
desktop: desktop,
|
||||||
listeners: map[uintptr]*func(entry *ImageEntry){},
|
listeners: map[uintptr]*func(entry *ImageEntry){},
|
||||||
cache: map[uint64]*ImageEntry{},
|
cache: map[uint64]*ImageEntry{},
|
||||||
|
maxSerial: 200, // TODO: Cleanup?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ type ImageCtx struct {
|
|||||||
cacheMu sync.Mutex
|
cacheMu sync.Mutex
|
||||||
cache map[uint64]*ImageEntry
|
cache map[uint64]*ImageEntry
|
||||||
current *ImageEntry
|
current *ImageEntry
|
||||||
|
maxSerial uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type ImageEntry struct {
|
type ImageEntry struct {
|
||||||
@ -43,6 +45,7 @@ func (manager *ImageCtx) Start() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
manager.current = entry
|
||||||
for _, emit := range manager.listeners {
|
for _, emit := range manager.listeners {
|
||||||
(*emit)(entry)
|
(*emit)(entry)
|
||||||
}
|
}
|
||||||
@ -61,7 +64,7 @@ func (manager *ImageCtx) Shutdown() {
|
|||||||
|
|
||||||
func (manager *ImageCtx) GetCached(serial uint64) (*ImageEntry, error) {
|
func (manager *ImageCtx) GetCached(serial uint64) (*ImageEntry, error) {
|
||||||
// zero means no serial available
|
// zero means no serial available
|
||||||
if serial == 0 {
|
if serial == 0 || serial > manager.maxSerial {
|
||||||
return manager.fetchEntry()
|
return manager.fetchEntry()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,6 +129,5 @@ func (manager *ImageCtx) fetchEntry() (*ImageEntry, error) {
|
|||||||
Image: img,
|
Image: img,
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.current = entry
|
|
||||||
return entry, nil
|
return entry, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user