Skip to content

Commit 7c815fb

Browse files
authored
LOOP-4415 Add support for preinstalled scenarios (#542)
* Add support for preinstalled scenarios * Add loading indicator
1 parent 61e9723 commit 7c815fb

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

Loop.xcodeproj/project.pbxproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,7 @@
15021502
C1E2774722433D7A00354103 /* MKRingProgressView.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = MKRingProgressView.framework; sourceTree = BUILT_PRODUCTS_DIR; };
15031503
C1E3862428247B7100F561A4 /* StoredLoopNotRunningNotification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoredLoopNotRunningNotification.swift; sourceTree = "<group>"; };
15041504
C1E71721292E90CC00DA646F /* SmallStatusWidgetEntryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmallStatusWidgetEntryView.swift; sourceTree = "<group>"; };
1505+
C1E9CB5A295101570022387B /* install-scenarios.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "install-scenarios.sh"; sourceTree = "<group>"; };
15051506
C1EF747128D6A44A00C8C083 /* CrashRecoveryManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CrashRecoveryManager.swift; sourceTree = "<group>"; };
15061507
C1F2075B26D6F9B0007AB7EB /* ProfileExpirationAlerter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileExpirationAlerter.swift; sourceTree = "<group>"; };
15071508
C1F7822527CC056900C0919A /* SettingsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsManager.swift; sourceTree = "<group>"; };
@@ -2695,6 +2696,7 @@
26952696
C18A491222FCC22800FDA733 /* build-derived-assets.sh */,
26962697
C18A491522FCC22900FDA733 /* copy-plugins.sh */,
26972698
C18A491322FCC22900FDA733 /* make_scenario.py */,
2699+
C1E9CB5A295101570022387B /* install-scenarios.sh */,
26982700
);
26992701
path = Scripts;
27002702
sourceTree = "<group>";
@@ -2885,6 +2887,7 @@
28852887
43776F8A1B8022E90074EA36 /* Resources */,
28862888
43A9439C1B926B7B0051FA24 /* Embed Watch Content */,
28872889
43A943AE1B928D400051FA24 /* Embed Frameworks */,
2890+
C113F4472951352C00758735 /* Install Scenarios */,
28882891
C16DA84322E8E5FF008624C2 /* Install Plugins */,
28892892
C1D19800232CFA2A0096D646 /* Capture Build Details */,
28902893
4F70C1EC1DE8DCA8006380B7 /* Embed App Extensions */,
@@ -3453,6 +3456,24 @@
34533456
/* End PBXResourcesBuildPhase section */
34543457

34553458
/* Begin PBXShellScriptBuildPhase section */
3459+
C113F4472951352C00758735 /* Install Scenarios */ = {
3460+
isa = PBXShellScriptBuildPhase;
3461+
buildActionMask = 2147483647;
3462+
files = (
3463+
);
3464+
inputFileListPaths = (
3465+
);
3466+
inputPaths = (
3467+
);
3468+
name = "Install Scenarios";
3469+
outputFileListPaths = (
3470+
);
3471+
outputPaths = (
3472+
);
3473+
runOnlyForDeploymentPostprocessing = 0;
3474+
shellPath = /bin/sh;
3475+
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n\"${SRCROOT}/Scripts/install-scenarios.sh\"\n";
3476+
};
34563477
C16DA84322E8E5FF008624C2 /* Install Plugins */ = {
34573478
isa = PBXShellScriptBuildPhase;
34583479
buildActionMask = 2147483647;

Loop/Managers/LocalTestingScenariosManager.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ final class LocalTestingScenariosManager: TestingScenariosManagerRequirements, D
3737
}
3838

3939
self.deviceManager = deviceManager
40-
let documentsDirectory = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!
41-
self.scenariosSource = documentsDirectory.appendingPathComponent("scenarios")
40+
self.scenariosSource = Bundle.main.bundleURL.appendingPathComponent("Scenarios")
4241

43-
log.debug("Place testing scenarios in %{public}@", scenariosSource.path)
42+
log.debug("Loading testing scenarios from %{public}@", scenariosSource.path)
4443
if !fileManager.fileExists(atPath: scenariosSource.path) {
4544
do {
4645
try fileManager.createDirectory(at: scenariosSource, withIntermediateDirectories: false)

Loop/View Controllers/TestingScenariosTableViewController.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,13 @@ final class TestingScenariosTableViewController: RadioSelectionTableViewControll
140140
}
141141

142142
let url = scenarioURLs[selectedIndex]
143+
144+
loadButtonItem.isEnabled = false
145+
loadButtonItem.title = "Loading..."
143146
scenariosManager.loadScenario(from: url) { error in
144147
DispatchQueue.main.async {
148+
self.loadButtonItem.isEnabled = true
149+
self.loadButtonItem.title = "Load"
145150
if let error = error {
146151
self.present(UIAlertController(with: error), animated: true)
147152
} else {

Scripts/install-scenarios.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
# install-scenarios.sh
4+
# Loop
5+
#
6+
# Created by Pete Schwamb on 12/19/22.
7+
# Copyright © 2022 LoopKit Authors. All rights reserved.
8+
9+
SCENARIOS_DIR="$WORKSPACE_ROOT"/Scenarios
10+
11+
if [ -d "$SCENARIOS_DIR" ]
12+
then
13+
echo "$SCENARIOS_DIR exists. Installing scenarios."
14+
echo cp -a "$SCENARIOS_DIR" "${BUILT_PRODUCTS_DIR}/Scenarios"
15+
cp -a "$SCENARIOS_DIR" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}/Scenarios"
16+
else
17+
echo "Scenarios missing or not configured... Not installing."
18+
fi

0 commit comments

Comments
 (0)