Skip to content

Commit

Permalink
Fixed Top notch problem + added imessage
Browse files Browse the repository at this point in the history
  • Loading branch information
arguiot committed May 26, 2020
1 parent 6f3242f commit 9ceabc4
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 17 deletions.
4 changes: 2 additions & 2 deletions CrypTool-iMessage/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionMainStoryboard</key>
Expand Down
13 changes: 12 additions & 1 deletion CrypTool.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
68C9AABA246330A30066563F /* MessagesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68C9AAB9246330A30066563F /* MessagesViewController.swift */; };
68C9AABD246330A30066563F /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 68C9AABB246330A30066563F /* MainInterface.storyboard */; };
68C9AABF246330AA0066563F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 68C9AABE246330AA0066563F /* Assets.xcassets */; };
68C9AAC3246330AA0066563F /* CrypTool-iMessage.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 68C9AAB4246330A30066563F /* CrypTool-iMessage.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
68C9AAC3246330AA0066563F /* CrypTool-iMessage.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 68C9AAB4246330A30066563F /* CrypTool-iMessage.appex */; platformFilter = ios; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
68C9AAC9246330CD0066563F /* Parser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68C9AAC8246330CD0066563F /* Parser.swift */; };
68C9AACA246331380066563F /* caesar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6814226F242A681B005C1F5C /* caesar.swift */; };
68C9AACB246331380066563F /* sha256.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68142270242A681B005C1F5C /* sha256.swift */; };
Expand All @@ -59,6 +59,7 @@
68C9AAD3246331380066563F /* ROT13.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68142278242A681B005C1F5C /* ROT13.swift */; };
68C9AAD4246331380066563F /* Rail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68142279242A681B005C1F5C /* Rail.swift */; };
68C9AAD52463313F0066563F /* Ciphers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68142288242A74BD005C1F5C /* Ciphers.swift */; };
68D9F85F247C694B0046AFE6 /* imessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68D9F85E247C694B0046AFE6 /* imessage.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -144,6 +145,7 @@
68C9AABE246330AA0066563F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
68C9AAC0246330AA0066563F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
68C9AAC8246330CD0066563F /* Parser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Parser.swift; sourceTree = "<group>"; };
68D9F85E247C694B0046AFE6 /* imessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = imessage.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -313,6 +315,7 @@
6885B0B2242A41F50075C219 /* Down.swift */,
68142290242A798A005C1F5C /* LoadingActivity.swift */,
6805279B242BB5BE0021F146 /* TextView.swift */,
68D9F85E247C694B0046AFE6 /* imessage.swift */,
);
path = "Special Views";
sourceTree = "<group>";
Expand Down Expand Up @@ -527,6 +530,7 @@
683C6BE324297609007A73DE /* LevelCell.swift in Sources */,
6814227D242A681B005C1F5C /* md5.swift in Sources */,
6814227E242A681B005C1F5C /* b64.swift in Sources */,
68D9F85F247C694B0046AFE6 /* imessage.swift in Sources */,
6885B0B3242A41F50075C219 /* Down.swift in Sources */,
683C6BE624298170007A73DE /* Level.swift in Sources */,
68142289242A74BD005C1F5C /* Ciphers.swift in Sources */,
Expand Down Expand Up @@ -592,6 +596,7 @@
};
68C9AAC2246330AA0066563F /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
platformFilter = ios;
target = 68C9AAB3246330A30066563F /* CrypTool-iMessage */;
targetProxy = 68C9AAC1246330AA0066563F /* PBXContainerItemProxy */;
};
Expand Down Expand Up @@ -738,6 +743,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = CrypTool/CrypTool.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_ASSET_PATHS = "\"CrypTool/Preview Content\"";
DEVELOPMENT_TEAM = 73CCF549YB;
ENABLE_PREVIEWS = YES;
Expand All @@ -762,6 +768,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = CrypTool/CrypTool.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_ASSET_PATHS = "\"CrypTool/Preview Content\"";
DEVELOPMENT_TEAM = 73CCF549YB;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -868,13 +875,15 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = "iMessage App Icon";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 73CCF549YB;
INFOPLIST_FILE = "CrypTool-iMessage/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.ArthurG.CrypTools.CrypTool-iMessage";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -888,13 +897,15 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = "iMessage App Icon";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 2;
DEVELOPMENT_TEAM = 73CCF549YB;
INFOPLIST_FILE = "CrypTool-iMessage/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 2.0;
PRODUCT_BUNDLE_IDENTIFIER = "com.ArthurG.CrypTools.CrypTool-iMessage";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
<key>CrypTool-iMessage.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
<key>CrypTool.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>
Expand Down
8 changes: 4 additions & 4 deletions CrypTool/Controllers/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ struct ContentView: View {
if #available(iOS 13.0, *) {
return UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.safeAreaInsets.top ?? 0 > 20
}else{
return UIApplication.shared.delegate?.window??.safeAreaInsets.top ?? 0 > 20
return UIApplication.shared.delegate?.window??.safeAreaInsets.top ?? 0 > 20
}

