diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-15 14:05:42 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-15 14:05:42 +0300 |
commit | 6580b4e2c396f2fdfb0fb017ec4249baa2fba5ff (patch) | |
tree | 1a0db802aa76dbf9f8b5c595e8b1a687ecdf4667 /src/ios.m | |
parent | 5119a72481a2c752972470ea7b488a5c9e58b720 (diff) |
iOS: Picking files for upload
Diffstat (limited to 'src/ios.m')
-rw-r--r-- | src/ios.m | 29 |
1 files changed, 24 insertions, 5 deletions
@@ -161,6 +161,7 @@ API_AVAILABLE(ios(13.0)) | |||
161 | 161 | ||
162 | @interface AppState : NSObject<UIDocumentPickerDelegate> { | 162 | @interface AppState : NSObject<UIDocumentPickerDelegate> { |
163 | iString *fileBeingSaved; | 163 | iString *fileBeingSaved; |
164 | iString *pickFileCommand; | ||
164 | } | 165 | } |
165 | @property (nonatomic, assign) BOOL isHapticsAvailable; | 166 | @property (nonatomic, assign) BOOL isHapticsAvailable; |
166 | @property (nonatomic, strong) NSObject *haptic; | 167 | @property (nonatomic, strong) NSObject *haptic; |
@@ -173,9 +174,17 @@ static AppState *appState_; | |||
173 | -(instancetype)init { | 174 | -(instancetype)init { |
174 | self = [super init]; | 175 | self = [super init]; |
175 | fileBeingSaved = NULL; | 176 | fileBeingSaved = NULL; |
177 | pickFileCommand = NULL; | ||
176 | return self; | 178 | return self; |
177 | } | 179 | } |
178 | 180 | ||
181 | -(void)setPickFileCommand:(const char *)command { | ||
182 | if (!pickFileCommand) { | ||
183 | pickFileCommand = new_String(); | ||
184 | } | ||
185 | setCStr_String(pickFileCommand, command); | ||
186 | } | ||
187 | |||
179 | -(void)setFileBeingSaved:(const iString *)path { | 188 | -(void)setFileBeingSaved:(const iString *)path { |
180 | fileBeingSaved = copy_String(path); | 189 | fileBeingSaved = copy_String(path); |
181 | } | 190 | } |
@@ -213,7 +222,11 @@ didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls { | |||
213 | NSURL *url = [urls firstObject]; | 222 | NSURL *url = [urls firstObject]; |
214 | iString *path = localFilePathFromUrl_String(collectNewCStr_String([[url absoluteString] | 223 | iString *path = localFilePathFromUrl_String(collectNewCStr_String([[url absoluteString] |
215 | UTF8String])); | 224 | UTF8String])); |
216 | postCommandf_App("file.open temp:1 path:%s", cstrCollect_String(path)); | 225 | postCommandf_App("%s temp:1 path:%s", |
226 | cstr_String(pickFileCommand), | ||
227 | cstrCollect_String(path)); | ||
228 | delete_String(pickFileCommand); | ||
229 | pickFileCommand = NULL; | ||
217 | } | 230 | } |
218 | } | 231 | } |
219 | 232 | ||
@@ -221,6 +234,10 @@ didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls { | |||
221 | if (fileBeingSaved) { | 234 | if (fileBeingSaved) { |
222 | [self removeSavedFile]; | 235 | [self removeSavedFile]; |
223 | } | 236 | } |
237 | if (pickFileCommand) { | ||
238 | delete_String(pickFileCommand); | ||
239 | pickFileCommand = NULL; | ||
240 | } | ||
224 | } | 241 | } |
225 | 242 | ||
226 | -(void)keyboardOnScreen:(NSNotification *)notification { | 243 | -(void)keyboardOnScreen:(NSNotification *)notification { |
@@ -454,11 +471,13 @@ void exportDownloadedFile_iOS(const iString *path) { | |||
454 | } | 471 | } |
455 | 472 | ||
456 | void pickFileForOpening_iOS(void) { | 473 | void pickFileForOpening_iOS(void) { |
474 | pickFile_iOS("file.open"); | ||
475 | } | ||
476 | |||
477 | void pickFile_iOS(const char *command) { | ||
478 | [appState_ setPickFileCommand:command]; | ||
457 | UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] | 479 | UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] |
458 | initWithDocumentTypes:@[@"fi.skyjake.lagrange.gemini", | 480 | initWithDocumentTypes:@[@"public.data"] |
459 | @"public.text", | ||
460 | @"public.image", | ||
461 | @"public.audio"] | ||
462 | inMode:UIDocumentPickerModeImport]; | 481 | inMode:UIDocumentPickerModeImport]; |
463 | picker.delegate = appState_; | 482 | picker.delegate = appState_; |
464 | [viewController_(get_Window()) presentViewController:picker animated:YES completion:nil]; | 483 | [viewController_(get_Window()) presentViewController:picker animated:YES completion:nil]; |