Skip to content

Commit

Permalink
fix: resolve symbol conflicts in wakelock_plus by updating Pigeon prefix
Browse files Browse the repository at this point in the history
Updated the Pigeon configuration for wakelock_plus to use a unique ObjCOptions.prefix ("WKP") to prevent symbol conflicts with other plugins such as image_picker_ios.

Changes include:
- Modified the Pigeon prefix from "FLT" to "WAKELOCK" in `messages.dart`.
- Regenerated the Pigeon files to reflect the new prefix.
- Cleaned and rebuilt the project to ensure compatibility.
  • Loading branch information
weitsai committed Dec 21, 2024
1 parent 0d68ead commit cc89613
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 60 deletions.
6 changes: 3 additions & 3 deletions wakelock_plus/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
integration_test: 252f60fa39af5e17c3aa9899d35d908a0721b573
package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c
wakelock_plus: 78ec7c5b202cab7761af8e2b2b3d0671be6c4ae1
package_info_plus: c0502532a26c7662a62a356cebe2692ec5fe4ec4
wakelock_plus: 373cfe59b235a6dd5837d0fb88791d2f13a90d56

PODFILE CHECKSUM: beab77b38961de946f08660e554f80ac174dc842

COCOAPODS: 1.15.2
COCOAPODS: 1.16.1
10 changes: 5 additions & 5 deletions wakelock_plus/ios/Classes/WakelockPlusPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#import "messages.g.h"
#import "UIApplication+idleTimerLock.h"

@interface WakelockPlusPlugin () <FLTWakelockPlusApi>
@interface WakelockPlusPlugin () <WAKELOCKPLUSWakelockPlusApi>

@property (nonatomic, assign) BOOL enable;

Expand All @@ -11,10 +11,10 @@ @interface WakelockPlusPlugin () <FLTWakelockPlusApi>
@implementation WakelockPlusPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
WakelockPlusPlugin* instance = [[WakelockPlusPlugin alloc] init];
SetUpFLTWakelockPlusApi(registrar.messenger, instance);
SetUpWAKELOCKPLUSWakelockPlusApi(registrar.messenger, instance);
}

