@@ -246,6 +246,7 @@ @interface MyStreamDeckPlugin ()
246246
247247// The empty post-it icon encoded in base64
248248@property (strong ) NSString *base64PostitEmpty;
249+ @property (strong ) NSString *base64PostitSleepy;
249250@property (strong ) NSString *base64PostitSecure;
250251
251252// The text we want to hold (one entry per key)
@@ -277,6 +278,9 @@ @implementation MyStreamDeckPlugin
277278
278279- (void )setupIfNeeded
279280{
281+ if (_base64PostitSleepy == nil ) {
282+ _base64PostitSleepy = CreateBase64EncodedString (ComposeImage (GetResourcePath (@" postit-unused@2x.png" ), @" " , nil ));
283+ }
280284 if (_base64PostitEmpty == nil ) {
281285 _base64PostitEmpty = CreateBase64EncodedString (ComposeImage (GetResourcePath (@" postit-empty@2x.png" ), @" " , nil ));
282286 }
@@ -432,7 +436,7 @@ - (void)willAppearForAction:(NSString *)action withContext:(id)context withPaylo
432436{
433437 // Set up the instance variables if needed
434438 [self setupIfNeeded ];
435-
439+
436440 // Add the context to the list of known contexts
437441 // [self.knownContexts addObject:context];
438442}
@@ -449,24 +453,31 @@ - (void)deviceDidConnect:(NSString *)deviceID withDeviceInfo:(NSDictionary *)dev
449453 NSInteger devWidth = [deviceInfo[@" size" ][@" rows" ] integerValue ];
450454 NSInteger devHeight= [deviceInfo[@" size" ][@" columns" ] integerValue ];
451455
452- // Preparing our dictionary objects (as we need the device's buttons info)
453- _tileText = [[NSMutableDictionary alloc ] initWithCapacity: devWidth*devHeight];
454- NSMutableDictionary * tmpDict = [[NSMutableDictionary alloc ] initWithCapacity: 1 ];
455-
456- // We need to initialize the dict for text (max the whole size of the device)
457- for (NSInteger row=0 ; row < devWidth; row++) {
458- for (NSInteger col=0 ; col < devHeight; col++) {
459- //
460- // We need to fake the usual structure we get while running to use the common keyFromCoord() method
461- // Unfortunately, a dict requires String or string-like elements so we have to do a formatting :(
462- //
463- tmpDict[@" row" ] = [NSString stringWithFormat: @" %ld " , row];
464- tmpDict[@" column" ] = [NSString stringWithFormat: @" %ld " , col];
465- _tileText[ keyFromCoord (tmpDict) ] = keyFromCoord (tmpDict);
466- // using the key as default value should make any code misbehavior visible
456+ // Making sure we do not loose data if the computer is locked or goes to sleep ;)
457+ if ( _dictInitialized ) {
458+ [_connectionManager logMessage: [NSString stringWithFormat: @" [DID-CONNECT] No need to re-intialize the internal text storage in order to avoid loosing existing data..." ]];
459+ }
460+ else {
461+ // Preparing our dictionary objects (as we need the device's buttons info)
462+ _tileText = [[NSMutableDictionary alloc ] initWithCapacity: devWidth*devHeight];
463+ NSMutableDictionary * tmpDict = [[NSMutableDictionary alloc ] initWithCapacity: 1 ];
464+
465+ // We need to initialize the dict for text (max the whole size of the device)
466+ for (NSInteger row=0 ; row < devWidth; row++) {
467+ for (NSInteger col=0 ; col < devHeight; col++) {
468+ //
469+ // We need to fake the usual structure we get while running to use the common keyFromCoord() method
470+ // Unfortunately, a dict requires String or string-like elements so we have to do a formatting :(
471+ //
472+ tmpDict[@" row" ] = [NSString stringWithFormat: @" %ld " , row];
473+ tmpDict[@" column" ] = [NSString stringWithFormat: @" %ld " , col];
474+
475+ _tileText[ keyFromCoord (tmpDict) ] = keyFromCoord (tmpDict);
476+ // using the key as default value should make any code misbehavior visible
477+ }
467478 }
479+ _dictInitialized = TRUE ;
468480 }
469- _dictInitialized = TRUE ;
470481}
471482
472483- (void )deviceDidDisconnect : (NSString *)deviceID
0 commit comments