Skip to content

Commit

Permalink
Remove running activity on termination
Browse files Browse the repository at this point in the history
  • Loading branch information
sieren committed Nov 10, 2023
1 parent 2699080 commit aa4f880
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
6 changes: 6 additions & 0 deletions ReleaseConfig.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright © 2023 Matthias Frick. All rights reserved.

// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974

CURRENT_PROJECT_VERSION=69
2 changes: 2 additions & 0 deletions midileactivity/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
<key>CFBundleVersion</key>
<string>69</string>
</dict>
</dict>
</plist>
29 changes: 21 additions & 8 deletions midimittr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
6953EF282AF95CAA00113943 /* ActivityAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6953EF272AF95CAA00113943 /* ActivityAttributes.swift */; };
695B546E25F4F27A004CAA44 /* NotificationBannerSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 695B546D25F4F27A004CAA44 /* NotificationBannerSwift */; };
696972FE2AFE944B00CDC438 /* ActivityAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6953EF272AF95CAA00113943 /* ActivityAttributes.swift */; };
696973022AFEB05D00CDC438 /* ReleaseConfig.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 696973012AFEB05D00CDC438 /* ReleaseConfig.xcconfig */; };
696973032AFEB05D00CDC438 /* ReleaseConfig.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 696973012AFEB05D00CDC438 /* ReleaseConfig.xcconfig */; };
69800AFB2AEE9275001F9860 /* SystemExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69800AFA2AEE9275001F9860 /* SystemExtension.swift */; };
699BDC6E1FF55D7E00C7057D /* MIDIPortTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 699BDC6D1FF55D7E00C7057D /* MIDIPortTableCell.swift */; };
69A79E831FF64FE100A367A4 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 69A79E821FF64FE100A367A4 /* Settings.bundle */; };
Expand Down Expand Up @@ -115,6 +117,7 @@
6953EF252AF9596F00113943 /* ActivityViewHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityViewHandler.swift; sourceTree = "<group>"; };
6953EF272AF95CAA00113943 /* ActivityAttributes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityAttributes.swift; sourceTree = "<group>"; };
6955AA321FF8076500224667 /* Peertalk.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Peertalk.framework; path = Carthage/Build/iOS/Peertalk.framework; sourceTree = "<group>"; };
696973012AFEB05D00CDC438 /* ReleaseConfig.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ReleaseConfig.xcconfig; sourceTree = "<group>"; };
69800AFA2AEE9275001F9860 /* SystemExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemExtension.swift; sourceTree = "<group>"; };
699BDC621FF54BA200C7057D /* MarqueeLabelSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MarqueeLabelSwift.framework; path = Carthage/Build/iOS/MarqueeLabelSwift.framework; sourceTree = "<group>"; };
699BDC631FF54BA200C7057D /* MarqueeLabel.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MarqueeLabel.framework; path = Carthage/Build/iOS/MarqueeLabel.framework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -176,6 +179,7 @@
694947D319DD7A4E00A6E65C = {
isa = PBXGroup;
children = (
696973012AFEB05D00CDC438 /* ReleaseConfig.xcconfig */,
69B8BA0B19DD8FEF00AB03A2 /* AVFoundation.framework */,
69B8BA0C19DD8FEF00AB03A2 /* AVKit.framework */,
6949480E19DD804200A6E65C /* CoreMIDI.framework */,
Expand Down Expand Up @@ -402,13 +406,15 @@
69B8BA1019DD99C900AB03A2 /* silence.mp3 in Resources */,
69A79E831FF64FE100A367A4 /* Settings.bundle in Resources */,
694947F019DD7A4E00A6E65C /* Images.xcassets in Resources */,
696973022AFEB05D00CDC438 /* ReleaseConfig.xcconfig in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
6953EF0E2AF957E400113943 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
696973032AFEB05D00CDC438 /* ReleaseConfig.xcconfig in Resources */,
6953EF1D2AF957E500113943 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -549,6 +555,7 @@
};
6949480119DD7A4E00A6E65C /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 696973012AFEB05D00CDC438 /* ReleaseConfig.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "compiler-default";
Expand Down Expand Up @@ -611,7 +618,7 @@
CODE_SIGN_ENTITLEMENTS = "";
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 67;
CURRENT_PROJECT_VERSION = 70;
DEVELOPMENT_TEAM = VEESE9857L;
ENABLE_NS_ASSERTIONS = YES;
ENABLE_STRICT_OBJC_MSGSEND = NO;
Expand All @@ -622,12 +629,14 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_WARN_UNDECLARED_SELECTOR = NO;
INFOPLIST_FILE = "$(SRCROOT)/midimittr/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = midimittr;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.4;
MARKETING_VERSION = 2.5;
OTHER_CFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = "com.matt.MIDI-LE";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -640,6 +649,7 @@
};
6949480419DD7A4E00A6E65C /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 696973012AFEB05D00CDC438 /* ReleaseConfig.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
Expand All @@ -651,7 +661,7 @@
CODE_SIGN_ENTITLEMENTS = "";
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 67;
CURRENT_PROJECT_VERSION = 70;
DEVELOPMENT_TEAM = VEESE9857L;
ENABLE_NS_ASSERTIONS = YES;
ENABLE_STRICT_OBJC_MSGSEND = NO;
Expand All @@ -662,12 +672,14 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_WARN_UNDECLARED_SELECTOR = NO;
INFOPLIST_FILE = "$(SRCROOT)/midimittr/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = midimittr;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.4;
MARKETING_VERSION = 2.5;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
PRODUCT_BUNDLE_IDENTIFIER = "com.matt.MIDI-LE";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -694,7 +706,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 70;
DEBUG_INFORMATION_FORMAT = dwarf;
DEVELOPMENT_TEAM = VEESE9857L;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
Expand All @@ -714,7 +726,7 @@
"@executable_path/../../Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 2.5;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.matt.MIDI-LE.midileactivity";
Expand All @@ -730,6 +742,7 @@
};
6953EF232AF957E500113943 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 696973012AFEB05D00CDC438 /* ReleaseConfig.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
Expand All @@ -746,7 +759,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 70;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_TEAM = VEESE9857L;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
Expand All @@ -766,7 +779,7 @@
"@executable_path/../../Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 2.5;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.matt.MIDI-LE.midileactivity";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Binary file not shown.
18 changes: 17 additions & 1 deletion midimittr/ActivityViewHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ public class ActivityViewHandler: MIDIControllerDelegate {
public init(midiController: MIDIController) {
self.midiController = midiController
self.midiController.setActivityViewDelegate(self)

NotificationCenter.default.addObserver(forName: UIApplication.willTerminateNotification, object: nil, queue: .main) { _ in
guard let runningActivity = self.currentActivity else { return }
Task {
await runningActivity.end(dismissalPolicy: .immediate)
}
for activity in Activity<MIDIPortsAttributes>.activities {
Task {
await activity.end(dismissalPolicy: .immediate)
}
}
}
}

public func updateResources() {
Expand All @@ -60,7 +72,6 @@ public class ActivityViewHandler: MIDIControllerDelegate {
return
}
guard let activity = currentActivity else { return }
let newState = contentState
Task.detached { @MainActor in
await activity.update(using: self.contentState)
}
Expand All @@ -72,6 +83,11 @@ public class ActivityViewHandler: MIDIControllerDelegate {
do {
let connectionState = MIDIPortsAttributes()

for activity in Activity<MIDIPortsAttributes>.activities {
Task {
await activity.end(dismissalPolicy: .immediate)
}
}
let activity = try Activity.request(
attributes: connectionState,
content: .init(state: contentState, staleDate: nil)
Expand Down

0 comments on commit aa4f880

Please sign in to comment.