- (void)toggleMsg:(FLTToggleMessage*)input error:(FlutterError**)error {
- (void)toggleMsg:(WAKELOCKPLUSToggleMessage*)input error:(FlutterError**)error {
BOOL enable = [input.enable boolValue];
if (!enable) {
[[UIApplication sharedApplication] lock_idleTimerlockEnable:enable];//should disable first
Expand All @@ -34,9 +34,9 @@ - (void)setIdleTimerDisabled:(BOOL)enable {
}


- (FLTIsEnabledMessage*)isEnabledWithError:(FlutterError* __autoreleasing *)error {
- (WAKELOCKPLUSIsEnabledMessage*)isEnabledWithError:(FlutterError* __autoreleasing *)error {
NSNumber *enabled = [NSNumber numberWithBool:[[UIApplication sharedApplication] isIdleTimerDisabled]];
FLTIsEnabledMessage* result = [[FLTIsEnabledMessage alloc] init];
WAKELOCKPLUSIsEnabledMessage* result = [[WAKELOCKPLUSIsEnabledMessage alloc] init];
result.enabled = enabled;
return result;
}
Expand Down
20 changes: 10 additions & 10 deletions wakelock_plus/ios/Classes/messages.g.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@

NS_ASSUME_NONNULL_BEGIN

@class FLTToggleMessage;
@class FLTIsEnabledMessage;
@class WAKELOCKPLUSToggleMessage;
@class WAKELOCKPLUSIsEnabledMessage;

/// Message for toggling the wakelock on the platform side.
@interface FLTToggleMessage : NSObject
@interface WAKELOCKPLUSToggleMessage : NSObject
+ (instancetype)makeWithEnable:(nullable NSNumber *)enable;
@property(nonatomic, strong, nullable) NSNumber * enable;
@end

/// Message for reporting the wakelock state from the platform side.
@interface FLTIsEnabledMessage : NSObject
@interface WAKELOCKPLUSIsEnabledMessage : NSObject
+ (instancetype)makeWithEnabled:(nullable NSNumber *)enabled;
@property(nonatomic, strong, nullable) NSNumber * enabled;
@end

/// The codec used by all APIs.
NSObject<FlutterMessageCodec> *FLTGetMessagesCodec(void);
NSObject<FlutterMessageCodec> *WAKELOCKPLUSGetMessagesCodec(void);

@protocol FLTWakelockPlusApi
- (void)toggleMsg:(FLTToggleMessage *)msg error:(FlutterError *_Nullable *_Nonnull)error;
@protocol WAKELOCKPLUSWakelockPlusApi
- (void)toggleMsg:(WAKELOCKPLUSToggleMessage *)msg error:(FlutterError *_Nullable *_Nonnull)error;
/// @return `nil` only when `error != nil`.
- (nullable FLTIsEnabledMessage *)isEnabledWithError:(FlutterError *_Nullable *_Nonnull)error;
- (nullable WAKELOCKPLUSIsEnabledMessage *)isEnabledWithError:(FlutterError *_Nullable *_Nonnull)error;
@end

extern void SetUpFLTWakelockPlusApi(id<FlutterBinaryMessenger> binaryMessenger, NSObject<FLTWakelockPlusApi> *_Nullable api);
extern void SetUpWAKELOCKPLUSWakelockPlusApi(id<FlutterBinaryMessenger> binaryMessenger, NSObject<WAKELOCKPLUSWakelockPlusApi> *_Nullable api);

extern void SetUpFLTWakelockPlusApiWithSuffix(id<FlutterBinaryMessenger> binaryMessenger, NSObject<FLTWakelockPlusApi> *_Nullable api, NSString *messageChannelSuffix);
extern void SetUpWAKELOCKPLUSWakelockPlusApiWithSuffix(id<FlutterBinaryMessenger> binaryMessenger, NSObject<WAKELOCKPLUSWakelockPlusApi> *_Nullable api, NSString *messageChannelSuffix);

NS_ASSUME_NONNULL_END
82 changes: 41 additions & 41 deletions wakelock_plus/ios/Classes/messages.g.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,31 @@ static id GetNullableObjectAtIndex(NSArray<id> *array, NSInteger key) {
return (result == [NSNull null]) ? nil : result;
}

@interface FLTToggleMessage ()
+ (FLTToggleMessage *)fromList:(NSArray<id> *)list;
+ (nullable FLTToggleMessage *)nullableFromList:(NSArray<id> *)list;
@interface WAKELOCKPLUSToggleMessage ()
+ (WAKELOCKPLUSToggleMessage *)fromList:(NSArray<id> *)list;
+ (nullable WAKELOCKPLUSToggleMessage *)nullableFromList:(NSArray<id> *)list;
- (NSArray<id> *)toList;
@end

@interface FLTIsEnabledMessage ()
+ (FLTIsEnabledMessage *)fromList:(NSArray<id> *)list;
+ (nullable FLTIsEnabledMessage *)nullableFromList:(NSArray<id> *)list;
@interface WAKELOCKPLUSIsEnabledMessage ()
+ (WAKELOCKPLUSIsEnabledMessage *)fromList:(NSArray<id> *)list;
+ (nullable WAKELOCKPLUSIsEnabledMessage *)nullableFromList:(NSArray<id> *)list;
- (NSArray<id> *)toList;
@end

@implementation FLTToggleMessage
@implementation WAKELOCKPLUSToggleMessage
+ (instancetype)makeWithEnable:(nullable NSNumber *)enable {
FLTToggleMessage* pigeonResult = [[FLTToggleMessage alloc] init];
WAKELOCKPLUSToggleMessage* pigeonResult = [[WAKELOCKPLUSToggleMessage alloc] init];
pigeonResult.enable = enable;
return pigeonResult;
}
+ (FLTToggleMessage *)fromList:(NSArray<id> *)list {
FLTToggleMessage *pigeonResult = [[FLTToggleMessage alloc] init];
+ (WAKELOCKPLUSToggleMessage *)fromList:(NSArray<id> *)list {
WAKELOCKPLUSToggleMessage *pigeonResult = [[WAKELOCKPLUSToggleMessage alloc] init];
pigeonResult.enable = GetNullableObjectAtIndex(list, 0);
return pigeonResult;
}
+ (nullable FLTToggleMessage *)nullableFromList:(NSArray<id> *)list {
return (list) ? [FLTToggleMessage fromList:list] : nil;
+ (nullable WAKELOCKPLUSToggleMessage *)nullableFromList:(NSArray<id> *)list {
return (list) ? [WAKELOCKPLUSToggleMessage fromList:list] : nil;
}
- (NSArray<id> *)toList {
return @[
Expand All @@ -60,19 +60,19 @@ + (nullable FLTToggleMessage *)nullableFromList:(NSArray<id> *)list {
}
@end

@implementation FLTIsEnabledMessage
@implementation WAKELOCKPLUSIsEnabledMessage
+ (instancetype)makeWithEnabled:(nullable NSNumber *)enabled {
FLTIsEnabledMessage* pigeonResult = [[FLTIsEnabledMessage alloc] init];
WAKELOCKPLUSIsEnabledMessage* pigeonResult = [[WAKELOCKPLUSIsEnabledMessage alloc] init];
pigeonResult.enabled = enabled;
return pigeonResult;
}
+ (FLTIsEnabledMessage *)fromList:(NSArray<id> *)list {
FLTIsEnabledMessage *pigeonResult = [[FLTIsEnabledMessage alloc] init];
+ (WAKELOCKPLUSIsEnabledMessage *)fromList:(NSArray<id> *)list {
WAKELOCKPLUSIsEnabledMessage *pigeonResult = [[WAKELOCKPLUSIsEnabledMessage alloc] init];
pigeonResult.enabled = GetNullableObjectAtIndex(list, 0);
return pigeonResult;
}
+ (nullable FLTIsEnabledMessage *)nullableFromList:(NSArray<id> *)list {
return (list) ? [FLTIsEnabledMessage fromList:list] : nil;
+ (nullable WAKELOCKPLUSIsEnabledMessage *)nullableFromList:(NSArray<id> *)list {
return (list) ? [WAKELOCKPLUSIsEnabledMessage fromList:list] : nil;
}
- (NSArray<id> *)toList {
return @[
Expand All @@ -81,29 +81,29 @@ + (nullable FLTIsEnabledMessage *)nullableFromList:(NSArray<id> *)list {
}
@end

@interface FLTMessagesPigeonCodecReader : FlutterStandardReader
@interface WAKELOCKPLUSMessagesPigeonCodecReader : FlutterStandardReader
@end
@implementation FLTMessagesPigeonCodecReader
@implementation WAKELOCKPLUSMessagesPigeonCodecReader
- (nullable id)readValueOfType:(UInt8)type {
switch (type) {
case 129:
return [FLTToggleMessage fromList:[self readValue]];
return [WAKELOCKPLUSToggleMessage fromList:[self readValue]];
case 130:
return [FLTIsEnabledMessage fromList:[self readValue]];
return [WAKELOCKPLUSIsEnabledMessage fromList:[self readValue]];
default:
return [super readValueOfType:type];
}
}
@end

@interface FLTMessagesPigeonCodecWriter : FlutterStandardWriter
@interface WAKELOCKPLUSMessagesPigeonCodecWriter : FlutterStandardWriter
@end
@implementation FLTMessagesPigeonCodecWriter
@implementation WAKELOCKPLUSMessagesPigeonCodecWriter
- (void)writeValue:(id)value {
if ([value isKindOfClass:[FLTToggleMessage class]]) {
if ([value isKindOfClass:[WAKELOCKPLUSToggleMessage class]]) {
[self writeByte:129];
[self writeValue:[value toList]];
} else if ([value isKindOfClass:[FLTIsEnabledMessage class]]) {
} else if ([value isKindOfClass:[WAKELOCKPLUSIsEnabledMessage class]]) {
[self writeByte:130];
[self writeValue:[value toList]];
} else {
Expand All @@ -112,43 +112,43 @@ - (void)writeValue:(id)value {
}
@end

@interface FLTMessagesPigeonCodecReaderWriter : FlutterStandardReaderWriter
@interface WAKELOCKPLUSMessagesPigeonCodecReaderWriter : FlutterStandardReaderWriter
@end
@implementation FLTMessagesPigeonCodecReaderWriter
@implementation WAKELOCKPLUSMessagesPigeonCodecReaderWriter
- (FlutterStandardWriter *)writerWithData:(NSMutableData *)data {
return [[FLTMessagesPigeonCodecWriter alloc] initWithData:data];
return [[WAKELOCKPLUSMessagesPigeonCodecWriter alloc] initWithData:data];
}
- (FlutterStandardReader *)readerWithData:(NSData *)data {
return [[FLTMessagesPigeonCodecReader alloc] initWithData:data];
return [[WAKELOCKPLUSMessagesPigeonCodecReader alloc] initWithData:data];
}
@end

NSObject<FlutterMessageCodec> *FLTGetMessagesCodec(void) {
NSObject<FlutterMessageCodec> *WAKELOCKPLUSGetMessagesCodec(void) {
static FlutterStandardMessageCodec *sSharedObject = nil;
static dispatch_once_t sPred = 0;
dispatch_once(&sPred, ^{
FLTMessagesPigeonCodecReaderWriter *readerWriter = [[FLTMessagesPigeonCodecReaderWriter alloc] init];
WAKELOCKPLUSMessagesPigeonCodecReaderWriter *readerWriter = [[WAKELOCKPLUSMessagesPigeonCodecReaderWriter alloc] init];
sSharedObject = [FlutterStandardMessageCodec codecWithReaderWriter:readerWriter];
});
return sSharedObject;
}
void SetUpFLTWakelockPlusApi(id<FlutterBinaryMessenger> binaryMessenger, NSObject<FLTWakelockPlusApi> *api) {
SetUpFLTWakelockPlusApiWithSuffix(binaryMessenger, api, @"");
void SetUpWAKELOCKPLUSWakelockPlusApi(id<FlutterBinaryMessenger> binaryMessenger, NSObject<WAKELOCKPLUSWakelockPlusApi> *api) {
SetUpWAKELOCKPLUSWakelockPlusApiWithSuffix(binaryMessenger, api, @"");
}

void SetUpFLTWakelockPlusApiWithSuffix(id<FlutterBinaryMessenger> binaryMessenger, NSObject<FLTWakelockPlusApi> *api, NSString *messageChannelSuffix) {
void SetUpWAKELOCKPLUSWakelockPlusApiWithSuffix(id<FlutterBinaryMessenger> binaryMessenger, NSObject<WAKELOCKPLUSWakelockPlusApi> *api, NSString *messageChannelSuffix) {
messageChannelSuffix = messageChannelSuffix.length > 0 ? [NSString stringWithFormat: @".%@", messageChannelSuffix] : @"";
{
FlutterBasicMessageChannel *channel =
[[FlutterBasicMessageChannel alloc]
initWithName:[NSString stringWithFormat:@"%@%@", @"dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.toggle", messageChannelSuffix]
binaryMessenger:binaryMessenger
codec:FLTGetMessagesCodec()];
codec:WAKELOCKPLUSGetMessagesCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(toggleMsg:error:)], @"FLTWakelockPlusApi api (%@) doesn't respond to @selector(toggleMsg:error:)", api);
NSCAssert([api respondsToSelector:@selector(toggleMsg:error:)], @"WAKELOCKPLUSWakelockPlusApi api (%@) doesn't respond to @selector(toggleMsg:error:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
NSArray<id> *args = message;
FLTToggleMessage *arg_msg = GetNullableObjectAtIndex(args, 0);
WAKELOCKPLUSToggleMessage *arg_msg = GetNullableObjectAtIndex(args, 0);
FlutterError *error;
[api toggleMsg:arg_msg error:&error];
callback(wrapResult(nil, error));
Expand All @@ -162,12 +162,12 @@ void SetUpFLTWakelockPlusApiWithSuffix(id<FlutterBinaryMessenger> binaryMessenge
[[FlutterBasicMessageChannel alloc]
initWithName:[NSString stringWithFormat:@"%@%@", @"dev.flutter.pigeon.wakelock_plus_platform_interface.WakelockPlusApi.isEnabled", messageChannelSuffix]
binaryMessenger:binaryMessenger
codec:FLTGetMessagesCodec()];
codec:WAKELOCKPLUSGetMessagesCodec()];
if (api) {
NSCAssert([api respondsToSelector:@selector(isEnabledWithError:)], @"FLTWakelockPlusApi api (%@) doesn't respond to @selector(isEnabledWithError:)", api);
NSCAssert([api respondsToSelector:@selector(isEnabledWithError:)], @"WAKELOCKPLUSWakelockPlusApi api (%@) doesn't respond to @selector(isEnabledWithError:)", api);
[channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
FlutterError *error;
FLTIsEnabledMessage *output = [api isEnabledWithError:&error];
WAKELOCKPLUSIsEnabledMessage *output = [api isEnabledWithError:&error];
callback(wrapResult(output, error));
}];
} else {
Expand Down
2 changes: 1 addition & 1 deletion wakelock_plus/pigeons/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class IsEnabledMessage {
objcHeaderOut: 'ios/Classes/messages.g.h',
objcSourceOut: 'ios/Classes/messages.g.m',
objcOptions: ObjcOptions(
prefix: 'FLT',
prefix: 'WAKELOCKPLUS',
),
kotlinOptions: KotlinOptions(errorClassName: "WakelockPlusFlutterError"),
kotlinOut:
Expand Down

0 comments on commit cc89613

Please sign in to comment.