Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature/app-provider] App Provider support #1151

Closed
wants to merge 60 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
9ad6429
[milestone/11.8.2] Milestone 11.8.2 (#1085)
hosy Jan 17, 2022
eccd8d1
Add In House certificate option to resign README.md (#1084)
michaelstingl Jan 18, 2022
84c3b4c
Update release item with new download URL (#1067)
michaelstingl Jan 18, 2022
de3ca41
- switch to feature/graph-api SDK branch
felix-schwarz Feb 14, 2022
101d3b4
- adapt to new and updated APIs (OCPath -> OCDriveID + OCLocation)
felix-schwarz Feb 23, 2022
76c0a3f
- update iOS SDK
felix-schwarz Mar 7, 2022
b6b9bf9
Via SDK update:
felix-schwarz Mar 7, 2022
f1fac7b
[milestone/11.9.0] Milestone 11.9.0 (#1071)
hosy Mar 16, 2022
883d136
- update SDK to include latest Drive and Data Source changes
felix-schwarz Mar 23, 2022
70cdc22
[milestone/11.9.1] Milestone 11.9.1 (#1111)
felix-schwarz Mar 29, 2022
281bd98
updated app version number because of redundant AppStore build
Mar 29, 2022
420e5ff
[docs/folder-structure] Changed Docs Structure / MDM Fixes (#1094)
hosy Apr 4, 2022
55d415b
set up a new version 11.10.0
Apr 6, 2022
ace22e8
- progress snapshot, before refactoring DataSourceCollectionViewContr…
felix-schwarz Apr 6, 2022
71af450
- CollectionViewController: generalized collection view controller ba…
felix-schwarz Apr 7, 2022
a265ac4
- CollectionView: seperate classes in their own source files, clean u…
felix-schwarz Apr 8, 2022
867c787
[feature/openssl-1.1.1] Migration to OpenSSL 1.1.0 (#1116)
hosy Apr 8, 2022
d6ff1d7
- update SDK for improved error handling
felix-schwarz Apr 13, 2022
dc89f48
- CollectionView: make progress on modular structure and implementati…
felix-schwarz Apr 13, 2022
ee90fa4
Merge branch 'milestone/11.10.0' (at 'fix/copy-timeout') into branch
felix-schwarz Apr 13, 2022
491facd
- SDK update for new functionality
felix-schwarz Apr 21, 2022
4e14155
- ClientItemViewController+ItemActions: provide standard implementati…
felix-schwarz Apr 21, 2022
3036f54
- address code review findings by @hosy in https://github.com/ownclou…
felix-schwarz Apr 25, 2022
217ebe5
- switch to new UTType APIs
felix-schwarz Apr 25, 2022
dd3239b
- ownCloudTests: fix compilation issues due to API changes
felix-schwarz Apr 25, 2022
01edb55
- migrate app to Swift 5
felix-schwarz Apr 26, 2022
f36e18e
- update SDK
felix-schwarz Apr 26, 2022
5b86651
- ThemeWindow: add static property .frontmostThemeWindow
felix-schwarz Apr 26, 2022
8aaf59b
- add KNOWN_ISSUES.md to keep track of user-visible known issues alon…
felix-schwarz May 5, 2022
7a359a2
- File Provider: make sure actions work with OCItems, not OCVFSNodes …
felix-schwarz May 5, 2022
ccd1671
- ClientContext
felix-schwarz May 6, 2022
3bb3484
- ClientContext: add .originatingViewController property to pass the …
felix-schwarz May 9, 2022
e68ae02
[milestone/11.10.0] Milestone 11.10.0 (#1117)
hosy May 17, 2022
57d2dba
fixed link in changelog files, which causes that calens did not creat…
May 19, 2022
171987a
[fix/changelog-11.10.0] Fixed Changelog Date 11.10.0 (#1126)
hosy May 19, 2022
ccee161
- ownCloudAppFramework:
felix-schwarz May 24, 2022
633fb60
- File Provider: disallow deletion, renaming and moving of a space's …
felix-schwarz May 24, 2022
d6bf596
- bump version to 219
felix-schwarz May 24, 2022
b9e93fc
- FileProvider:
felix-schwarz May 26, 2022
47337b1
- AlertView: add support for text alignment
felix-schwarz May 27, 2022
de3af5e
- bump app version to 221
felix-schwarz May 27, 2022
0343980
- add OCDataItem+InteractionProtocols allow OCDataItems to provide ha…
felix-schwarz May 30, 2022
95a3bfd
- SortBarCell: WIP
felix-schwarz May 30, 2022
c74d316
- CollectionView:
felix-schwarz Jun 10, 2022
fa2e0dc
- ClientContext:
felix-schwarz Jun 20, 2022
ffe536c
- Action: add new .dropAction location and add relevant actions there
felix-schwarz Jun 21, 2022
152ad2f
- Search
felix-schwarz Jun 28, 2022
ea17262
- ItemListCell:
felix-schwarz Jun 29, 2022
edfd339
- SearchScope: set result count default from 2 (debug value) to 100 (…
felix-schwarz Jun 29, 2022
b5ea3d4
- update known issues, add new ideas regarding location picker, colle…
felix-schwarz Jun 30, 2022
42e612a
- MessageGroupCell: change order of "Apply to all" label and switch, …
felix-schwarz Jul 5, 2022
2d9c0b4
Merge remote-tracking branch 'origin/master' into feature/graph-api
felix-schwarz Jul 25, 2022
b59c62b
Fix code review findings from #1101.
felix-schwarz Jul 29, 2022
10d6367
- support for App Providers
felix-schwarz Sep 8, 2022
6348314
Merge branch 'milestone/12.0' into feature/app-provider
felix-schwarz Sep 12, 2022
3c92e57
Calens changelog updated
felix-schwarz Sep 12, 2022
6055bd9
- ClientWebAppViewController: add view controller to present a WKWebV…
felix-schwarz Sep 19, 2022
4b9af63
- ClientWebAppViewController
felix-schwarz Sep 19, 2022
2900675
Fix App Provider review findings from #1151:
felix-schwarz Oct 6, 2022
e8b125e
- update SDK for additional bugfix
felix-schwarz Oct 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios-sdk
Submodule ios-sdk updated 80 files
+11 −0 CHANGELOG.md
+86 −2 ownCloudSDK.xcodeproj/project.pbxproj
+1 −0 ownCloudSDK/App Identity/OCAppIdentity.h
+62 −0 ownCloudSDK/App Providers/OCAppProvider.h
+162 −0 ownCloudSDK/App Providers/OCAppProvider.m
+52 −0 ownCloudSDK/App Providers/OCAppProviderApp.h
+103 −0 ownCloudSDK/App Providers/OCAppProviderApp.m
+50 −0 ownCloudSDK/App Providers/OCAppProviderFileType.h
+60 −0 ownCloudSDK/App Providers/OCAppProviderFileType.m
+3 −1 ownCloudSDK/Categories/Foundation/NSArray+OCMapping.h
+19 −2 ownCloudSDK/Categories/Foundation/NSArray+OCMapping.m
+1 −1 ownCloudSDK/Categories/Foundation/NSArray+ObjCRuntime.m
+2 −0 ownCloudSDK/Categories/Foundation/NSDate+OCDateParser.h
+23 −0 ownCloudSDK/Categories/Foundation/NSDate+OCDateParser.m
+5 −0 ownCloudSDK/Connection/Capabilities/OCCapabilities.h
+73 −0 ownCloudSDK/Connection/Capabilities/OCCapabilities.m
+31 −0 ownCloudSDK/Connection/NSError+OCISError.h
+76 −0 ownCloudSDK/Connection/NSError+OCISError.m
+367 −0 ownCloudSDK/Connection/OCConnection+AppProviders.m
+17 −1 ownCloudSDK/Connection/OCConnection+Tools.m
+23 −0 ownCloudSDK/Connection/OCConnection.h
+4 −0 ownCloudSDK/Connection/OCConnection.m
+1 −0 ownCloudSDK/Core/Data Sources/OCCore+DataSources.h
+5 −0 ownCloudSDK/Core/Data Sources/OCCore+DataSources.m
+5 −0 ownCloudSDK/Core/OCCore.h
+116 −151 ownCloudSDK/Core/OCCore.m
+1 −0 ownCloudSDK/Core/Resources/Resource/OCResource.h
+1 −0 ownCloudSDK/Core/Resources/Resource/OCResource.m
+36 −0 ownCloudSDK/Core/Resources/URLItems/OCResourceRequestURLItem.h
+73 −0 ownCloudSDK/Core/Resources/URLItems/OCResourceRequestURLItem.m
+29 −0 ownCloudSDK/Core/Resources/URLItems/OCResourceSourceURLItems.h
+136 −0 ownCloudSDK/Core/Resources/URLItems/OCResourceSourceURLItems.m
+1 −1 ownCloudSDK/Core/Sync/Actions/CopyMove/OCSyncActionCopyMove.m
+4 −1 ownCloudSDK/Core/Sync/Actions/Delete/OCSyncActionDelete.m
+1 −0 ownCloudSDK/Data Sources/OCDataTypes.h
+1 −0 ownCloudSDK/Data Sources/OCDataTypes.m
+5 −4 ownCloudSDK/Drive/OCDrive.h
+3 −2 ownCloudSDK/Drive/OCDrive.m
+4 −1 ownCloudSDK/Errors/NSError+OCError.h
+8 −0 ownCloudSDK/Errors/NSError+OCError.m
+5 −1 ownCloudSDK/Extensions/OCExtensionManager.h
+79 −0 ownCloudSDK/Extensions/OCExtensionManager.m
+1 −1 ownCloudSDK/File Handling/Checksums/OCChecksumAlgorithmSHA1.m
+4 −33 ownCloudSDK/GraphAPI/GeneratedTypes/GAUser.h
+11 −100 ownCloudSDK/GraphAPI/GeneratedTypes/GAUser.m
+29 −0 ownCloudSDK/HTTP/Request/NSDictionary+OCFormEncoding.h
+40 −0 ownCloudSDK/HTTP/Request/NSDictionary+OCFormEncoding.m
+1 −0 ownCloudSDK/HTTP/Request/OCHTTPDAVRequest.m
+1 −0 ownCloudSDK/HTTP/Request/OCHTTPRequest.h
+3 −16 ownCloudSDK/HTTP/Request/OCHTTPRequest.m
+1 −0 ownCloudSDK/HTTP/Status/OCHTTPStatus.h
+4 −0 ownCloudSDK/HTTP/Status/OCHTTPStatus.m
+10 −0 ownCloudSDK/Item/OCItem+OCFileURLMetadata.h
+10 −0 ownCloudSDK/Item/OCItem+OCFileURLMetadata.m
+37 −0 ownCloudSDK/Item/OCItem+OCTypeAlias.h
+167 −0 ownCloudSDK/Item/OCItem+OCTypeAlias.m
+10 −1 ownCloudSDK/Item/OCItem+OCXMLObjectCreation.m
+10 −1 ownCloudSDK/Item/OCItem.h
+8 −1 ownCloudSDK/Item/OCItem.m
+1 −0 ownCloudSDK/Logging/OCLogger.h
+30 −5 ownCloudSDK/Logging/OCLogger.m
+1 −0 ownCloudSDK/OCMacros.h
+4 −0 ownCloudSDK/OCTypes.h
+4 −0 ownCloudSDK/Query/Condition/OCQueryCondition.h
+4 −0 ownCloudSDK/Query/Condition/OCQueryCondition.m
+9 −0 ownCloudSDK/Resources/en.lproj/Localizable.strings
+148 −0 ownCloudSDK/Vaults/Database/OCDatabase+Schemas.m
+3 −3 ownCloudSDK/Vaults/Database/OCDatabase.h
+58 −0 ownCloudSDK/Vaults/Database/OCDatabase.m
+1 −0 ownCloudSDK/Vaults/Database/SQLite/OCSQLiteDB.h
+6 −0 ownCloudSDK/Vaults/Database/SQLite/OCSQLiteDB.m
+3 −0 ownCloudSDK/Vaults/OCVault+Internal.h
+3 −0 ownCloudSDK/Vaults/OCVault+Internal.m
+15 −1 ownCloudSDK/Vaults/OCVault.h
+275 −33 ownCloudSDK/Vaults/OCVault.m
+7 −0 ownCloudSDK/ownCloudSDK.h
+24 −0 ownCloudSDKTests/ConnectionTests.m
+3 −3 ownCloudSDKTests/DataSourceTests.m
+4 −0 ownCloudSDKTests/OCTestTarget.h
+10 −0 ownCloudSDKTests/OCTestTarget.m
12 changes: 12 additions & 0 deletions ownCloud.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@
DC0A35A124C1091400FB58FC /* UserInterfaceContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC0A35A024C1091400FB58FC /* UserInterfaceContext.swift */; };
DC0A5C432550C70800E6674B /* class-settings-sdk in Resources */ = {isa = PBXBuildFile; fileRef = DC0A5C422550C70800E6674B /* class-settings-sdk */; };
DC0B379420514E4700189B9A /* ServerListBookmarkCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC0B379320514E4700189B9A /* ServerListBookmarkCell.swift */; };
DC0CE19228C7DBE3009ABDFB /* OpenInWebAppAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC0CE19128C7DBE3009ABDFB /* OpenInWebAppAction.swift */; };
DC0CE19D28C89CD9009ABDFB /* CreateDocumentAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC0CE19C28C89CD9009ABDFB /* CreateDocumentAction.swift */; };
DC18898E218A773700CFB3F9 /* ownCloudMocking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DC0196A620F754CA00C41B78 /* ownCloudMocking.framework */; };
DC1B270C209CF34B004715E1 /* BookmarkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC1B270B209CF34B004715E1 /* BookmarkViewController.swift */; };
DC20DE5C21C01A3D0096000B /* ownCloudMocking.framework in EarlGrey Copy Files */ = {isa = PBXBuildFile; fileRef = DC0196A620F754CA00C41B78 /* ownCloudMocking.framework */; };
Expand Down Expand Up @@ -555,6 +557,7 @@
DCFC9ED128002335005D9144 /* CollectionViewCellProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCFC9ED028002335005D9144 /* CollectionViewCellProvider.swift */; };
DCFC9ED3280023BB005D9144 /* CollectionViewCellProvider+StandardImplementations.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCFC9ED2280023BB005D9144 /* CollectionViewCellProvider+StandardImplementations.swift */; };
DCFC9ED528002F33005D9144 /* CollectionViewCellConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCFC9ED428002F33005D9144 /* CollectionViewCellConfiguration.swift */; };
DCFE682728D869A400091D2A /* ClientWebAppViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCFE682628D869A400091D2A /* ClientWebAppViewController.swift */; };
DCFEF90926EFA45A001DC7A4 /* VendorServices+App.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCFEF90526EFA45A001DC7A4 /* VendorServices+App.swift */; };
DCFEFE2A236876BD009A142F /* OCLicenseManager.h in Headers */ = {isa = PBXBuildFile; fileRef = DCFEFE28236876BD009A142F /* OCLicenseManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
DCFEFE2B236876BD009A142F /* OCLicenseManager.m in Sources */ = {isa = PBXBuildFile; fileRef = DCFEFE29236876BD009A142F /* OCLicenseManager.m */; };
Expand Down Expand Up @@ -1249,6 +1252,8 @@
DC0B379320514E4700189B9A /* ServerListBookmarkCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListBookmarkCell.swift; sourceTree = "<group>"; };
DC0B37952051541C00189B9A /* ownCloud.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ownCloud.entitlements; sourceTree = "<group>"; };
DC0B37962051681600189B9A /* ThemeButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeButton.swift; sourceTree = "<group>"; };
DC0CE19128C7DBE3009ABDFB /* OpenInWebAppAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenInWebAppAction.swift; sourceTree = "<group>"; };
DC0CE19C28C89CD9009ABDFB /* CreateDocumentAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateDocumentAction.swift; sourceTree = "<group>"; };
DC136581208223F000FC0F60 /* OCBookmark+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "OCBookmark+Extension.swift"; sourceTree = "<group>"; };
DC1AC7CF2319ADAE002B7892 /* ScanViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanViewController.swift; sourceTree = "<group>"; };
DC1B270B209CF34B004715E1 /* BookmarkViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1550,6 +1555,7 @@
DCFC9ED028002335005D9144 /* CollectionViewCellProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewCellProvider.swift; sourceTree = "<group>"; };
DCFC9ED2280023BB005D9144 /* CollectionViewCellProvider+StandardImplementations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CollectionViewCellProvider+StandardImplementations.swift"; sourceTree = "<group>"; };
DCFC9ED428002F33005D9144 /* CollectionViewCellConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionViewCellConfiguration.swift; sourceTree = "<group>"; };
DCFE682628D869A400091D2A /* ClientWebAppViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientWebAppViewController.swift; sourceTree = "<group>"; };
DCFED971208095E200A2D984 /* ClientItemCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientItemCell.swift; sourceTree = "<group>"; };
DCFED9B920809B8900A2D984 /* ThemeTVGResource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThemeTVGResource.swift; sourceTree = "<group>"; };
DCFEF90526EFA45A001DC7A4 /* VendorServices+App.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "VendorServices+App.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2231,6 +2237,9 @@
0233F45D246E9D960095A799 /* UploadCameraMediaAction.swift */,
025F063224AA163C009D8FC5 /* DisplayExifMetadataAction.swift */,
39EF06AF25D6C3FC001E1E19 /* PresentationModeAction.swift */,
DC0CE19128C7DBE3009ABDFB /* OpenInWebAppAction.swift */,
DCFE682628D869A400091D2A /* ClientWebAppViewController.swift */,
DC0CE19C28C89CD9009ABDFB /* CreateDocumentAction.swift */,
);
path = "Actions+Extensions";
sourceTree = "<group>";
Expand Down Expand Up @@ -4224,6 +4233,7 @@
396BE4CA2289500E00B254A9 /* RoundedLabel.swift in Sources */,
394E1FFF233E43F5009D2897 /* LinksAction.swift in Sources */,
392DDB1424CF024D009E5406 /* ImportFilesController.swift in Sources */,
DC0CE19228C7DBE3009ABDFB /* OpenInWebAppAction.swift in Sources */,
396C82FB2319AFDD00938262 /* CollaborateAction.swift in Sources */,
0233F45E246E9D960095A799 /* UploadCameraMediaAction.swift in Sources */,
DC854936218331CF00782BA8 /* UserInterfaceSettingsSection.swift in Sources */,
Expand Down Expand Up @@ -4285,12 +4295,14 @@
6E5FC172221590B000F60846 /* DisplayHostViewController.swift in Sources */,
4C51727F22DE04BD001BC97F /* ScheduledTaskManager.swift in Sources */,
39BC9C3023DB831F0097C52D /* DocumentEditingAction.swift in Sources */,
DCFE682728D869A400091D2A /* ClientWebAppViewController.swift in Sources */,
DCB6C4D72453A6CA00C1EAE1 /* ClientAuthenticationUpdater.swift in Sources */,
399697F5260255B100E5AEBA /* PDFGotoPageAction.swift in Sources */,
3998F5D522411EDF00B66713 /* BorderedLabel.swift in Sources */,
DCC3701624D4D365008B0DEB /* OCScanJobActivity+DiagnosticGenerator.swift in Sources */,
39A243C424BDD9E100F4441F /* StaticLoginBundle.swift in Sources */,
DC27A19D20CAB602008ACB6C /* FileProviderInterfaceManager.swift in Sources */,
DC0CE19D28C89CD9009ABDFB /* CreateDocumentAction.swift in Sources */,
4C51727D22DE04BD001BC97F /* ScheduledTaskExtension.swift in Sources */,
025F063324AA163C009D8FC5 /* DisplayExifMetadataAction.swift in Sources */,
DCC085512293ED52008CC05C /* DisplaySettingsSection.swift in Sources */,
Expand Down
15 changes: 15 additions & 0 deletions ownCloud.xcodeproj/xcshareddata/xcschemes/ownCloud.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,21 @@
value = "[com.owncloud.action.copy,com.owncloud.action.move]"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "oc:action.open-in-web-app-mode"
value = "string:default-browser"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "oc:action.open-in-web-app-mode"
value = "string:in-app"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "oc:action.open-in-web-app-mode"
value = "string:in-app-with-default-browser-option"
isEnabled = "NO">
</EnvironmentVariable>
<EnvironmentVariable
key = "oc:bookmark.prepopulation"
value = "string:streaming"
Expand Down
1 change: 1 addition & 0 deletions ownCloud/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
OCExtensionManager.shared.addExtension(PDFGoToPageAction.actionExtension)
OCExtensionManager.shared.addExtension(ImportPasteboardAction.actionExtension)
OCExtensionManager.shared.addExtension(CutAction.actionExtension)
OCExtensionManager.shared.addExtension(CreateDocumentAction.actionExtension)

