Skip to content

Commit

Permalink
Merge pull request #413 from SUPLA/develop
Browse files Browse the repository at this point in the history
v24.09
  • Loading branch information
przemyslawzygmunt authored Sep 10, 2024
2 parents f8b8f0e + 268e9cc commit 103e491
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 39 deletions.
12 changes: 8 additions & 4 deletions SUPLA.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@
A52BFEF62B18883600A2F64C /* AuthInfo+Mock.swift in Sources */ = {isa = PBXBuildFile; fileRef = A52BFEF52B18883600A2F64C /* AuthInfo+Mock.swift */; };
A52BFEF82B189ECC00A2F64C /* ActivateProfileUseCaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A52BFEF72B189ECC00A2F64C /* ActivateProfileUseCaseTests.swift */; };
A52BFEFA2B18A43000A2F64C /* DeleteProfileUseCaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A52BFEF92B18A43000A2F64C /* DeleteProfileUseCaseTests.swift */; };
A52D13B12C8F0F3000134961 /* SuplaClient+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = A52D13B02C8F0F3000134961 /* SuplaClient+Ext.swift */; };
A530EDEB2A53F60400F8DAEE /* SwitchDetailVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = A530EDEA2A53F60400F8DAEE /* SwitchDetailVM.swift */; };
A530EDED2A53F6A800F8DAEE /* SwitchDetailVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A530EDEC2A53F6A800F8DAEE /* SwitchDetailVC.swift */; };
A530EDF02A53F8E100F8DAEE /* SuplaTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A530EDEF2A53F8E100F8DAEE /* SuplaTabBarController.swift */; };
Expand Down Expand Up @@ -1800,6 +1801,7 @@
A52BFEF52B18883600A2F64C /* AuthInfo+Mock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AuthInfo+Mock.swift"; sourceTree = "<group>"; };
A52BFEF72B189ECC00A2F64C /* ActivateProfileUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivateProfileUseCaseTests.swift; sourceTree = "<group>"; };
A52BFEF92B18A43000A2F64C /* DeleteProfileUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteProfileUseCaseTests.swift; sourceTree = "<group>"; };
A52D13B02C8F0F3000134961 /* SuplaClient+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SuplaClient+Ext.swift"; sourceTree = "<group>"; };
A530EDEA2A53F60400F8DAEE /* SwitchDetailVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchDetailVM.swift; sourceTree = "<group>"; };
A530EDEC2A53F6A800F8DAEE /* SwitchDetailVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwitchDetailVC.swift; sourceTree = "<group>"; };
A530EDEF2A53F8E100F8DAEE /* SuplaTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SuplaTabBarController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2801,6 +2803,7 @@
011021B325CC386D00621D41 /* SAVersionError.h */,
011021B425CC386D00621D41 /* SAVersionError.m */,
401CA1F11BA0A28A00117AF4 /* SuplaClient.m */,
A52D13B02C8F0F3000134961 /* SuplaClient+Ext.swift */,
);
name = "supla-client-lib";
sourceTree = "<group>";
Expand Down Expand Up @@ -6546,6 +6549,7 @@
AEF79D8D2712FF8D00D7554B /* AppSettingsVC.swift in Sources */,
A55A8D9F2BAC263000C540D4 /* ExecuteRollerShutterActionUseCase.swift in Sources */,
A5F14B7429DED41000682FA6 /* BaseViewModel.swift in Sources */,
A52D13B12C8F0F3000134961 /* SuplaClient+Ext.swift in Sources */,
01215A7324C8AECC00429947 /* SALightsourceLifespanSettingsDialog.m in Sources */,
A5074BDB2BCFE22E0081B6B1 /* SuplaChannelShadingSystemBaseConfig.swift in Sources */,
AEED87DF276F1FCE005D76CF /* LocationOrderingVM.swift in Sources */,
Expand Down Expand Up @@ -7567,7 +7571,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = SUPLA/SUPLA.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 194;
CURRENT_PROJECT_VERSION = 195;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = T6ZPGSWA75;
GCC_PREPROCESSOR_DEFINITIONS = (
Expand All @@ -7586,7 +7590,7 @@
"$(inherited)",
"$(PROJECT_DIR)/SUPLA/lib",
);
MARKETING_VERSION = 24.08.01;
MARKETING_VERSION = 24.09;
OTHER_SWIFT_FLAGS = "$(inherited) -D COCOAPODS -D DEBUG";
PRODUCT_BUNDLE_IDENTIFIER = com.acsoftware.ios.supla;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -7606,7 +7610,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = SUPLA/SUPLA.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 194;
CURRENT_PROJECT_VERSION = 195;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = T6ZPGSWA75;
GCC_PREPROCESSOR_DEFINITIONS = (
Expand All @@ -7625,7 +7629,7 @@
"$(inherited)",
"$(PROJECT_DIR)/SUPLA/lib",
);
MARKETING_VERSION = 24.08.01;
MARKETING_VERSION = 24.09;
PRODUCT_BUNDLE_IDENTIFIER = com.acsoftware.ios.supla;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SUPLA/SUPLA-Bridging-Header.h";
Expand Down
6 changes: 4 additions & 2 deletions SUPLA/AddWizardVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -639,12 +639,12 @@ -(NSString*)cloudHostName {

- (void)onRegistrationEnabled:(NSNotification *)notification {

SARegistrationEnabled *reg_enabled =
[SARegistrationEnabled notificationToRegistrationEnabled:notification];
SARegistrationEnabled *reg_enabled = [SARegistrationEnabled notificationToRegistrationEnabled:notification];

if ( reg_enabled != nil ) {

if ( [reg_enabled isIODeviceRegistrationEnabled] ) {
[DisconnectUseCaseLegacyWrapper cancelWithAddWizardStartedReason];
[self showPage:PAGE_STEP_3];
} else {
[self setStep:STEP_SUPERUSER_AUTHORIZATION];
Expand All @@ -658,6 +658,7 @@ - (void)onSetRegistrationEnabledResult:(NSNotification *)notification {
if ( notification.userInfo != nil ) {
NSNumber *code = (NSNumber *)[notification.userInfo objectForKey:@"code"];
if (code && [code intValue] == SUPLA_RESULTCODE_TRUE) {
[DisconnectUseCaseLegacyWrapper cancelWithAddWizardStartedReason];
[self showPage:PAGE_STEP_3];
}
}
Expand Down Expand Up @@ -784,6 +785,7 @@ - (IBAction)cancelOrBackTouch:(nullable id)sender {
[self cleanUp];
[self.OpQueue cancelAllOperations];
[self savePrefs];
[SuplaAppStateHolderProxy addWizardFinished];
[SuplaAppCoordinatorLegacyWrapper dismissWithAnimated: true];
}

Expand Down
3 changes: 1 addition & 2 deletions SUPLA/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
var settings = settings
settings.backgroundEntryTime = dateProvider.currentTimestamp()

disconnectUseCase.invokeSynchronous()
suplaAppStateHolder.handle(event: .finish(reason: .appInBackground))
disconnectUseCase.invokeSynchronous(reason: .appInBackground)
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Expand Down
3 changes: 2 additions & 1 deletion SUPLA/Core/State/SuplaAppEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ enum SuplaAppEvent: Equatable {
case noAccount
case connecting
case connected
case cancel
case lock
case unlock
case onStart
case networkConnected
case addWizardFinished

case cancel(reason: SuplaAppState.Reason? = nil)
case finish(reason: SuplaAppState.Reason? = nil)
case error(reason: SuplaAppState.Reason)
}
44 changes: 34 additions & 10 deletions SUPLA/Core/State/SuplaAppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum SuplaAppState: Equatable {
case firstProfileCreation
case connecting(reason: Reason? = nil)
case connected
case disconnecting
case disconnecting(reason: Reason? = nil)
case locking
case finished(reason: Reason? = nil)

Expand All @@ -33,6 +33,7 @@ enum SuplaAppState: Equatable {
case versionError
case noNetwork
case appInBackground
case addWizardStarted

var shouldAuthorize: Bool {
switch (self) {
Expand All @@ -54,7 +55,7 @@ enum SuplaAppState: Equatable {
case .firstProfileCreation: firstProfileCreationNextState(for: event)
case .connecting(let reason): connectingNextState(for: event, previousReason: reason)
case .connected: try! connectedNextState(for: event)
case .disconnecting: disconnectingNextState(for: event)
case .disconnecting(let reason): disconnectingNextState(for: event, previousReason: reason)
case .locking: lockingNextState(for: event)
case .finished(let reason): finishedNextState(for: event, previousReason: reason)
}
Expand All @@ -71,6 +72,7 @@ enum SuplaAppState: Equatable {
case .cancel: try! illegalCancelEvent()
case .unlock: try! illegalUnlockEvent()
case .error: try! illegalErrorEvent()
case .addWizardFinished: try! illegalAddWizardFinishedEvent()
}
}

Expand All @@ -84,6 +86,7 @@ enum SuplaAppState: Equatable {
case .connected: try! illegalConnectedEvent()
case .cancel: try! illegalCancelEvent()
case .error: try! illegalErrorEvent()
case .addWizardFinished: try! illegalAddWizardFinishedEvent()
}
}

Expand All @@ -98,6 +101,7 @@ enum SuplaAppState: Equatable {
case .initialized: try! illegalInitializedEvent()
case .noAccount: try! illegalNoAccountEvent()
case .lock: try! illegalLockEvent()
case .addWizardFinished: try! illegalAddWizardFinishedEvent()
}
}

Expand All @@ -106,21 +110,22 @@ enum SuplaAppState: Equatable {
case .connecting, .initialized, .onStart: nil
case .connected: .connected
case .lock: .locked
case .cancel: .disconnecting
case .cancel(let reason): .disconnecting(reason: reason)
case .networkConnected: .connecting()
case .error(let reason): .connecting(reason: reason)
case .finish(let reason): .finished(reason: reason == nil ? previousReason : reason)
case .noAccount: try! illegalNoAccountEvent()
case .unlock: try! illegalUnlockEvent()
case .addWizardFinished: try! illegalAddWizardFinishedEvent()
}
}

private func connectedNextState(for event: SuplaAppEvent) throws -> SuplaAppState? {
switch (event) {
case .onStart, .networkConnected: nil
case .onStart, .networkConnected, .addWizardFinished: nil
case .connecting: .connecting()
case .lock: .locked
case .cancel: .disconnecting
case .cancel(let reason): .disconnecting(reason: reason)
case .finish(let reason): .finished(reason: reason)
case .error(let reason): .finished(reason: reason)
case .initialized: try! illegalInitializedEvent()
Expand All @@ -130,15 +135,16 @@ enum SuplaAppState: Equatable {
}
}

private func disconnectingNextState(for event: SuplaAppEvent) -> SuplaAppState? {
private func disconnectingNextState(for event: SuplaAppEvent, previousReason: Reason?) -> SuplaAppState? {
switch (event) {
case .onStart, .cancel, .networkConnected, .connecting, .connected: nil
case .lock: .locking
case .finish(let reason): .finished(reason: reason)
case .finish(let reason): .finished(reason: previousReason ?? reason)
case .error(let reason): .finished(reason: reason)
case .initialized: try! illegalInitializedEvent()
case .noAccount: try! illegalNoAccountEvent()
case .unlock: try! illegalUnlockEvent()
case .addWizardFinished: try! illegalAddWizardFinishedEvent()
}
}

Expand All @@ -152,18 +158,32 @@ enum SuplaAppState: Equatable {
case .unlock: try! illegalUnlockEvent()
case .connecting: try! illegalConnectingEvent()
case .error(_): try! illegalErrorEvent()
case .addWizardFinished: try! illegalAddWizardFinishedEvent()
}
}

private func finishedNextState(for event: SuplaAppEvent, previousReason: Reason?) -> SuplaAppState? {
switch (event) {
case .cancel, .networkConnected: nil
case .initialized, .connecting: .connecting()
case .initialized, .addWizardFinished: .connecting()
case .connecting: previousReason == .addWizardStarted ? nil : .connecting()
case .lock: .locked
case .onStart: previousReason == .noNetwork ? .connecting(reason: previousReason) : .connecting()
case .onStart:
if (previousReason == .addWizardStarted) {
nil
} else if (previousReason == .noNetwork) {
.connecting(reason: previousReason)
} else {
.connecting()
}
case .noAccount: .firstProfileCreation
case .error(let reason): reason != previousReason ? .finished(reason: reason) : nil
case .finish(let reason): reason != previousReason ? .finished(reason: reason ?? previousReason) : nil
case .finish(let reason):
if (previousReason == .addWizardStarted || previousReason == reason) {
nil
} else {
.finished(reason: reason ?? previousReason)
}
case .connected: try! illegalConnectedEvent()
case .unlock: try! illegalUnlockEvent()
}
Expand Down Expand Up @@ -204,4 +224,8 @@ enum SuplaAppState: Equatable {
private func illegalLockEvent() throws -> SuplaAppState? {
throw Error.illegalEvent(message: "Unexpected lock event!")
}

private func illegalAddWizardFinishedEvent() throws -> SuplaAppState? {
throw Error.illegalEvent(message: "Unexpected add wizard finished event!")
}
}
8 changes: 7 additions & 1 deletion SUPLA/Core/State/SuplaAppStateHolder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ final class SuplaAppStateHolderProxy: NSObject {
@Singleton<SuplaAppStateHolder> var stateHolder
stateHolder.handle(event: .connecting)
}

@objc
static func addWizardFinished() {
@Singleton<SuplaAppStateHolder> var stateHolder
stateHolder.handle(event: .addWizardFinished)
}

@objc
static func connectionError(code: Int32) {
Expand All @@ -101,7 +107,7 @@ final class SuplaAppStateHolderProxy: NSObject {
@objc
static func cancel() {
@Singleton<SuplaAppStateHolder> var stateHolder
stateHolder.handle(event: .cancel)
stateHolder.handle(event: .cancel())
}

@objc
Expand Down
2 changes: 1 addition & 1 deletion SUPLA/Features/Status/StatusVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extension StatusFeature {
case .connectionError(let code):
code == SUPLA_RESULT_HOST_NOT_FOUND ? Strings.Status.errorHostNotFound : nil
case .registerError(let code): SuplaResultCode.from(value: code).getTextMessage(authDialog: true)
case .noNetwork, .versionError, .appInBackground, .none: nil
case .noNetwork, .versionError, .appInBackground, .addWizardStarted, .none: nil
}
}
}
Expand Down
Loading

0 comments on commit 103e491

Please sign in to comment.