return false
}

var isMac: Bool {
Expand Down Expand Up @@ -76,7 +74,9 @@ struct ContentView: View {
.font(.system(size: 18, weight: .bold, design: .monospaced))
}
}.tag(1)
}.edgesIgnoringSafeArea(hasTopNotch ? [.top] : []).accentColor(Color(#colorLiteral(red: 0.07058823529, green: 0.4666666667, blue: 0.9215686275, alpha: 1)))
}
// .edgesIgnoringSafeArea(hasTopNotch ? [.top] : [])
.accentColor(Color(#colorLiteral(red: 0.07058823529, green: 0.4666666667, blue: 0.9215686275, alpha: 1)))
}
}

Expand Down
43 changes: 37 additions & 6 deletions CrypTool/Controllers/EncryptView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import SwiftUI
import MessageUI

struct EncryptView: View {
@State private var isOpen = false
Expand All @@ -17,6 +18,17 @@ struct EncryptView: View {
@State private var key = ""

@State private var encrypted = ""

@State var result: Result<MessageComposeResult, Error>? = nil
@State var isShowingMessageView = false

var shareableString: String {
"""
---------- \(self.ciphers.name[self.selection]) ----------
\(self.ciphers.get(self.ciphers.name[self.selection])(self.message, self.key))
---------- \(key) ----------
"""
}
var body: some View {
ZStack(alignment: .top) {
ScrollView {
Expand Down Expand Up @@ -68,12 +80,31 @@ struct EncryptView: View {
.frame(width: geometry.size.width - 40)
.overlay(RoundedRectangle(cornerRadius: 4).stroke(Color.black))

Button(action: {
UIPasteboard.general.string = self.ciphers.get(self.ciphers.name[self.selection])(self.message, self.key)
}) {
Text("Copy")
}
.padding()
HStack {
Button(action: {
UIPasteboard.general.string = self.ciphers.get(self.ciphers.name[self.selection])(self.message, self.key)
}) {
VStack {
Image(systemName: "doc.on.doc")
Text("Copy")
}
}
.padding()

Button(action: {
self.isShowingMessageView.toggle()
}) {
VStack {
Image(systemName: "message")
Text("Message")
}
}
.padding()
.disabled(!MFMessageComposeViewController.canSendText())
.sheet(isPresented: self.$isShowingMessageView) {
MessageView(result: self.$result, content: self.shareableString)
}
}.padding()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion CrypTool/Controllers/LearnView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct LearnView: View {
AF.request(location).responseJSON {
response in
if (response.error != nil) {
print(response.error?.localizedDescription)
print(response.error?.localizedDescription ?? "Error")
return
}
do {
Expand Down
2 changes: 1 addition & 1 deletion CrypTool/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
53 changes: 53 additions & 0 deletions CrypTool/Special Views/imessage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// imessage.swift
// CrypTool
//
// Created by Arthur Guiot on 2020-05-25.
// Copyright © 2020 Arthur Guiot. All rights reserved.
//

import SwiftUI
import MessageUI

struct MessageView: UIViewControllerRepresentable {

@Environment(\.presentationMode) var presentation
@Binding var result: Result<MessageComposeResult, Error>?
var content: String

class Coordinator: NSObject, MFMessageComposeViewControllerDelegate {
func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
defer {
$presentation.wrappedValue.dismiss()
}
self.result = .success(result)
}


@Binding var presentation: PresentationMode
@Binding var result: Result<MessageComposeResult, Error>?

init(presentation: Binding<PresentationMode>,
result: Binding<Result<MessageComposeResult, Error>?>) {
_presentation = presentation
_result = result
}
}

func makeCoordinator() -> Coordinator {
return Coordinator(presentation: presentation,
result: $result)
}

func makeUIViewController(context: UIViewControllerRepresentableContext<MessageView>) -> MFMessageComposeViewController {
let vc = MFMessageComposeViewController()
vc.messageComposeDelegate = context.coordinator
vc.body = self.content
return vc
}

func updateUIViewController(_ uiViewController: MFMessageComposeViewController,
context: UIViewControllerRepresentableContext<MessageView>) {

}
}

0 comments on commit 9ceabc4

Please sign in to comment.