if UIDevice.current.isIpad {
// iPad only
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//
// ClientWebAppViewController.swift
// ownCloud
//
// Created by Felix Schwarz on 19.09.22.
// Copyright © 2022 ownCloud GmbH. All rights reserved.
//

/*
* Copyright (C) 2022, ownCloud GmbH.
*
* This code is covered by the GNU Public License Version 3.
*
* For distribution utilizing Apple mechanisms please see https://owncloud.org/contribute/iOS-license-exception/
* You should have received a copy of this license along with this program. If not, see <http://www.gnu.org/licenses/gpl-3.0.en.html>.
*
*/

import UIKit
import WebKit
import ownCloudAppShared

class ClientWebAppViewController: UIViewController, WKUIDelegate {
var urlRequest: URLRequest
var webView: WKWebView?

var shouldSendCloseEvent: Bool = true

init(with urlRequest: URLRequest) {
self.urlRequest = urlRequest

super.init(nibName: nil, bundle: nil)

self.isModalInPresentation = true
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

var webViewConfiguration: WKWebViewConfiguration {
let configuration = WKWebViewConfiguration()
let webSiteDataStore = WKWebsiteDataStore.nonPersistent()

configuration.websiteDataStore = webSiteDataStore
configuration.applicationNameForUserAgent = "MobileSafari" // Needed for some web apps that will present the desktop UI otherwise (f.ex. OnlyOffice as of 2022-09-19)

return configuration
}

override func loadView() {
let rootView = UIView()

webView = WKWebView(frame: .zero, configuration: webViewConfiguration)
webView?.translatesAutoresizingMaskIntoConstraints = false
webView?.uiDelegate = self

rootView.addSubview(webView!)

NSLayoutConstraint.activate([
webView!.leadingAnchor.constraint(equalTo: rootView.safeAreaLayoutGuide.leadingAnchor),
webView!.trailingAnchor.constraint(equalTo: rootView.safeAreaLayoutGuide.trailingAnchor),
webView!.topAnchor.constraint(equalTo: rootView.safeAreaLayoutGuide.topAnchor),
webView!.bottomAnchor.constraint(equalTo: rootView.safeAreaLayoutGuide.bottomAnchor)
])

view = rootView
}

override func viewDidLoad() {
super.viewDidLoad()

navigationItem.rightBarButtonItem = UIBarButtonItem(title: nil, image: UIImage(systemName: "xmark.circle.fill")?.withRenderingMode(.alwaysTemplate), primaryAction: UIAction(handler: { [weak self] _ in
if self?.shouldSendCloseEvent == true {
// Close via window.close(), which is calling dismissSecurely() once done
self?.closeWebWindow()

// Call dismissOnce() after 10 seconds regardless
OnMainThread(after: 10) {
self?.dismissOnce()
}
} else {
// Close directly
self?.closeWebWindow()
}
}))
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
webView?.load(urlRequest)
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)

// Drop web view
webView?.uiDelegate = nil
webView?.removeFromSuperview()
webView = nil
}

private var isDismissed = false
func dismissOnce() {
if !isDismissed {
isDismissed = true
self.dismiss(animated: true)
}
}

// window.close() handling
func closeWebWindow() {
webView?.evaluateJavaScript("window.close();")
}

// UI delegate
func webViewDidClose(_ webView: WKWebView) {
dismissOnce()
}
}
Loading