Skip to content

Commit

Permalink
✨ Numerous bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsetsonwheels committed Mar 2, 2023
1 parent 186ffe8 commit 9c0786a
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 23 deletions.
1 change: 1 addition & 0 deletions App/Views/Images/ImageDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ struct ImageDetailView: View {
method: .get,
authStrategy: self.imageAndMetadata.image.isPrivate ? .required : .none
).0
ImagePipeline.shared.cache.storeCachedData(data, for: self.request!)
self.isDownloadingToastPresented = false
} catch {
self.isDownloadingToastPresented = false
Expand Down
13 changes: 13 additions & 0 deletions App/Views/Images/ImageInformationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,21 @@ struct ImageInformationView: View {
}
Toggle("Private", isOn: .constant(self.imageAndMetadata.image.isPrivate))
.disabled(true)
}
Section {
Toggle("Locked", isOn: .constant(self.imageAndMetadata.image.lock.isLocked))
.disabled(true)
if self.imageAndMetadata.image.lock.isLocked,
let friendlyName = self.imageAndMetadata.image.lock.version?.friendlyName
{
LabeledContent("Version", value: friendlyName)
}
} header: {
Text("Lock")
} footer: {
if self.imageAndMetadata.image.lock.upgradable == true {
Text("New lock version available.\nUpgrade by editing this image.")
}
}
Section("ID") {
Button(action: self.copyID) {
Expand Down
15 changes: 8 additions & 7 deletions App/Views/Modifiers/OpenURLModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ struct OpenURLModifier: ViewModifier {
@State private var error: LocalizedAlertError?

private func validateURL(url: URL) -> Bool {
if (url.host() != "iamages.jkelol111.me" || url.scheme != "iamages") &&
(url.pathComponents.first != "api" || url.pathComponents.last != "embed")
if (url.host() == "iamages.jkelol111.me" || url.scheme == "iamages") &&
(url.pathComponents[safe: 1] == "api" && url.pathComponents.last == "embed")
{
return false
return true
}
return true
return false
}

func body(content: Content) -> some View {
Expand Down Expand Up @@ -152,9 +152,10 @@ struct OpenURLModifier: ViewModifier {
self.isImageSheetPresented = false
self.isLoadingToastPresented = true

switch url.pathComponents[safe: 1] {
switch url.pathComponents[safe: 2] {
case "images":
if let id = url.pathComponents[safe: 2] {
if let id = url.pathComponents[safe: 3] {
print(id)
Task {
do {
let image = try await self.globalViewModel.getImagePublicMetadata(id: id)
Expand All @@ -175,7 +176,7 @@ struct OpenURLModifier: ViewModifier {
}
}
case "collections":
if let id = url.pathComponents[safe: 2] {
if let id = url.pathComponents[safe: 3] {
Task {
do {
let collection = try self.globalViewModel.jsond.decode(
Expand Down
24 changes: 12 additions & 12 deletions Iamages.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 27;
CURRENT_PROJECT_VERSION = 29;
DEVELOPMENT_TEAM = 2VZNUT7D2E;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Widgets/Info.plist;
Expand All @@ -1017,7 +1017,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 4.1.0;
MARKETING_VERSION = 4.1.1;
PRODUCT_BUNDLE_IDENTIFIER = me.jkelol111.Iamages.Widgets;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand All @@ -1039,7 +1039,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 27;
CURRENT_PROJECT_VERSION = 29;
DEVELOPMENT_TEAM = 2VZNUT7D2E;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Widgets/Info.plist;
Expand All @@ -1051,7 +1051,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 4.1.0;
MARKETING_VERSION = 4.1.1;
PRODUCT_BUNDLE_IDENTIFIER = me.jkelol111.Iamages.Widgets;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand All @@ -1072,7 +1072,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 27;
CURRENT_PROJECT_VERSION = 29;
DEVELOPMENT_TEAM = 2VZNUT7D2E;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = ShareExtension/Info.plist;
Expand All @@ -1084,7 +1084,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 4.1.0;
MARKETING_VERSION = 4.1.1;
PRODUCT_BUNDLE_IDENTIFIER = me.jkelol111.Iamages.ShareExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand All @@ -1104,7 +1104,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 27;
CURRENT_PROJECT_VERSION = 29;
DEVELOPMENT_TEAM = 2VZNUT7D2E;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = ShareExtension/Info.plist;
Expand All @@ -1116,7 +1116,7 @@
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 4.1.0;
MARKETING_VERSION = 4.1.1;
PRODUCT_BUNDLE_IDENTIFIER = me.jkelol111.Iamages.ShareExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand Down Expand Up @@ -1251,7 +1251,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 27;
CURRENT_PROJECT_VERSION = 29;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"App/Preview Content\"";
DEVELOPMENT_TEAM = 2VZNUT7D2E;
Expand All @@ -1277,7 +1277,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 4.1.0;
MARKETING_VERSION = 4.1.1;
PRODUCT_BUNDLE_IDENTIFIER = me.jkelol111.Iamages;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand All @@ -1301,7 +1301,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 27;
CURRENT_PROJECT_VERSION = 29;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"App/Preview Content\"";
DEVELOPMENT_TEAM = 2VZNUT7D2E;
Expand All @@ -1327,7 +1327,7 @@
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.0;
MARKETING_VERSION = 4.1.0;
MARKETING_VERSION = 4.1.1;
PRODUCT_BUNDLE_IDENTIFIER = me.jkelol111.Iamages;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand Down
29 changes: 25 additions & 4 deletions ShareExtension/ShareView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct ShareView: View {

@FocusState private var focusedField: Field?
@State private var isLoggedIn: Bool = false
@State private var isCancelAlertPresented = false
@State private var isBusy: Bool = true

private func dismiss() {
Expand Down Expand Up @@ -75,10 +76,29 @@ struct ShareView: View {
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Cancel", action: self.dismiss)
.keyboardShortcut(.escape)
.disabled(self.uploadModel.isUploading || self.isBusy)
.tint(self.uploadModel.information.description.isEmpty ? .none : .red)
Button("Cancel") {
if !self.uploadModel.information.description.isEmpty ||
self.uploadModel.information.isPrivate ||
self.uploadModel.information.isLocked
{
self.isCancelAlertPresented = true
} else {
self.dismiss()
}
}
.keyboardShortcut(.escape)
.disabled(self.uploadModel.isUploading || self.isBusy)
.confirmationDialog(
"Leave without uploading?",
isPresented: self.$isCancelAlertPresented,
titleVisibility: .visible
) {
Button("Leave", role: .destructive) {
self.dismiss()
}
} message: {
Text("This image will not be uploaded")
}
}
ToolbarItem(placement: .primaryAction) {
Button("Upload") {
Expand All @@ -98,6 +118,7 @@ struct ShareView: View {
}
}
.tint(.orange)
.interactiveDismissDisabled()
.errorAlert(error: self.$uploadModel.error)
.onChange(of: self.uploadModel.information.isLocked) { isLocked in
self.uploadModel.information.lockKey = ""
Expand Down
5 changes: 5 additions & 0 deletions ShareExtension/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import SwiftUI
class ShareViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

// Prevent share sheet dismissal.
self.isModalInPresentation = true

let shareView = ShareView()
.environment(\.extensionContext, self.extensionContext)

Expand All @@ -11,6 +15,7 @@ class ShareViewController: UIViewController {
self.addChild(hostingController)
self.view.addSubview(hostingController.view)

// Expand hosted SwiftUI VC to sheet size.
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
hostingController.view.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
Expand Down
7 changes: 7 additions & 0 deletions Shared/Models/IamagesImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ struct IamagesImage: Codable, Identifiable, Hashable {
struct Lock: Codable, Hashable {
enum Version: Int, Codable {
case aes128gcm_argon2 = 1

var friendlyName: String {
switch self {
case .aes128gcm_argon2:
return NSLocalizedString("AES-128 GCM with Argon2 derived key (\(self.rawValue))", comment: "")
}
}
}

var isLocked: Bool
Expand Down

0 comments on commit 9c0786a

Please sign in to comment.