Skip to content

Commit 2682e05

Browse files
Merge pull request #363 from alichherawalla/fix/ios-poll-main-thread-hang
fix(ios): prevent main-thread hang in download progress polling
2 parents a42cbc0 + 61debb8 commit 2682e05

5 files changed

Lines changed: 40 additions & 15 deletions

File tree

__tests__/rntl/screens/OnboardingScreen.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ describe('OnboardingScreen', () => {
237237
expect(mockDiscoverLANServers).toHaveBeenCalled();
238238
});
239239

240+
it('opens correct Wednesday URL when tapping Made with love', () => {
241+
const { Linking } = require('react-native');
242+
const spy = jest.spyOn(Linking, 'openURL').mockImplementation(() => Promise.resolve());
243+
const { getByText } = render(<OnboardingScreen navigation={navigation} />);
244+
fireEvent.press(getByText('Wednesday'));
245+
expect(spy).toHaveBeenCalledWith(
246+
expect.stringContaining('mobile.wednesday.is/hire-ai-native-mobile-squad'),
247+
);
248+
spy.mockRestore();
249+
});
250+
240251
it('completes onboarding when Get Started pressed on last slide', async () => {
241252
const { act: reactAct } = require('@testing-library/react-native');
242253
const { Dimensions } = require('react-native');

ios/DownloadManagerModule.swift

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,11 @@ extension DownloadManagerModule {
937937

938938
func pollProgress() {
939939
guard hasListeners else { return }
940-
queue.sync(flags: .barrier) {
941-
let activeDownloads = downloads.filter { $0.value.status == "running" || $0.value.status == "pending" || $0.value.status == "paused" }
942-
for (downloadId, var info) in activeDownloads {
940+
queue.async(flags: .barrier) { [weak self] in
941+
guard let self = self else { return }
942+
let activeDownloads = self.downloads.filter { $0.value.status == "running" || $0.value.status == "pending" || $0.value.status == "paused" }
943+
var events: [[String: Any]] = []
944+
for (_, var info) in activeDownloads {
943945
if info.isMultiFile {
944946
var aggregateBytes: Int64 = 0
945947
var aggregateTotal: Int64 = 0
@@ -961,17 +963,24 @@ extension DownloadManagerModule {
961963
if task.countOfBytesExpectedToReceive > 0 {
962964
info.totalBytes = task.countOfBytesExpectedToReceive
963965
}
964-
info.status = statusString(from: task.state)
966+
info.status = self.statusString(from: task.state)
967+
}
968+
self.downloads[info.downloadId] = info
969+
events.append([
970+
"downloadId": info.downloadId,
971+
"fileName": info.fileName,
972+
"modelId": info.modelId,
973+
"bytesDownloaded": NSNumber(value: info.bytesDownloaded),
974+
"totalBytes": NSNumber(value: info.totalBytes),
975+
"status": info.status
976+
] as [String: Any])
977+
}
978+
if !events.isEmpty {
979+
DispatchQueue.main.async { [weak self] in
980+
for event in events {
981+
self?.sendEvent(withName: "DownloadProgress", body: event)
982+
}
965983
}
966-
downloads[downloadId] = info
967-
sendEvent(withName: "DownloadProgress", body: [
968-
"downloadId": info.downloadId,
969-
"fileName": info.fileName,
970-
"modelId": info.modelId,
971-
"bytesDownloaded": NSNumber(value: info.bytesDownloaded),
972-
"totalBytes": NSNumber(value: info.totalBytes),
973-
"status": info.status
974-
] as [String: Any])
975984
}
976985
}
977986
}

ios/Podfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ target 'OffgridMobile' do
4040
target.build_configurations.each do |config|
4141
config.build_settings['CLANG_CXX_LANGUAGE_STANDARD'] = 'c++20'
4242
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '17.0'
43+
# Suppress fmt consteval errors on newer Xcode/clang
44+
if target.name == 'fmt'
45+
config.build_settings['GCC_TREAT_WARNINGS_AS_ERRORS'] = 'NO'
46+
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = '$(inherited) -Wno-error'
47+
end
4348
end
4449
end
4550
end

src/screens/OnboardingScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ export const OnboardingScreen: React.FC<OnboardingScreenProps> = ({
264264
testID="onboarding-next"
265265
/>
266266
<TouchableOpacity
267-
onPress={() => Linking.openURL('https://www.wednesday.is/?utm_source=off-grid-mobile-app')}
267+
onPress={() => Linking.openURL('https://mobile.wednesday.is/hire-ai-native-mobile-squad?utm_source=off-grid-mobile-app&utm_medium=onboarding&utm_campaign=in-app')}
268268
style={styles.madeWithLove}
269269
>
270270
<View style={styles.madeWithLoveRow}>

src/screens/ProDetailScreen/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const ProDetailScreen: React.FC = () => {
3939

4040
<ScrollView style={styles.flex} contentContainerStyle={styles.content}>
4141
<Text style={styles.title}>Off Grid PRO</Text>
42-
<Text style={styles.subtitle}>Lifetime access - Coming soon</Text>
42+
<Text style={styles.subtitle}>Coming soon</Text>
4343

4444
<View style={styles.featureList}>
4545
{FEATURES.map(f => (

0 commit comments

Comments
 (0)