From 95b209ff0209a16e7d8656521678d48989b64e4b Mon Sep 17 00:00:00 2001 From: mustii Date: Thu, 4 Feb 2021 22:00:19 +0300 Subject: [PATCH] Update app 2.0 --- FlatAero/FlatAero.xcodeproj/project.pbxproj | 8 +- FlatAero/FlatAero/AppDelegate.swift | 23 +- FlatAero/FlatAero/C_Link/FlatWrapper.swift | 30 +- .../Controllers/DecoderViewController.swift | 45 +- .../Controllers/ImportController.swift | 65 +- .../ImportFromFileController.swift | 94 ++- .../ImportFromUintArrayController.swift | 67 +- .../Controllers/MainViewController.swift | 80 +- .../Controllers/TextViewController.swift | 86 +- .../FlatAero/Extension/Colors+extenion.swift | 12 +- .../Extension/NSView+Constraints.swift | 37 +- FlatAero/FlatAero/Logging.swift | 16 +- FlatAero/FlatAero/Models/Errors.swift | 18 +- .../FlatAero/Models/ImportableTypes.swift | 2 +- FlatAero/FlatAero/Models/ImportedData.swift | 20 +- FlatAero/FlatAero/Models/PlaceHolder.swift | 6 +- FlatAero/FlatAero/Models/Schema.swift | 6 +- .../FlatAero/Models/TypesOfDisplayers.swift | 2 +- .../BaseOperations/AsyncOperation.swift | 14 +- .../BaseOperations/BaseOperation.swift | 24 +- .../ChainedAsyncOperation.swift | 79 +- .../Operations/ConvertOperation.swift | 31 + .../FlatAero/Operations/DecodeOperation.swift | 8 +- .../Operations/ValidateOperation.swift | 12 +- .../Presenter/DecodeViewPresenter.swift | 43 +- .../Presenter/ImportBinaryPresenter.swift | 14 +- .../Presenter/ImportFBSTextPresenter.swift | 13 +- .../FlatAero/Presenter/ImportPresenter.swift | 15 +- .../Presenter/ImportUIntArrayPresenter.swift | 14 +- .../Presenter/MainViewPresenter.swift | 9 +- .../FlatAero/Protocols/DecodeProtocols.swift | 3 +- .../FlatAero/Protocols/ImportFBSFile.swift | 31 +- FlatAero/FlatAero/Protocols/ImportFiles.swift | 20 +- .../FlatAero/Protocols/ImportsProtocols.swift | 19 +- .../Protocols/MainViewProtocols.swift | 12 +- FlatAero/FlatAero/Protocols/Router.swift | 2 +- FlatAero/FlatAero/Router/MainViewRouter.swift | 12 +- FlatAero/FlatAero/Styles/FBSStyling.swift | 2 +- FlatAero/FlatAero/Styles/Styling.swift | 31 +- FlatAero/FlatAero/UI/FlatAeroButton.swift | 6 +- FlatAero/FlatAero/UI/NSLabel.swift | 2 +- FlatAero/FlatAero/main.swift | 5 +- FlatAero/FlatAeroTests/FlatAeroTests.swift | 12 +- FlatAero/FlatAeroTests/FlatTests.swift | 149 +++- .../FlatAeroUITests/FlatAeroUITests.swift | 58 +- electron/index.js | 43 - electron/package-lock.json | 732 ------------------ electron/package.json | 15 - electron/views/index.html | 15 - flat | 2 +- swift.swiftformat | 25 + 51 files changed, 820 insertions(+), 1269 deletions(-) create mode 100644 FlatAero/FlatAero/Operations/ConvertOperation.swift delete mode 100644 electron/index.js delete mode 100644 electron/package-lock.json delete mode 100644 electron/package.json delete mode 100644 electron/views/index.html create mode 100644 swift.swiftformat diff --git a/FlatAero/FlatAero.xcodeproj/project.pbxproj b/FlatAero/FlatAero.xcodeproj/project.pbxproj index a9004c8..cf244eb 100644 --- a/FlatAero/FlatAero.xcodeproj/project.pbxproj +++ b/FlatAero/FlatAero.xcodeproj/project.pbxproj @@ -51,6 +51,7 @@ DF788369244F8F9C00B818E1 /* DecodeViewPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF788368244F8F9C00B818E1 /* DecodeViewPresenter.swift */; }; DF78836B244F900900B818E1 /* DecodeProtocols.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF78836A244F900900B818E1 /* DecodeProtocols.swift */; }; DF78836D244F962800B818E1 /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF78836C244F962800B818E1 /* Errors.swift */; }; + DF7F062E25CC796000E0D3D6 /* ConvertOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF7F062D25CC796000E0D3D6 /* ConvertOperation.swift */; }; DF95C949240D77BE009FA3C5 /* FlatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF95C948240D77BE009FA3C5 /* FlatTests.swift */; }; DFA8BDB0247315750006D34D /* DecodeOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFA8BDAF247315750006D34D /* DecodeOperation.swift */; }; DFAEDE37244E56C800B8E8CA /* FlatAeroButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFAEDE36244E56C800B8E8CA /* FlatAeroButton.swift */; }; @@ -197,6 +198,7 @@ DF788368244F8F9C00B818E1 /* DecodeViewPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodeViewPresenter.swift; sourceTree = ""; }; DF78836A244F900900B818E1 /* DecodeProtocols.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodeProtocols.swift; sourceTree = ""; }; DF78836C244F962800B818E1 /* Errors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = ""; }; + DF7F062D25CC796000E0D3D6 /* ConvertOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConvertOperation.swift; sourceTree = ""; }; DF95C948240D77BE009FA3C5 /* FlatTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlatTests.swift; sourceTree = ""; }; DFA8BDAF247315750006D34D /* DecodeOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecodeOperation.swift; sourceTree = ""; }; DFAEDE36244E56C800B8E8CA /* FlatAeroButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlatAeroButton.swift; sourceTree = ""; }; @@ -325,6 +327,7 @@ DF03B544247312F60028FB07 /* BaseOperations */, DF03B540247312A50028FB07 /* ValidateOperation.swift */, DFA8BDAF247315750006D34D /* DecodeOperation.swift */, + DF7F062D25CC796000E0D3D6 /* ConvertOperation.swift */, ); path = Operations; sourceTree = ""; @@ -719,6 +722,7 @@ DFF27C182442F6B30039FE42 /* ImportController.swift in Sources */, DF78836D244F962800B818E1 /* Errors.swift in Sources */, DFD067CD244AF8CA00173B21 /* FBSStyling.swift in Sources */, + DF7F062E25CC796000E0D3D6 /* ConvertOperation.swift in Sources */, DF09A941243A5097003FCFE6 /* NSView+Constraints.swift in Sources */, DF03B53F2473126A0028FB07 /* AsyncOperation.swift in Sources */, DF03B541247312A50028FB07 /* ValidateOperation.swift in Sources */, @@ -903,7 +907,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 1.2; + MARKETING_VERSION = 2.0; OTHER_LDFLAGS = ( "-Wl,-search_paths_first", "-Wl,-headerpad_max_install_names", @@ -942,7 +946,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 10.15; - MARKETING_VERSION = 1.2; + MARKETING_VERSION = 2.0; OTHER_LDFLAGS = ( "-Wl,-search_paths_first", "-Wl,-headerpad_max_install_names", diff --git a/FlatAero/FlatAero/AppDelegate.swift b/FlatAero/FlatAero/AppDelegate.swift index 9c44a74..4bab29e 100644 --- a/FlatAero/FlatAero/AppDelegate.swift +++ b/FlatAero/FlatAero/AppDelegate.swift @@ -10,19 +10,25 @@ import Cocoa import SwiftUI class AppDelegate: NSObject, NSApplicationDelegate { - + static let size = NSRect(x: 0, y: 0, width: 1000, height: 500) - + var window: NSWindow! var mainRouter: MainViewRouter! - + func applicationDidFinishLaunching(_ aNotification: Notification) { mainRouter = MainViewRouter() mainRouter.start() - + window = NSWindow( contentRect: AppDelegate.size, - styleMask: [.titled, .closable, .resizable, .miniaturizable, .fullSizeContentView], + styleMask: [ + .titled, + .closable, + .resizable, + .miniaturizable, + .fullSizeContentView, + ], backing: .buffered, defer: false) window.center() window.setFrameAutosaveName("Main Window") @@ -30,12 +36,13 @@ class AppDelegate: NSObject, NSApplicationDelegate { window.makeFirstResponder(mainRouter.navigation) window.makeKeyAndOrderFront(nil) } - + func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } - - @objc func abort() { + + @objc + func abort() { NSApplication.shared.terminate(self) } } diff --git a/FlatAero/FlatAero/C_Link/FlatWrapper.swift b/FlatAero/FlatAero/C_Link/FlatWrapper.swift index e39d2e2..9835bb3 100644 --- a/FlatAero/FlatAero/C_Link/FlatWrapper.swift +++ b/FlatAero/FlatAero/C_Link/FlatWrapper.swift @@ -9,53 +9,53 @@ import Foundation struct Flat { - + fileprivate var parser = Wrapper() fileprivate var schema: Schema - + init(schema _s: Schema) { schema = _s } - + func parser(_ array: inout [UInt8], type: ParseType = .flat) throws -> String { - + guard schema.hasRoot else { throw Errors.schemaRequiresRoot } - + guard !array.isEmpty else { throw Errors.invalidArrayInput } - + do { try schema.doesntInclude() } catch { throw error } - + var err: NSError? var str = "" switch type { case .flat: str = flat(&array, err: &err) - + case .json: str = json(&array, err: &err) } - + if let err = err { throw Errors.libraryError(e: err) } - + return str } - + func json(_ array: inout [UInt8], err: inout NSError?) -> String { - return parser.printJSON(fromBuffer: &array, from: schema.input, error: &err) + parser.printJSON(fromBuffer: &array, from: schema.input, error: &err) } - + func flat(_ array: inout [UInt8], err: inout NSError?) -> String { - return parser.printFLAT(fromBuffer: &array, from: schema.input, error: &err) + parser.printFLAT(fromBuffer: &array, from: schema.input, error: &err) } - + enum ParseType: Int { case flat, json } diff --git a/FlatAero/FlatAero/Controllers/DecoderViewController.swift b/FlatAero/FlatAero/Controllers/DecoderViewController.swift index a6e7f2f..6fdd883 100644 --- a/FlatAero/FlatAero/Controllers/DecoderViewController.swift +++ b/FlatAero/FlatAero/Controllers/DecoderViewController.swift @@ -9,7 +9,7 @@ import Cocoa class DecoderViewController: NSViewController, DecodeViewControllerDelegate { - + lazy var decodedLabel: NSLabel = { let lbl = NSLabel() lbl.stringValue = "Decoded FlatBuffer" @@ -17,67 +17,74 @@ class DecoderViewController: NSViewController, DecodeViewControllerDelegate { lbl.heightAnchor.constraint(equalToConstant: 20).isActive = true return lbl }() - + lazy var decodeButton: NSButton = { let btn = NSButton(title: "Decode", target: self, action: #selector(decode)) btn.translatesAutoresizingMaskIntoConstraints = false btn.widthAnchor.constraint(equalToConstant: 100).isActive = true return btn }() - + lazy var languagePopUpButton: NSPopUpButton = { let btn = NSPopUpButton() btn.addItems(withTitles: ["FLAT", "JSON"]) return btn }() - + lazy var decodedTextViewController: TextViewController = { let controller = TextViewController() controller.isEnabled = false return controller }() - + var presenter: DecodeViewPresenterDelegate! - + override func loadView() { view = NSView() } - + override func viewDidLoad() { super.viewDidLoad() setupView() } - - @objc func decode() { + + @objc + func decode() { presenter.type = Flat.ParseType(rawValue: languagePopUpButton.indexOfSelectedItem) ?? .flat decodedTextViewController.remove() presenter.decode() } - + func parsedBuffer(_ str: String) { decodedTextViewController.add(text: str) } } extension DecoderViewController { - + func setupView() { - + let stackView = NSStackView(views: [languagePopUpButton, decodeButton]) - + stackView.spacing = 50 stackView.distribution = .fill view.addSubview(decodedLabel) view.addSubview(stackView) addChild(decodedTextViewController) view.addSubview(decodedTextViewController.view) - - stackView.anchorInSuperViewDisregarding(edges: .bottom, padding: .init(top: 4, left: 4, bottom: 4, right: 4)) - + + stackView.anchorInSuperViewDisregarding( + edges: .bottom, + padding: .init(top: 4, left: 4, bottom: 4, right: 4)) + decodedLabel.anchorInSuperViewDisregarding(edges: .bottom, .top) - decodedLabel.topAnchor.constraint(equalTo: stackView.bottomAnchor, constant: 10).isActive = true - + decodedLabel.topAnchor.constraint( + equalTo: stackView.bottomAnchor, + constant: 10).isActive = true + decodedTextViewController.view.anchorInSuperViewDisregarding(edges: .top) - decodedTextViewController.view.topAnchor.constraint(equalTo: decodedLabel.bottomAnchor, constant: 10).isActive = true + decodedTextViewController.view.topAnchor.constraint( + equalTo: decodedLabel.bottomAnchor, + constant: 10).isActive = true } } diff --git a/FlatAero/FlatAero/Controllers/ImportController.swift b/FlatAero/FlatAero/Controllers/ImportController.swift index 654d4df..3dd3831 100644 --- a/FlatAero/FlatAero/Controllers/ImportController.swift +++ b/FlatAero/FlatAero/Controllers/ImportController.swift @@ -9,73 +9,90 @@ import Cocoa class ImportController: NSViewController, ImportControllerDelegate { - + var presenter: ImportPresenterDelegate! - + lazy var displayFromArrayOrBinaryFile: NSSegmentedControl = { - let control = NSSegmentedControl(labels: TypesOfDisplayers.types, trackingMode: .selectOne, target: self, action: #selector(handleSelection)) + let control = NSSegmentedControl( + labels: TypesOfDisplayers.types, + trackingMode: .selectOne, + target: self, + action: #selector(handleSelection)) control.translatesAutoresizingMaskIntoConstraints = false control.selectedSegment = 0 return control }() - + lazy var importUIntArrayController: ImportFromUintArrayController = { let controller = ImportFromUintArrayController() controller.presenter = ImportUIntArrayPresenter(controller: controller) return controller }() - + lazy var importBinaryFileController: ImportFromFileController = { let controller = ImportFromFileController() controller.presenter = ImportBinaryPresenter(controller: controller) return controller }() - + override func loadView() { view = NSView() } - + override func viewDidLoad() { super.viewDidLoad() - + view.addSubview(displayFromArrayOrBinaryFile) - displayFromArrayOrBinaryFile.topAnchor.constraint(equalTo: view.topAnchor, constant: 4).isActive = true - displayFromArrayOrBinaryFile.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 0.6).isActive = true + displayFromArrayOrBinaryFile.topAnchor.constraint( + equalTo: view.topAnchor, + constant: 4).isActive = true + displayFromArrayOrBinaryFile.widthAnchor.constraint( + equalTo: view.widthAnchor, + multiplier: 0.6).isActive = true displayFromArrayOrBinaryFile.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true - + view.addSubview(importUIntArrayController.view) importUIntArrayController.view.anchorInSuperViewDisregarding(edges: .top) - importUIntArrayController.view.topAnchor.constraint(equalTo: displayFromArrayOrBinaryFile.bottomAnchor, constant: 20).isActive = true + importUIntArrayController.view.topAnchor.constraint( + equalTo: displayFromArrayOrBinaryFile.bottomAnchor, + constant: 20).isActive = true importUIntArrayController.view.isHidden = true - + view.addSubview(importBinaryFileController.view) importBinaryFileController.view.anchorInSuperViewDisregarding(edges: .top) - importBinaryFileController.view.topAnchor.constraint(equalTo: displayFromArrayOrBinaryFile.bottomAnchor, constant: 20).isActive = true + importBinaryFileController.view.topAnchor.constraint( + equalTo: displayFromArrayOrBinaryFile.bottomAnchor, + constant: 20).isActive = true } - + } extension ImportController { - - @objc func handleSelection() { + + @objc + func handleSelection() { Logging.logger.info("User switched between input methods") presenter.switchDisplayedControllers(of: displayFromArrayOrBinaryFile.indexOfSelectedItem) } - + func should(displayController isHidden: Bool) { importUIntArrayController.view.isHidden = isHidden importBinaryFileController.view.isHidden = !isHidden } - - func fetchData() -> ImportedData { + + func fetchData() -> SelectedData { guard let selection = TypesOfDisplayers(rawValue: displayFromArrayOrBinaryFile.indexOfSelectedItem) else { fatalError("Selection has an issue!") } switch selection { case .array: - return importUIntArrayController.presenter.data - + return SelectedData( + decoding: .array, + data: importUIntArrayController.presenter.data) + case .file: - return importBinaryFileController.presenter.data + return SelectedData( + decoding: .file, + data: importBinaryFileController.presenter.data) } } - + } diff --git a/FlatAero/FlatAero/Controllers/ImportFromFileController.swift b/FlatAero/FlatAero/Controllers/ImportFromFileController.swift index 97d67bd..fadd47c 100644 --- a/FlatAero/FlatAero/Controllers/ImportFromFileController.swift +++ b/FlatAero/FlatAero/Controllers/ImportFromFileController.swift @@ -9,58 +9,59 @@ import Cocoa class ImportFromFileController: NSViewController, ImportBinaryControllerDelegate { - + private var padding: NSEdgeInsets = .init(top: 8, left: 8, bottom: 8, right: 8) - + var presenter: ImportBinaryPresenterDelegate! - + var importBinaryTable: NSLabel! var pathBinaryTextField: NSTextField! var importBinaryFileButton: FlatAeroButton! - + var importTable: NSLabel! var pathTextField: NSTextField! var importFBSFileButton: FlatAeroButton! - + lazy var fbsTextViewController: TextViewController = { let controller = TextViewController() controller.delegate = self controller.textViewType = .fbsFile return controller }() - + override func loadView() { view = NSView() } - + override func viewDidLoad() { super.viewDidLoad() setupView() } - + } extension ImportFromFileController: BuildImportFileView, ImportFiles { - - @objc func importFile(_ sender: Any) { + + @objc + func importFile(_ sender: Any) { guard let type = (sender as? FlatAeroButton)?.type else { return } Logging.logger.info("Importing \(type) file") switch type { case .fbsFile: importFile(in: view, type: type) - + case .binary: importFile(in: view, type: type, fileTypes: ImportableTypes.BinaryFiles) } } - + func selectedFile(_ url: URL, ofType type: ImportableTypes) { do { try openFile(from: url, type: type) switch type { case .binary: pathBinaryTextField.stringValue = url.absoluteString - + case .fbsFile: pathTextField.stringValue = url.absoluteString } @@ -68,29 +69,29 @@ extension ImportFromFileController: BuildImportFileView, ImportFiles { NotificationCenter.default.post(name: .flatAeroError, object: error) } } - + func set(data: Data) { presenter.binaryFile = data } - + func set(fbs: String) { presenter.set(fbs) } - + func present(fbs: String?) { guard let fbs = fbs else { return } fbsTextViewController.add(text: fbs) } - + } extension ImportFromFileController: TextViewcontrollerDelegate { - + func textDidChange(in type: ImportableTypes) { switch type { case .binary: break - + case .fbsFile: presenter.fbsFile = fbsTextViewController.text } @@ -98,41 +99,60 @@ extension ImportFromFileController: TextViewcontrollerDelegate { } extension ImportFromFileController { - + func setupView() { setupBinaryImportView() setupFBSImporterView() - - importBinaryTable.anchorInSuperViewDisregarding(edges: .bottom, padding: padding) - importTable.anchorInSuperViewDisregarding(edges: .top, .bottom, padding: padding) - importTable.topAnchor.constraint(equalTo: pathBinaryTextField.bottomAnchor, constant: 10).isActive = true - + + importBinaryTable.anchorInSuperViewDisregarding( + edges: .bottom, + padding: padding) + importTable.anchorInSuperViewDisregarding( + edges: .top, + .bottom, + padding: padding) + importTable.topAnchor.constraint( + equalTo: pathBinaryTextField.bottomAnchor, + constant: 10).isActive = true + view.addSubview(fbsTextViewController.view) - fbsTextViewController.view.topAnchor.constraint(equalTo: importFBSFileButton.bottomAnchor, constant: 10).isActive = true - fbsTextViewController.view.anchorInSuperViewDisregarding(edges: .top, padding: padding) - + fbsTextViewController.view.topAnchor.constraint( + equalTo: importFBSFileButton.bottomAnchor, + constant: 10).isActive = true + fbsTextViewController.view.anchorInSuperViewDisregarding( + edges: .top, + padding: padding) + importFBSFileButton.action = #selector(importFile) importBinaryFileButton.action = #selector(importFile) } - + func setupBinaryImportView() { - + importBinaryTable = importTableConstructor pathBinaryTextField = pathTextFieldConstructor importBinaryFileButton = importFBSFileButtonConstructor - + importBinaryFileButton.type = .binary importBinaryTable.stringValue = "Import binary file" - - let importerViewStack = NSStackView(views: [pathBinaryTextField, importBinaryFileButton]) + + let importerViewStack = NSStackView(views: [ + pathBinaryTextField, + importBinaryFileButton, + ]) importerViewStack.spacing = 10 importerViewStack.distribution = .fillProportionally - + view.addSubview(importBinaryTable) view.addSubview(importerViewStack) - - importerViewStack.topAnchor.constraint(equalTo: importBinaryTable.bottomAnchor, constant: 10).isActive = true - importerViewStack.anchorInSuperViewDisregarding(edges: .top, .bottom, padding: .init(top: 8, left: 8, bottom: 8, right: 8)) + + importerViewStack.topAnchor.constraint( + equalTo: importBinaryTable.bottomAnchor, + constant: 10).isActive = true + importerViewStack.anchorInSuperViewDisregarding( + edges: .top, + .bottom, + padding: .init(top: 8, left: 8, bottom: 8, right: 8)) // fbsTextViewController.add(text: PlaceHolder.) } } diff --git a/FlatAero/FlatAero/Controllers/ImportFromUintArrayController.swift b/FlatAero/FlatAero/Controllers/ImportFromUintArrayController.swift index 0679831..d57170a 100644 --- a/FlatAero/FlatAero/Controllers/ImportFromUintArrayController.swift +++ b/FlatAero/FlatAero/Controllers/ImportFromUintArrayController.swift @@ -9,15 +9,15 @@ import Cocoa class ImportFromUintArrayController: NSViewController, ImportUIntControllerDelegate, TextViewcontrollerDelegate { - + private var padding: NSEdgeInsets = .init(top: 8, left: 8, bottom: 8, right: 8) - + var importTable: NSLabel! var pathTextField: NSTextField! var importFBSFileButton: FlatAeroButton! - + var presenter: ImportUIntArrayPresenterDelegate! - + lazy var createArray: NSLabel = { let lbl = NSLabel() lbl.stringValue = "\(PlaceHolder.exampleArray)" @@ -25,14 +25,14 @@ class ImportFromUintArrayController: NSViewController, ImportUIntControllerDeleg lbl.heightAnchor.constraint(equalToConstant: 20).isActive = true return lbl }() - + lazy var fbsTextViewController: TextViewController = { let controller = TextViewController() controller.textViewType = .fbsFile controller.delegate = self return controller }() - + lazy var uintArrayViewController: TextViewController = { let controller = TextViewController() controller.textViewType = .binary @@ -40,11 +40,11 @@ class ImportFromUintArrayController: NSViewController, ImportUIntControllerDeleg controller.view.translatesAutoresizingMaskIntoConstraints = false return controller }() - + override func loadView() { view = NSView() } - + override func viewDidLoad() { super.viewDidLoad() setupView() @@ -52,13 +52,14 @@ class ImportFromUintArrayController: NSViewController, ImportUIntControllerDeleg } extension ImportFromUintArrayController: BuildImportFileView, ImportFiles { - - @objc func importFile(_ sender: Any) { + + @objc + func importFile(_ sender: Any) { guard let type = (sender as? FlatAeroButton)?.type, type == .fbsFile else { return } Logging.logger.info("Importing fbs file") importFile(in: view, type: type) } - + func selectedFile(_ url: URL, ofType type: ImportableTypes) { do { try openFile(from: url, type: type) @@ -68,47 +69,61 @@ extension ImportFromUintArrayController: BuildImportFileView, ImportFiles { NotificationCenter.default.post(name: .flatAeroError, object: error) } } - + func set(data: Data) {} - + func set(fbs: String) { presenter.set(fbs) } - + func present(fbs: String?) { guard let fbs = fbs else { return } fbsTextViewController.add(text: fbs) } - + func textDidChange(in type: ImportableTypes) { switch type { case .binary: - var modifiedText = uintArrayViewController.text.replacingOccurrences(of: "[", with: "").replacingOccurrences(of: "]", with: "") + var modifiedText = uintArrayViewController.text.replacingOccurrences( + of: "[", + with: "").replacingOccurrences(of: "]", with: "") modifiedText = modifiedText.replacingOccurrences(of: " ", with: "") presenter.binaryData = modifiedText.components(separatedBy: ",").map( { UInt8($0) }).compactMap({ $0 }) - + case .fbsFile: presenter.fbsFile = fbsTextViewController.text } } - + func setupView() { setupFBSImporterView() - let stackView = NSStackView(views: [createArray, uintArrayViewController.view]) + let stackView = NSStackView(views: [ + createArray, + uintArrayViewController.view, + ]) stackView.orientation = .vertical stackView.spacing = 10 stackView.alignment = .leading - + view.addSubview(stackView) view.addSubview(fbsTextViewController.view) stackView.anchorInSuperViewDisregarding(edges: .bottom, padding: padding) uintArrayViewController.view.heightAnchor.constraint(equalToConstant: 100).isActive = true - - importTable.anchorInSuperViewDisregarding(edges: .top, .bottom, padding: padding) - importTable.topAnchor.constraint(equalTo: stackView.bottomAnchor, constant: 10).isActive = true - - fbsTextViewController.view.topAnchor.constraint(equalTo: importFBSFileButton.bottomAnchor, constant: 10).isActive = true - fbsTextViewController.view.anchorInSuperViewDisregarding(edges: .top, padding: padding) + + importTable.anchorInSuperViewDisregarding( + edges: .top, + .bottom, + padding: padding) + importTable.topAnchor.constraint( + equalTo: stackView.bottomAnchor, + constant: 10).isActive = true + + fbsTextViewController.view.topAnchor.constraint( + equalTo: importFBSFileButton.bottomAnchor, + constant: 10).isActive = true + fbsTextViewController.view.anchorInSuperViewDisregarding( + edges: .top, + padding: padding) importFBSFileButton.action = #selector(importFile) } } diff --git a/FlatAero/FlatAero/Controllers/MainViewController.swift b/FlatAero/FlatAero/Controllers/MainViewController.swift index 5df0b06..11eb341 100644 --- a/FlatAero/FlatAero/Controllers/MainViewController.swift +++ b/FlatAero/FlatAero/Controllers/MainViewController.swift @@ -9,54 +9,69 @@ import Cocoa class MainViewController: NSViewController, MainViewControllerImportsDelegate { - + var presenter: MainViewPresenterDelegate? - + lazy var importController: ImportController = { let controller = ImportController() - controller.presenter = ImportPresenter(importControllerDelegate: controller, parent: self) + controller.presenter = ImportPresenter( + importControllerDelegate: controller, + parent: self) return controller }() - + lazy var decoderController: DecoderViewController = { let controller = DecoderViewController() - controller.presenter = DecodeViewPresenter(controller: controller, parent: self) + controller.presenter = DecodeViewPresenter( + controller: controller, + parent: self) return controller }() - + override func loadView() { - self.view = NSView() + view = NSView() } - + init() { super.init(nibName: nil, bundle: nil) } - + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + override func viewDidLoad() { super.viewDidLoad() view.frame = AppDelegate.size - + addChild(importController) addChild(decoderController) view.addSubview(importController.view) view.addSubview(decoderController.view) - importController.view.anchorInSuperViewDisregarding(edges: .trailing, padding: .init(top: 24, left: 8, bottom: 8, right: 8)) - decoderController.view.anchorInSuperViewDisregarding(edges: .leading, padding: .init(top: 24, left: 8, bottom: 8, right: 8)) - decoderController.view.leadingAnchor.constraint(equalTo: importController.view.trailingAnchor, constant: 10).isActive = true - + let padding = NSEdgeInsets(top: 40, left: 8, bottom: 8, right: 8) + importController.view.anchorInSuperViewDisregarding( + edges: .trailing, + padding: padding) + decoderController.view.anchorInSuperViewDisregarding( + edges: .leading, + padding: padding) + decoderController.view.leadingAnchor.constraint( + equalTo: importController.view.trailingAnchor, + constant: 10).isActive = true + importController.view.widthAnchor.constraint(greaterThanOrEqualToConstant: (AppDelegate.size.width / 2) - 8).isActive = true decoderController.view.widthAnchor.constraint(equalTo: importController.view.widthAnchor).isActive = true } - + override func viewWillAppear() { super.viewWillAppear() - NotificationCenter.default.addObserver(self, selector: #selector(handle), name: .flatAeroError, object: nil) + NotificationCenter.default.addObserver( + self, + selector: #selector(handle), + name: .flatAeroError, + object: nil) } - + override func viewWillDisappear() { super.viewWillDisappear() NotificationCenter.default.removeObserver(self) @@ -64,22 +79,25 @@ class MainViewController: NSViewController, MainViewControllerImportsDelegate { } extension MainViewController: MainViewControllerDecodeDelegate { - - func fetchData() -> ImportedData { - return importController.presenter.prepareData() + + func fetchData() -> SelectedData { + importController.presenter.fetchData() } } extension MainViewController: MainViewControllerPresenterDelegate { - - @objc func handle(_ notification: Notification) { - guard notification.name == .flatAeroError, let err = notification.object as? Errors else { return } - Logging.logger.error(err) - let alert = NSAlert() - alert.messageText = "Error" - alert.informativeText = err.errorDescription ?? "Unknown Error Occurred" - alert.alertStyle = .warning - alert.addButton(withTitle: "OK") - alert.runModal() + + @objc + func handle(_ notification: Notification) { + DispatchQueue.main.async { + guard notification.name == .flatAeroError, let err = notification.object as? Errors else { return } + Logging.logger.error(err) + let alert = NSAlert() + alert.messageText = "Error" + alert.informativeText = err.errorDescription ?? "Unknown Error Occurred" + alert.alertStyle = .warning + alert.addButton(withTitle: "OK") + alert.runModal() + } } } diff --git a/FlatAero/FlatAero/Controllers/TextViewController.swift b/FlatAero/FlatAero/Controllers/TextViewController.swift index a0b36a9..2c6bdae 100644 --- a/FlatAero/FlatAero/Controllers/TextViewController.swift +++ b/FlatAero/FlatAero/Controllers/TextViewController.swift @@ -8,36 +8,38 @@ import Cocoa -protocol TextViewcontrollerDelegate: class { +protocol TextViewcontrollerDelegate: AnyObject { func textDidChange(in type: ImportableTypes) } class TextViewController: NSViewController, NSTextViewDelegate { - + var styler: Styling! var highlightedText: String = "" - + var textViewType: ImportableTypes! var text: String { get { - return textView.string + textView.string } } - + weak var delegate: TextViewcontrollerDelegate? - + fileprivate lazy var textStorage = NSTextStorage() fileprivate lazy var layoutManager = NSLayoutManager() fileprivate lazy var textContainer = NSTextContainer() - fileprivate lazy var textView: NSTextView = NSTextView(frame: CGRect(), textContainer: textContainer) + fileprivate lazy var textView: NSTextView = NSTextView( + frame: CGRect(), + textContainer: textContainer) fileprivate lazy var scrollview = NSScrollView() - + var isEnabled: Bool = true - + override func loadView() { view = NSView() } - + override func viewDidLoad() { super.viewDidLoad() setupLayout() @@ -45,62 +47,78 @@ class TextViewController: NSViewController, NSTextViewDelegate { setupUI(isHorizontalScrollingEnabled: false) setupTextStack() } - + func remove() { textView.string = "" highlightedText = "" } - + func add(text: String) { - let att = [NSAttributedString.Key.foregroundColor: NSColor.white, .font: NSFont.systemFont(ofSize: 14)] - textView.textStorage?.append(NSAttributedString(string: text, - attributes: att)) + let att = [ + NSAttributedString.Key.foregroundColor: NSColor.white, + .font: NSFont.systemFont(ofSize: 14), + ] + textView.textStorage?.append(NSAttributedString( + string: text, + attributes: att)) } - + } extension TextViewController { - + fileprivate func setupTextStack() { textStorage.addLayoutManager(layoutManager) layoutManager.addTextContainer(textContainer) } - + fileprivate func setupUI(isHorizontalScrollingEnabled: Bool) { textView.delegate = self let contentSize = scrollview.contentSize - textContainer.containerSize = CGSize(width: contentSize.width, height: CGFloat.greatestFiniteMagnitude) + textContainer.containerSize = CGSize( + width: contentSize.width, + height: CGFloat.greatestFiniteMagnitude) textContainer.widthTracksTextView = true - + textView.minSize = CGSize(width: 0, height: 0) - textView.maxSize = CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude) + textView.maxSize = CGSize( + width: CGFloat.greatestFiniteMagnitude, + height: CGFloat.greatestFiniteMagnitude) textView.isVerticallyResizable = true textView.isHorizontallyResizable = isHorizontalScrollingEnabled - textView.frame = CGRect(x: 0, y: 0, width: contentSize.width, height: contentSize.height) + textView.frame = CGRect( + x: 0, + y: 0, + width: contentSize.width, + height: contentSize.height) textView.autoresizingMask = [.width] textView.isEditable = true textView.isSelectable = true textView.backgroundColor = .clear textView.delegate = self textStorage.delegate = self - + scrollview.borderType = .noBorder scrollview.hasVerticalScroller = true scrollview.hasHorizontalScroller = isHorizontalScrollingEnabled scrollview.documentView = textView scrollview.backgroundColor = .background } - + fileprivate func setupLayout() { view.addSubview(scrollview) scrollview.translatesAutoresizingMaskIntoConstraints = false scrollview.fillSuperView() } - - func textView(_ textView: NSTextView, shouldChangeTextIn affectedCharRange: NSRange, replacementString: String?) -> Bool { - return isEnabled + + func textView( + _ textView: NSTextView, + shouldChangeTextIn affectedCharRange: NSRange, + replacementString: String?) -> Bool + { + isEnabled } - + func textDidChange(_ notification: Notification) { guard notification.name == NSText.didChangeNotification else { return } delegate?.textDidChange(in: textViewType) @@ -108,10 +126,12 @@ extension TextViewController { } extension TextViewController: NSTextStorageDelegate { - - func textStorage(_ textStorage: NSTextStorage, - didProcessEditing editedMask: NSTextStorageEditActions, - range editedRange: NSRange, - changeInLength delta: Int) { + + func textStorage( + _ textStorage: NSTextStorage, + didProcessEditing editedMask: NSTextStorageEditActions, + range editedRange: NSRange, + changeInLength delta: Int) + { } } diff --git a/FlatAero/FlatAero/Extension/Colors+extenion.swift b/FlatAero/FlatAero/Extension/Colors+extenion.swift index b5b2f9d..a733df9 100644 --- a/FlatAero/FlatAero/Extension/Colors+extenion.swift +++ b/FlatAero/FlatAero/Extension/Colors+extenion.swift @@ -9,15 +9,15 @@ import Cocoa extension NSColor { - + convenience init(hex: Int) { let red = CGFloat((hex & 0xFF0000) >> 16) / 255.0 let green = CGFloat((hex & 0xFF00) >> 8) / 255.0 - let blue = CGFloat((hex & 0xFF)) / 255.0 + let blue = CGFloat(hex & 0xFF) / 255.0 self.init(calibratedRed: red, green: green, blue: blue, alpha: 1.0) } - - static var background: NSColor { return NSColor(hex: 0x292a2f) } - - static var codeMainColor: NSColor { return NSColor(hex: 0xef82b1) } + + static var background: NSColor { NSColor(hex: 0x292a2f) } + + static var codeMainColor: NSColor { NSColor(hex: 0xef82b1) } } diff --git a/FlatAero/FlatAero/Extension/NSView+Constraints.swift b/FlatAero/FlatAero/Extension/NSView+Constraints.swift index 0fa8566..786710f 100644 --- a/FlatAero/FlatAero/Extension/NSView+Constraints.swift +++ b/FlatAero/FlatAero/Extension/NSView+Constraints.swift @@ -9,37 +9,52 @@ import Cocoa extension NSView { - + enum Edges { case top, bottom, leading, trailing } - + func fillSuperView(padding: NSEdgeInsets = .init()) { translatesAutoresizingMaskIntoConstraints = false if let _super = superview { NSLayoutConstraint.activate([ topAnchor.constraint(equalTo: _super.topAnchor, constant: padding.top), - bottomAnchor.constraint(equalTo: _super.bottomAnchor, constant: -padding.bottom), - leadingAnchor.constraint(equalTo: _super.leadingAnchor, constant: padding.left), - trailingAnchor.constraint(equalTo: _super.trailingAnchor, constant: -padding.right) + bottomAnchor.constraint( + equalTo: _super.bottomAnchor, + constant: -padding.bottom), + leadingAnchor.constraint( + equalTo: _super.leadingAnchor, + constant: padding.left), + trailingAnchor.constraint( + equalTo: _super.trailingAnchor, + constant: -padding.right), ]) } } - - func anchorInSuperViewDisregarding(edges: Edges..., padding: NSEdgeInsets = .init()) { + + func anchorInSuperViewDisregarding( + edges: Edges..., + padding: NSEdgeInsets = .init()) + { translatesAutoresizingMaskIntoConstraints = false - + if let _super = superview, !edges.contains(.top) { topAnchor.constraint(equalTo: _super.topAnchor, constant: padding.top).isActive = true } if let _super = superview, !edges.contains(.bottom) { - bottomAnchor.constraint(equalTo: _super.bottomAnchor, constant: -padding.bottom).isActive = true + bottomAnchor.constraint( + equalTo: _super.bottomAnchor, + constant: -padding.bottom).isActive = true } if let _super = superview, !edges.contains(.leading) { - leadingAnchor.constraint(equalTo: _super.leadingAnchor, constant: padding.left).isActive = true + leadingAnchor.constraint( + equalTo: _super.leadingAnchor, + constant: padding.left).isActive = true } if let _super = superview, !edges.contains(.trailing) { - trailingAnchor.constraint(equalTo: _super.trailingAnchor, constant: -padding.right).isActive = true + trailingAnchor.constraint( + equalTo: _super.trailingAnchor, + constant: -padding.right).isActive = true } } } diff --git a/FlatAero/FlatAero/Logging.swift b/FlatAero/FlatAero/Logging.swift index 89818aa..cd9643c 100644 --- a/FlatAero/FlatAero/Logging.swift +++ b/FlatAero/FlatAero/Logging.swift @@ -6,22 +6,24 @@ // Copyright © 2020 Mustafa Khalil. All rights reserved. // -import SwiftyBeaver import FlatBuffers +import SwiftyBeaver struct Logging { - + static let logger = SwiftyBeaver.self - + static func __init() { guard let url = Bundle.main.url(forResource: "keys", withExtension: "mon"), - let data = try? Data(contentsOf: url) else { + let data = try? Data(contentsOf: url) else + { return } let keys = LogKeys.getRootAsLogKeys(bb: ByteBuffer(data: data)) - let platform = SBPlatformDestination(appID: keys.appId ?? "", - appSecret: keys.appSecret ?? "", - encryptionKey: keys.encryption ?? "") + let platform = SBPlatformDestination( + appID: keys.appId ?? "", + appSecret: keys.appSecret ?? "", + encryptionKey: keys.encryption ?? "") Logging.logger.addDestination(platform) Logging.logger.addDestination(ConsoleDestination()) } diff --git a/FlatAero/FlatAero/Models/Errors.swift b/FlatAero/FlatAero/Models/Errors.swift index 8c041ce..962736f 100644 --- a/FlatAero/FlatAero/Models/Errors.swift +++ b/FlatAero/FlatAero/Models/Errors.swift @@ -10,31 +10,31 @@ import Foundation enum Errors: Error, LocalizedError { case invalidArrayInput, libraryError(e: Error), schemaRequiresRoot, - flatAeroCantHandleImports, couldntOpenFile, importedDataNotFound, invalidTableOrBuffer, noInputPassedToDecode - + flatAeroCantHandleImports, couldntOpenFile, importedDataNotFound, invalidTableOrBuffer, noInputPassedToDecode + var errorDescription: String? { switch self { case .invalidArrayInput: return "The input array is invalid or empty please check it!" - + case .schemaRequiresRoot: return "Schema is invalid!\n Check if the Schema has root_type" - + case .libraryError(let err): return err.localizedDescription - + case .flatAeroCantHandleImports: return "FlatAero cant handle flatbuffers imports yet." - + case .couldntOpenFile: return "Couldnt open file" - + case .importedDataNotFound: return "Couldnt import data! Something terrible happened!" - + case .invalidTableOrBuffer: return "Invalid Data! Something terrible happened!" - + case .noInputPassedToDecode: return "Ooooops! Our operations arent working please report this issue to flataero!" } diff --git a/FlatAero/FlatAero/Models/ImportableTypes.swift b/FlatAero/FlatAero/Models/ImportableTypes.swift index adcecdc..146b590 100644 --- a/FlatAero/FlatAero/Models/ImportableTypes.swift +++ b/FlatAero/FlatAero/Models/ImportableTypes.swift @@ -10,6 +10,6 @@ import Foundation enum ImportableTypes { case fbsFile, binary - + static let BinaryFiles = ["mon", "bin"] } diff --git a/FlatAero/FlatAero/Models/ImportedData.swift b/FlatAero/FlatAero/Models/ImportedData.swift index 4594626..7b7709d 100644 --- a/FlatAero/FlatAero/Models/ImportedData.swift +++ b/FlatAero/FlatAero/Models/ImportedData.swift @@ -8,11 +8,25 @@ import Foundation -struct ImportedData { +protocol FBSData { + var table: String? { get } + var validate: Bool { get } +} + +struct ImportedArrayData: FBSData { var buffer: [UInt8]? var table: String? - + + var validate: Bool { + table != nil && buffer != nil + } +} + +struct ImportedNSData: FBSData { + var buffer: Data? + var table: String? + var validate: Bool { - return table != nil && buffer != nil + table != nil && buffer != nil } } diff --git a/FlatAero/FlatAero/Models/PlaceHolder.swift b/FlatAero/FlatAero/Models/PlaceHolder.swift index 317f99d..e17d6a1 100644 --- a/FlatAero/FlatAero/Models/PlaceHolder.swift +++ b/FlatAero/FlatAero/Models/PlaceHolder.swift @@ -10,7 +10,7 @@ import Foundation struct PlaceHolder { static let fbsTable = - """ + """ union Favorite { Music, Movie } table Music { @@ -30,9 +30,9 @@ struct PlaceHolder { } root_type User; """ - + static let exampleArray = - """ + """ Enter an Array without brackets separating each Uint by a comma """ } diff --git a/FlatAero/FlatAero/Models/Schema.swift b/FlatAero/FlatAero/Models/Schema.swift index 164bbaf..991bcdd 100644 --- a/FlatAero/FlatAero/Models/Schema.swift +++ b/FlatAero/FlatAero/Models/Schema.swift @@ -10,11 +10,11 @@ import Foundation struct Schema { var input: String - + var hasRoot: Bool { - return input.contains("root_type") + input.contains("root_type") } - + func doesntInclude() throws { for line in input.components(separatedBy: "\n") { let component = line.components(separatedBy: " ") diff --git a/FlatAero/FlatAero/Models/TypesOfDisplayers.swift b/FlatAero/FlatAero/Models/TypesOfDisplayers.swift index 76f1c73..0716e28 100644 --- a/FlatAero/FlatAero/Models/TypesOfDisplayers.swift +++ b/FlatAero/FlatAero/Models/TypesOfDisplayers.swift @@ -10,6 +10,6 @@ import Foundation enum TypesOfDisplayers: Int { case file, array - + static let types = ["Import File", "UInt 8 Array"] } diff --git a/FlatAero/FlatAero/Operations/BaseOperations/AsyncOperation.swift b/FlatAero/FlatAero/Operations/BaseOperations/AsyncOperation.swift index f81a9fa..52e3ec2 100644 --- a/FlatAero/FlatAero/Operations/BaseOperations/AsyncOperation.swift +++ b/FlatAero/FlatAero/Operations/BaseOperations/AsyncOperation.swift @@ -9,34 +9,34 @@ import Foundation class AsyncOperation: BaseOperation where Failure: Error { - + typealias OperationResult = Result - + private(set) var result: OperationResult? { didSet { guard let result = result else { return } onResult?(result) } } - + var onResult: ((OperationResult) -> Void)? - + override init() { super.init() isAsynchronous = true } - + override func start() { guard !isCancelled else { return } executing(true) main() } - + func finish(with operationResult: OperationResult) { result = operationResult executing(false) } - + func cancel(with err: Failure) { result = .failure(err) executing(false) diff --git a/FlatAero/FlatAero/Operations/BaseOperations/BaseOperation.swift b/FlatAero/FlatAero/Operations/BaseOperations/BaseOperation.swift index dd2cd2c..6d71d2a 100644 --- a/FlatAero/FlatAero/Operations/BaseOperations/BaseOperation.swift +++ b/FlatAero/FlatAero/Operations/BaseOperations/BaseOperation.swift @@ -11,16 +11,16 @@ import Foundation infix operator >>> public class BaseOperation: Operation { - + fileprivate var lockQueue = DispatchQueue(label: "space.mmk.lock") fileprivate var _isExecuting = false fileprivate var _isFinished = false fileprivate var _isAsynchronous = false fileprivate var _isCancelled = false - + public override var isExecuting: Bool { get { - return lockQueue.sync { _isExecuting } + lockQueue.sync { _isExecuting } } set { willChangeValue(forKey: "isExecuting") @@ -30,10 +30,10 @@ public class BaseOperation: Operation { didChangeValue(forKey: "isExecuting") } } - + public override var isFinished: Bool { get { - return lockQueue.sync { _isFinished } + lockQueue.sync { _isFinished } } set { willChangeValue(forKey: "isFinished") @@ -45,7 +45,7 @@ public class BaseOperation: Operation { } public override var isAsynchronous: Bool { get { - return lockQueue.sync { _isAsynchronous } + lockQueue.sync { _isAsynchronous } } set { willChangeValue(forKey: "isAsynchronous") @@ -55,10 +55,10 @@ public class BaseOperation: Operation { didChangeValue(forKey: "isAsynchronous") } } - + public override var isCancelled: Bool { get { - return lockQueue.sync { _isCancelled } + lockQueue.sync { _isCancelled } } set { willChangeValue(forKey: "isCancelled") @@ -68,15 +68,15 @@ public class BaseOperation: Operation { didChangeValue(forKey: "isCancelled") } } - + public func executing(_ isExecuting: Bool) { self.isExecuting = isExecuting - self.isFinished = !isExecuting + isFinished = !isExecuting } } extension OperationQueue { - + public func cancelAllOperationsWithDependencies() { for operation in operations.reversed() { operation.cancel() @@ -85,7 +85,7 @@ extension OperationQueue { } extension Operation { - + /// Adds a dependency for the operation, the lhs would be a dependency to rhs /// - Parameters: /// - lhs: Operation diff --git a/FlatAero/FlatAero/Operations/BaseOperations/ChainedAsyncOperation.swift b/FlatAero/FlatAero/Operations/BaseOperations/ChainedAsyncOperation.swift index c9c236f..665f772 100644 --- a/FlatAero/FlatAero/Operations/BaseOperations/ChainedAsyncOperation.swift +++ b/FlatAero/FlatAero/Operations/BaseOperations/ChainedAsyncOperation.swift @@ -9,48 +9,51 @@ import Foundation protocol ChainedAsyncOperationOutput { - var output: Any? { get } - var error: Error? { get } + var output: Any? { get } + var error: Error? { get } } extension AsyncOperation: ChainedAsyncOperationOutput { - - var output: Any? { try? result?.get() } - var error: Error? { - switch result { - case .failure(let r): - return r - - default: - return nil - } + + var output: Any? { try? result?.get() } + var error: Error? { + switch result { + case .failure(let r): + return r + + default: + return nil } + } } -class ChainedAsyncOperation: AsyncOperation where Failure: Error { - var input: Input? - - init(input: Input? = nil) { - self.input = input - super.init() - } - - override func start() { - findDependencies() - guard !isCancelled else { return } - super.start() - } - - func findDependencies() { - guard input == nil && !dependencies.isEmpty else { return } - let _result = dependencies.compactMap { (operation) -> ChainedAsyncOperationOutput? in - return operation as? ChainedAsyncOperationOutput - }.first - input = _result?.output as? Input - - guard input == nil else { return } - guard let err = _result?.error as? Failure else { return } - finish(with: .failure(err)) - isCancelled = true - } +class ChainedAsyncOperation: AsyncOperation< + Success, + Failure +> where Failure: Error { + var input: Input? + + init(input: Input? = nil) { + self.input = input + super.init() + } + + override func start() { + findDependencies() + guard !isCancelled else { return } + super.start() + } + + func findDependencies() { + guard input == nil && !dependencies.isEmpty else { return } + let _result = dependencies.compactMap { (operation) -> ChainedAsyncOperationOutput? in + operation as? ChainedAsyncOperationOutput + }.first + input = _result?.output as? Input + + guard input == nil else { return } + guard let err = _result?.error as? Failure else { return } + finish(with: .failure(err)) + isCancelled = true + } } diff --git a/FlatAero/FlatAero/Operations/ConvertOperation.swift b/FlatAero/FlatAero/Operations/ConvertOperation.swift new file mode 100644 index 0000000..ac66478 --- /dev/null +++ b/FlatAero/FlatAero/Operations/ConvertOperation.swift @@ -0,0 +1,31 @@ +// +// ConvertOperation.swift +// FlatAero +// +// Created by Mustafa Khalil on 2/4/21. +// Copyright © 2021 Mustafa Khalil. All rights reserved. +// + +import Foundation + +class ConvertOperation: ChainedAsyncOperation< + ImportedNSData, + ImportedArrayData, + Error +> { + + override func main() { + guard let input = input else { + finish(with: .failure(Errors.noInputPassedToDecode)) + return + } + + guard let table = input.table, let buffer = input.buffer else { return } + + finish( + with: .success( + .init(buffer: buffer.map { $0 }, table: table) + ) + ) + } +} diff --git a/FlatAero/FlatAero/Operations/DecodeOperation.swift b/FlatAero/FlatAero/Operations/DecodeOperation.swift index 3da6edd..95cb53b 100644 --- a/FlatAero/FlatAero/Operations/DecodeOperation.swift +++ b/FlatAero/FlatAero/Operations/DecodeOperation.swift @@ -8,15 +8,15 @@ import Foundation -class DecodeOperation: ChainedAsyncOperation { - +class DecodeOperation: ChainedAsyncOperation { + fileprivate var type: Flat.ParseType - + init(decoderType type: Flat.ParseType) { self.type = type super.init() } - + override func main() { guard let input = input else { finish(with: .failure(Errors.noInputPassedToDecode)) diff --git a/FlatAero/FlatAero/Operations/ValidateOperation.swift b/FlatAero/FlatAero/Operations/ValidateOperation.swift index 93299c1..6ac851c 100644 --- a/FlatAero/FlatAero/Operations/ValidateOperation.swift +++ b/FlatAero/FlatAero/Operations/ValidateOperation.swift @@ -8,15 +8,15 @@ import Foundation -class ValidateOperation: AsyncOperation { - - fileprivate var data: ImportedData? - - init(data: ImportedData?) { +class ValidateOperation: AsyncOperation where T: FBSData { + + fileprivate var data: T? + + init(data: T?) { self.data = data super.init() } - + override func main() { guard let data = data else { Logging.logger.warning("Failed to pass data into validate operation") diff --git a/FlatAero/FlatAero/Presenter/DecodeViewPresenter.swift b/FlatAero/FlatAero/Presenter/DecodeViewPresenter.swift index 9fd548a..c8afa96 100644 --- a/FlatAero/FlatAero/Presenter/DecodeViewPresenter.swift +++ b/FlatAero/FlatAero/Presenter/DecodeViewPresenter.swift @@ -9,39 +9,58 @@ import Foundation class DecodeViewPresenter: NSObject, DecodeViewPresenterDelegate { - + var type: Flat.ParseType = .flat - + var operationQueue: OperationQueue = { let op = OperationQueue() op.name = "space.mmk.decode-queue" return op }() - + weak var controller: DecodeViewControllerDelegate? weak var parent: MainViewControllerDecodeDelegate? - - init(controller: DecodeViewControllerDelegate, parent: MainViewControllerDecodeDelegate) { + + init( + controller: DecodeViewControllerDelegate, + parent: MainViewControllerDecodeDelegate) + { self.controller = controller self.parent = parent } - + func decode() { Logging.logger.info("user pressed decode with type: \(type)") - let validateOperation = ValidateOperation(data: parent?.fetchData()) + guard let data = parent?.fetchData() else { return } + let decodeOperation = DecodeOperation(decoderType: type) - + var ops: [Operation] = [decodeOperation] + + switch data.decoding { + case .array: + let validateOperation = ValidateOperation(data: data.data as? ImportedArrayData) + validateOperation >>> decodeOperation + ops.append(validateOperation) + + case .file: + let validateOperation = ValidateOperation(data: data.data as? ImportedNSData) + let converterOperation = ConvertOperation() + validateOperation >>> converterOperation + converterOperation >>> decodeOperation + ops.append(validateOperation) + ops.append(converterOperation) + } + decodeOperation.onResult = { [weak self] result in switch result { case .success(let str): self?.controller?.parsedBuffer(str) - + case .failure(let err): NotificationCenter.default.post(name: .flatAeroError, object: err) - + } } - validateOperation >>> decodeOperation - operationQueue.addOperations([validateOperation, decodeOperation], waitUntilFinished: false) + operationQueue.addOperations(ops, waitUntilFinished: false) } } diff --git a/FlatAero/FlatAero/Presenter/ImportBinaryPresenter.swift b/FlatAero/FlatAero/Presenter/ImportBinaryPresenter.swift index 2809b3f..91ac112 100644 --- a/FlatAero/FlatAero/Presenter/ImportBinaryPresenter.swift +++ b/FlatAero/FlatAero/Presenter/ImportBinaryPresenter.swift @@ -9,20 +9,20 @@ import Foundation class ImportBinaryPresenter: NSObject, ImportBinaryPresenterDelegate { - + var fbsFile: String? var binaryFile: Data? - - var data: ImportedData { - return ImportedData(buffer: binaryFile?.map({ $0 }), table: fbsFile) + + var data: ImportedNSData { + ImportedNSData(buffer: binaryFile, table: fbsFile) } - + weak var controller: ImportBinaryControllerDelegate? - + init(controller: ImportBinaryControllerDelegate) { self.controller = controller } - + func set(_ fbs: String) { fbsFile = fbs controller?.present(fbs: fbs) diff --git a/FlatAero/FlatAero/Presenter/ImportFBSTextPresenter.swift b/FlatAero/FlatAero/Presenter/ImportFBSTextPresenter.swift index 9e1f035..86233d3 100644 --- a/FlatAero/FlatAero/Presenter/ImportFBSTextPresenter.swift +++ b/FlatAero/FlatAero/Presenter/ImportFBSTextPresenter.swift @@ -8,15 +8,18 @@ import Foundation -protocol TextPresenterDelegate: class {} -protocol TextPresenterControllerDelegate: class {} +protocol TextPresenterDelegate: AnyObject {} +protocol TextPresenterControllerDelegate: AnyObject {} class ImportFBSTextPresenter: NSObject, TextPresenterDelegate { - + weak var controller: TextPresenterControllerDelegate? weak var mainPresenter: MainViewPresenterDelegate? - - init(controller: TextPresenterControllerDelegate, mainPresenter: MainViewPresenterDelegate?) { + + init( + controller: TextPresenterControllerDelegate, + mainPresenter: MainViewPresenterDelegate?) + { self.controller = controller self.mainPresenter = mainPresenter } diff --git a/FlatAero/FlatAero/Presenter/ImportPresenter.swift b/FlatAero/FlatAero/Presenter/ImportPresenter.swift index 06f186a..9ca7ffa 100644 --- a/FlatAero/FlatAero/Presenter/ImportPresenter.swift +++ b/FlatAero/FlatAero/Presenter/ImportPresenter.swift @@ -9,21 +9,24 @@ import Foundation class ImportPresenter: NSObject, ImportPresenterDelegate { - + weak var controller: ImportControllerDelegate? weak var parent: MainViewControllerImportsDelegate? - - init(importControllerDelegate: ImportControllerDelegate, parent parentDelegate: MainViewControllerImportsDelegate) { + + init( + importControllerDelegate: ImportControllerDelegate, + parent parentDelegate: MainViewControllerImportsDelegate) + { controller = importControllerDelegate parent = parentDelegate } - + func switchDisplayedControllers(of type: Int) { guard let selection = TypesOfDisplayers(rawValue: type) else { return } controller?.should(displayController: selection == .file) } - - func prepareData() -> ImportedData { + + func fetchData() -> SelectedData { guard let controller = controller else { fatalError("import delegate failed") } return controller.fetchData() } diff --git a/FlatAero/FlatAero/Presenter/ImportUIntArrayPresenter.swift b/FlatAero/FlatAero/Presenter/ImportUIntArrayPresenter.swift index 0b09381..2acb978 100644 --- a/FlatAero/FlatAero/Presenter/ImportUIntArrayPresenter.swift +++ b/FlatAero/FlatAero/Presenter/ImportUIntArrayPresenter.swift @@ -9,20 +9,20 @@ import Foundation class ImportUIntArrayPresenter: NSObject, ImportUIntArrayPresenterDelegate { - + var fbsFile: String? var binaryData: [UInt8] = [] - - var data: ImportedData { - return ImportedData(buffer: binaryData, table: fbsFile) + + var data: ImportedArrayData { + ImportedArrayData(buffer: binaryData, table: fbsFile) } - + weak var controller: ImportUIntControllerDelegate? - + init(controller: ImportUIntControllerDelegate) { self.controller = controller } - + func set(_ fbs: String) { fbsFile = fbs controller?.present(fbs: fbs) diff --git a/FlatAero/FlatAero/Presenter/MainViewPresenter.swift b/FlatAero/FlatAero/Presenter/MainViewPresenter.swift index 40baea7..9a2328d 100644 --- a/FlatAero/FlatAero/Presenter/MainViewPresenter.swift +++ b/FlatAero/FlatAero/Presenter/MainViewPresenter.swift @@ -9,11 +9,14 @@ import Foundation class MainViewPresenter: NSObject, MainViewPresenterDelegate { - + weak var controller: MainViewControllerPresenterDelegate? weak var router: MainViewRouterDelegate? - - init(controller: MainViewControllerPresenterDelegate, router: MainViewRouterDelegate) { + + init( + controller: MainViewControllerPresenterDelegate, + router: MainViewRouterDelegate) + { self.controller = controller self.router = router } diff --git a/FlatAero/FlatAero/Protocols/DecodeProtocols.swift b/FlatAero/FlatAero/Protocols/DecodeProtocols.swift index 0c8a5cb..6221cd3 100644 --- a/FlatAero/FlatAero/Protocols/DecodeProtocols.swift +++ b/FlatAero/FlatAero/Protocols/DecodeProtocols.swift @@ -13,6 +13,7 @@ protocol DecodeViewPresenterDelegate: Presenter { func decode() } -protocol DecodeViewControllerDelegate: class { +protocol DecodeViewControllerDelegate: AnyObject { +// var type func parsedBuffer(_ str: String) } diff --git a/FlatAero/FlatAero/Protocols/ImportFBSFile.swift b/FlatAero/FlatAero/Protocols/ImportFBSFile.swift index ec2df86..d3a4a3c 100644 --- a/FlatAero/FlatAero/Protocols/ImportFBSFile.swift +++ b/FlatAero/FlatAero/Protocols/ImportFBSFile.swift @@ -8,7 +8,8 @@ import Cocoa -@objc protocol BuildImportFileView: class { +@objc +protocol BuildImportFileView: AnyObject { var importTable: NSLabel! { get set } var pathTextField: NSTextField! { get set } var importFBSFileButton: FlatAeroButton! { get set } @@ -16,7 +17,7 @@ import Cocoa } extension BuildImportFileView where Self: NSViewController { - + var importTableConstructor: NSLabel { let lbl = NSLabel() lbl.stringValue = "Import Schema (.fbs)" @@ -24,7 +25,7 @@ extension BuildImportFileView where Self: NSViewController { lbl.heightAnchor.constraint(equalToConstant: 20).isActive = true return lbl } - + var pathTextFieldConstructor: NSTextField { let txtfield = NSTextField() txtfield.placeholderString = "Path" @@ -32,27 +33,35 @@ extension BuildImportFileView where Self: NSViewController { txtfield.isEditable = false return txtfield } - + var importFBSFileButtonConstructor: FlatAeroButton { let btn = FlatAeroButton(type: .fbsFile, title: "Import", target: self) btn.translatesAutoresizingMaskIntoConstraints = false btn.widthAnchor.constraint(equalToConstant: 100).isActive = true return btn } - + func setupFBSImporterView() { importTable = importTableConstructor pathTextField = pathTextFieldConstructor importFBSFileButton = importFBSFileButtonConstructor - - let importerViewStack = NSStackView(views: [pathTextField, importFBSFileButton]) + + let importerViewStack = NSStackView(views: [ + pathTextField, + importFBSFileButton, + ]) importerViewStack.spacing = 10 importerViewStack.distribution = .fillProportionally - + view.addSubview(importTable) view.addSubview(importerViewStack) - - importerViewStack.topAnchor.constraint(equalTo: importTable.bottomAnchor, constant: 10).isActive = true - importerViewStack.anchorInSuperViewDisregarding(edges: .top, .bottom, padding: .init(top: 8, left: 8, bottom: 8, right: 8)) + + importerViewStack.topAnchor.constraint( + equalTo: importTable.bottomAnchor, + constant: 10).isActive = true + importerViewStack.anchorInSuperViewDisregarding( + edges: .top, + .bottom, + padding: .init(top: 8, left: 8, bottom: 8, right: 8)) } } diff --git a/FlatAero/FlatAero/Protocols/ImportFiles.swift b/FlatAero/FlatAero/Protocols/ImportFiles.swift index f5cdfdd..3d63eea 100644 --- a/FlatAero/FlatAero/Protocols/ImportFiles.swift +++ b/FlatAero/FlatAero/Protocols/ImportFiles.swift @@ -15,31 +15,35 @@ protocol ImportFiles { } extension ImportFiles { - - func importFile(in view: NSView, type: ImportableTypes, fileTypes: [String] = ["fbs"]) { + + func importFile( + in view: NSView, + type: ImportableTypes, + fileTypes: [String] = ["fbs"]) + { guard let window = view.window else { return } - + let panel = NSOpenPanel() panel.canChooseFiles = true panel.canChooseDirectories = false panel.allowsMultipleSelection = false panel.allowedFileTypes = fileTypes - - panel.beginSheetModal(for: window) { (result) in + + panel.beginSheetModal(for: window) { result in if result.rawValue == NSApplication.ModalResponse.OK.rawValue { guard !panel.urls.isEmpty else { return } self.selectedFile(panel.urls[0], ofType: type) } } } - + func openFile(from url: URL, type: ImportableTypes) throws { do { let data = try Data(contentsOf: url) switch type { case .binary: set(data: data) - + case .fbsFile: let str = try buildStringFrom(data: data) set(fbs: str) @@ -48,7 +52,7 @@ extension ImportFiles { throw error } } - + func buildStringFrom(data: Data) throws -> String { guard let str = String(data: data, encoding: .utf8) else { throw Errors.couldntOpenFile diff --git a/FlatAero/FlatAero/Protocols/ImportsProtocols.swift b/FlatAero/FlatAero/Protocols/ImportsProtocols.swift index d452241..ea1a52b 100644 --- a/FlatAero/FlatAero/Protocols/ImportsProtocols.swift +++ b/FlatAero/FlatAero/Protocols/ImportsProtocols.swift @@ -8,32 +8,37 @@ import Foundation +struct SelectedData { + var decoding: TypesOfDisplayers + var data: FBSData +} + protocol ImportPresenterDelegate: Presenter { + func fetchData() -> SelectedData func switchDisplayedControllers(of type: Int) - func prepareData() -> ImportedData } -protocol ImportControllerDelegate: class { - func fetchData() -> ImportedData +protocol ImportControllerDelegate: AnyObject { + func fetchData() -> SelectedData func should(displayController isHidden: Bool) } // MARK: - Delegates for containers -protocol ImportUIntControllerDelegate: class, PresentableFbs {} +protocol ImportUIntControllerDelegate: AnyObject, PresentableFbs {} protocol ImportUIntArrayPresenterDelegate: Presenter, SetableFbs { - var data: ImportedData { get } + var data: ImportedArrayData { get } var fbsFile: String? { get set } var binaryData: [UInt8] { get set } } -protocol ImportBinaryControllerDelegate: class, PresentableFbs {} +protocol ImportBinaryControllerDelegate: AnyObject, PresentableFbs {} protocol ImportBinaryPresenterDelegate: Presenter, SetableFbs { + var data: ImportedNSData { get } var fbsFile: String? { get set } var binaryFile: Data? { get set } - var data: ImportedData { get } } protocol PresentableFbs { diff --git a/FlatAero/FlatAero/Protocols/MainViewProtocols.swift b/FlatAero/FlatAero/Protocols/MainViewProtocols.swift index 660bf7f..ebb5c7c 100644 --- a/FlatAero/FlatAero/Protocols/MainViewProtocols.swift +++ b/FlatAero/FlatAero/Protocols/MainViewProtocols.swift @@ -8,14 +8,14 @@ import Foundation -protocol MainViewRouterDelegate: class {} +protocol MainViewRouterDelegate: AnyObject {} -protocol MainViewPresenterDelegate: class {} +protocol MainViewPresenterDelegate: AnyObject {} -protocol MainViewControllerPresenterDelegate: class {} +protocol MainViewControllerPresenterDelegate: AnyObject {} -protocol MainViewControllerImportsDelegate: class {} +protocol MainViewControllerImportsDelegate: AnyObject {} -protocol MainViewControllerDecodeDelegate: class { - func fetchData() -> ImportedData +protocol MainViewControllerDecodeDelegate: AnyObject { + func fetchData() -> SelectedData } diff --git a/FlatAero/FlatAero/Protocols/Router.swift b/FlatAero/FlatAero/Protocols/Router.swift index 33036a9..4b6fd3a 100644 --- a/FlatAero/FlatAero/Protocols/Router.swift +++ b/FlatAero/FlatAero/Protocols/Router.swift @@ -8,7 +8,7 @@ import Foundation -protocol Presenter: class {} +protocol Presenter: AnyObject {} protocol Router { func start() diff --git a/FlatAero/FlatAero/Router/MainViewRouter.swift b/FlatAero/FlatAero/Router/MainViewRouter.swift index dd82521..a99d86b 100644 --- a/FlatAero/FlatAero/Router/MainViewRouter.swift +++ b/FlatAero/FlatAero/Router/MainViewRouter.swift @@ -9,21 +9,21 @@ import Cocoa class MainViewRouter: Router { - + var navigation: NSViewController! - + init() {} - + func start() { let controller = MainViewController() let presenter = MainViewPresenter(controller: controller, router: self) controller.presenter = presenter - + navigation = controller } - + } extension MainViewRouter: MainViewRouterDelegate { - + } diff --git a/FlatAero/FlatAero/Styles/FBSStyling.swift b/FlatAero/FlatAero/Styles/FBSStyling.swift index ad23913..df0ddc7 100644 --- a/FlatAero/FlatAero/Styles/FBSStyling.swift +++ b/FlatAero/FlatAero/Styles/FBSStyling.swift @@ -9,5 +9,5 @@ import Cocoa struct FBSStyling: Styling { - + } diff --git a/FlatAero/FlatAero/Styles/Styling.swift b/FlatAero/FlatAero/Styles/Styling.swift index 2e19e84..be5e0d4 100644 --- a/FlatAero/FlatAero/Styles/Styling.swift +++ b/FlatAero/FlatAero/Styles/Styling.swift @@ -9,23 +9,30 @@ import Cocoa protocol Styling { - + } extension Styling { - + func style(text: String, for textView: NSTextView) { - + } - - func apply(pattern: String, - in text: String, - options: NSRegularExpression.Options = [], - color: NSColor?, - textView: NSTextView) { - - guard let regex = try? NSRegularExpression(pattern: pattern, options: options) else { return } - let matches = regex.matches(in: text, options: [], range: NSRange(text.startIndex..., in: text)) + + func apply( + pattern: String, + in text: String, + options: NSRegularExpression.Options = [], + color: NSColor?, + textView: NSTextView) + { + + guard let regex = try? NSRegularExpression( + pattern: pattern, + options: options) else { return } + let matches = regex.matches( + in: text, + options: [], + range: NSRange(text.startIndex..., in: text)) for match in matches { textView.setTextColor(color, range: match.range) } diff --git a/FlatAero/FlatAero/UI/FlatAeroButton.swift b/FlatAero/FlatAero/UI/FlatAeroButton.swift index eec8476..4996672 100644 --- a/FlatAero/FlatAero/UI/FlatAeroButton.swift +++ b/FlatAero/FlatAero/UI/FlatAeroButton.swift @@ -9,9 +9,9 @@ import Cocoa class FlatAeroButton: NSButton { - + var type: ImportableTypes - + init(type: ImportableTypes, title: String, target: Any) { self.type = type super.init(frame: .zero) @@ -19,7 +19,7 @@ class FlatAeroButton: NSButton { self.title = title self.target = target as AnyObject } - + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } diff --git a/FlatAero/FlatAero/UI/NSLabel.swift b/FlatAero/FlatAero/UI/NSLabel.swift index 9313e8d..fafd71b 100644 --- a/FlatAero/FlatAero/UI/NSLabel.swift +++ b/FlatAero/FlatAero/UI/NSLabel.swift @@ -17,7 +17,7 @@ open class NSLabel: NSTextField { isSelectable = false alignment = .left } - + required public init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } diff --git a/FlatAero/FlatAero/main.swift b/FlatAero/FlatAero/main.swift index e36cdb4..5b742d5 100644 --- a/FlatAero/FlatAero/main.swift +++ b/FlatAero/FlatAero/main.swift @@ -12,7 +12,10 @@ func addMenu() { let myApp: NSApplication = NSApplication.shared let mainBundle: Bundle = Bundle.main let mainNibFileBaseName: String = mainBundle.infoDictionary!["NSMainNibFile"] as! String - mainBundle.loadNibNamed(mainNibFileBaseName, owner: myApp, topLevelObjects: nil) + mainBundle.loadNibNamed( + mainNibFileBaseName, + owner: myApp, + topLevelObjects: nil) } Logging.__init() diff --git a/FlatAero/FlatAeroTests/FlatAeroTests.swift b/FlatAero/FlatAeroTests/FlatAeroTests.swift index 67e9728..e224a9f 100644 --- a/FlatAero/FlatAeroTests/FlatAeroTests.swift +++ b/FlatAero/FlatAeroTests/FlatAeroTests.swift @@ -10,25 +10,25 @@ import XCTest @testable import FlatAero class FlatAeroTests: XCTestCase { - + override func setUp() { // Put setup code here. This method is called before the invocation of each test method in the class. } - + override func tearDown() { // Put teardown code here. This method is called after the invocation of each test method in the class. } - + func testExample() { // This is an example of a functional test case. // Use XCTAssert and related functions to verify your tests produce the correct results. } - + func testPerformanceExample() { // This is an example of a performance test case. - self.measure { + measure { // Put the code you want to measure the time of here. } } - + } diff --git a/FlatAero/FlatAeroTests/FlatTests.swift b/FlatAero/FlatAeroTests/FlatTests.swift index a1350ae..54741d5 100644 --- a/FlatAero/FlatAeroTests/FlatTests.swift +++ b/FlatAero/FlatAeroTests/FlatTests.swift @@ -11,38 +11,139 @@ import XCTest class FlatTests: XCTestCase { let schema = """ - union Favorite { Music, Movie } - - table Music { - name: string; - } - - table Movie { - name: string; - } - - table User { - name: string; - age: uint; - email: string; - loggedIn: bool; - starred: Favorite; - } - - root_type User; - """ - var array: [UInt8] = [20, 0, 0, 0, 16, 0, 24, 0, 8, 0, 12, 0, 16, 0, 0, 0, 7, 0, 20, 0, 16, 0, 0, 0, 0, 0, 0, 1, 36, 0, 0, 0, 25, 0, 0, 0, 8, 0, 0, 0, 36, 0, 0, 0, 14, 0, 0, 0, 109, 117, 115, 116, 105, 105, 64, 109, 109, 107, 46, 111, 110, 101, 0, 0, 1, 0, 0, 0, 77, 0, 6, 0, 8, 0, 4, 0, 6, 0, 0, 0, 4, 0, 0, 0, 10, 0, 0, 0, 80, 105, 110, 107, 32, 70, 108, 111, 121, 100, 0, 0] + union Favorite { Music, Movie } + + table Music { + name: string; + } + + table Movie { + name: string; + } + + table User { + name: string; + age: uint; + email: string; + loggedIn: bool; + starred: Favorite; + } + + root_type User; + """ + var array: [UInt8] = [ + 20, + 0, + 0, + 0, + 16, + 0, + 24, + 0, + 8, + 0, + 12, + 0, + 16, + 0, + 0, + 0, + 7, + 0, + 20, + 0, + 16, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 36, + 0, + 0, + 0, + 25, + 0, + 0, + 0, + 8, + 0, + 0, + 0, + 36, + 0, + 0, + 0, + 14, + 0, + 0, + 0, + 109, + 117, + 115, + 116, + 105, + 105, + 64, + 109, + 109, + 107, + 46, + 111, + 110, + 101, + 0, + 0, + 1, + 0, + 0, + 0, + 77, + 0, + 6, + 0, + 8, + 0, + 4, + 0, + 6, + 0, + 0, + 0, + 4, + 0, + 0, + 0, + 10, + 0, + 0, + 0, + 80, + 105, + 110, + 107, + 32, + 70, + 108, + 111, + 121, + 100, + 0, + 0, + ] var flat: Flat! - + override func setUp() { // Put setup code here. This method is called before the invocation of each test method in the class. flat = Flat(schema: Schema(input: schema)) } - + override func tearDown() { // Put teardown code here. This method is called after the invocation of each test method in the class. } - + func testValidArray() { do { let c = try flat.parser(&array, type: .flat) diff --git a/FlatAero/FlatAeroUITests/FlatAeroUITests.swift b/FlatAero/FlatAeroUITests/FlatAeroUITests.swift index 8e78c1d..2915a92 100644 --- a/FlatAero/FlatAeroUITests/FlatAeroUITests.swift +++ b/FlatAero/FlatAeroUITests/FlatAeroUITests.swift @@ -10,34 +10,34 @@ import XCTest class FlatAeroUITests: XCTestCase { - override func setUp() { - // Put setup code here. This method is called before the invocation of each test method in the class. - - // In UI tests it is usually best to stop immediately when a failure occurs. - continueAfterFailure = false - - // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - } - - func testExample() { - // UI tests must launch the application that they test. - let app = XCUIApplication() - app.launch() - - // Use recording to get started writing UI tests. - // Use XCTAssert and related functions to verify your tests produce the correct results. - } - - func testLaunchPerformance() { - if #available(macOS 10.15, iOS 13.0, tvOS 13.0, *) { - // This measures how long it takes to launch your application. - measure(metrics: [XCTOSSignpostMetric.applicationLaunch]) { - XCUIApplication().launch() - } - } + override func setUp() { + // Put setup code here. This method is called before the invocation of each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false + + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + func testExample() { + // UI tests must launch the application that they test. + let app = XCUIApplication() + app.launch() + + // Use recording to get started writing UI tests. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + func testLaunchPerformance() { + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, *) { + // This measures how long it takes to launch your application. + measure(metrics: [XCTOSSignpostMetric.applicationLaunch]) { + XCUIApplication().launch() + } } + } } diff --git a/electron/index.js b/electron/index.js deleted file mode 100644 index 91b832d..0000000 --- a/electron/index.js +++ /dev/null @@ -1,43 +0,0 @@ -const { app, BrowserWindow } = require('electron') - -function createWindow () { - // Create the browser window. - const win = new BrowserWindow({ - width: 800, - height: 600, - webPreferences: { - nodeIntegration: true - } - }) - - // and load the index.html of the app. - win.loadFile('views/index.html') - - // Open the DevTools. - win.webContents.openDevTools() -} - -// This method will be called when Electron has finished -// initialization and is ready to create browser windows. -// Some APIs can only be used after this event occurs. -app.whenReady().then(createWindow) - -// Quit when all windows are closed, except on macOS. There, it's common -// for applications and their menu bar to stay active until the user quits -// explicitly with Cmd + Q. -app.on('window-all-closed', () => { - if (process.platform !== 'darwin') { - app.quit() - } -}) - -app.on('activate', () => { - // On macOS it's common to re-create a window in the app when the - // dock icon is clicked and there are no other windows open. - if (BrowserWindow.getAllWindows().length === 0) { - createWindow() - } -}) - -// In this file you can include the rest of your app's specific main process -// code. You can also put them in separate files and require them here. \ No newline at end of file diff --git a/electron/package-lock.json b/electron/package-lock.json deleted file mode 100644 index 11ab9ae..0000000 --- a/electron/package-lock.json +++ /dev/null @@ -1,732 +0,0 @@ -{ - "name": "flataero", - "version": "1.0.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "@electron/get": { - "version": "1.12.2", - "resolved": "https://registry.npmjs.org/@electron/get/-/get-1.12.2.tgz", - "integrity": "sha512-vAuHUbfvBQpYTJ5wB7uVIDq5c/Ry0fiTBMs7lnEYAo/qXXppIVcWdfBr57u6eRnKdVso7KSiH6p/LbQAG6Izrg==", - "dev": true, - "requires": { - "debug": "^4.1.1", - "env-paths": "^2.2.0", - "fs-extra": "^8.1.0", - "global-agent": "^2.0.2", - "global-tunnel-ng": "^2.7.1", - "got": "^9.6.0", - "progress": "^2.0.3", - "sanitize-filename": "^1.6.2", - "sumchecker": "^3.0.1" - } - }, - "@sindresorhus/is": { - "version": "0.14.0", - "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", - "integrity": "sha512-9NET910DNaIPngYnLLPeg+Ogzqsi9uM4mSboU5y6p8S5DzMTVEsJZrawi+BoDNUVBa2DhJqQYUFvMDfgU062LQ==", - "dev": true - }, - "@szmarczak/http-timer": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-1.1.2.tgz", - "integrity": "sha512-XIB2XbzHTN6ieIjfIMV9hlVcfPU26s2vafYWQcZHWXHOxiaRZYEDKEwdl129Zyg50+foYV2jCgtrqSA6qNuNSA==", - "dev": true, - "requires": { - "defer-to-connect": "^1.0.1" - } - }, - "@types/node": { - "version": "12.12.54", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.54.tgz", - "integrity": "sha512-ge4xZ3vSBornVYlDnk7yZ0gK6ChHf/CHB7Gl1I0Jhah8DDnEQqBzgohYG4FX4p81TNirSETOiSyn+y1r9/IR6w==", - "dev": true - }, - "boolean": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/boolean/-/boolean-3.0.1.tgz", - "integrity": "sha512-HRZPIjPcbwAVQvOTxR4YE3o8Xs98NqbbL1iEZDCz7CL8ql0Lt5iOyJFxfnAB0oFs8Oh02F/lLlg30Mexv46LjA==", - "dev": true, - "optional": true - }, - "buffer-crc32": { - "version": "0.2.13", - "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", - "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=", - "dev": true - }, - "buffer-from": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", - "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", - "dev": true - }, - "cacheable-request": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-6.1.0.tgz", - "integrity": "sha512-Oj3cAGPCqOZX7Rz64Uny2GYAZNliQSqfbePrgAQ1wKAihYmCUnraBtJtKcGR4xz7wF+LoJC+ssFZvv5BgF9Igg==", - "dev": true, - "requires": { - "clone-response": "^1.0.2", - "get-stream": "^5.1.0", - "http-cache-semantics": "^4.0.0", - "keyv": "^3.0.0", - "lowercase-keys": "^2.0.0", - "normalize-url": "^4.1.0", - "responselike": "^1.0.2" - }, - "dependencies": { - "get-stream": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.1.0.tgz", - "integrity": "sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw==", - "dev": true, - "requires": { - "pump": "^3.0.0" - } - }, - "lowercase-keys": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", - "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==", - "dev": true - } - } - }, - "clone-response": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz", - "integrity": "sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws=", - "dev": true, - "requires": { - "mimic-response": "^1.0.0" - } - }, - "concat-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", - "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", - "dev": true, - "requires": { - "buffer-from": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^2.2.2", - "typedarray": "^0.0.6" - } - }, - "config-chain": { - "version": "1.1.12", - "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.12.tgz", - "integrity": "sha512-a1eOIcu8+7lUInge4Rpf/n4Krkf3Dd9lqhljRzII1/Zno/kRtUWnznPO3jOKBmTEktkt3fkxisUcivoj0ebzoA==", - "dev": true, - "optional": true, - "requires": { - "ini": "^1.3.4", - "proto-list": "~1.2.1" - } - }, - "core-js": { - "version": "3.6.5", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.6.5.tgz", - "integrity": "sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA==", - "dev": true, - "optional": true - }, - "core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true - }, - "debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "dev": true, - "requires": { - "ms": "^2.1.1" - } - }, - "decompress-response": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-3.3.0.tgz", - "integrity": "sha1-gKTdMjdIOEv6JICDYirt7Jgq3/M=", - "dev": true, - "requires": { - "mimic-response": "^1.0.0" - } - }, - "defer-to-connect": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-1.1.3.tgz", - "integrity": "sha512-0ISdNousHvZT2EiFlZeZAHBUvSxmKswVCEf8hW7KWgG4a8MVEu/3Vb6uWYozkjylyCxe0JBIiRB1jV45S70WVQ==", - "dev": true - }, - "define-properties": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", - "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", - "dev": true, - "optional": true, - "requires": { - "object-keys": "^1.0.12" - } - }, - "detect-node": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/detect-node/-/detect-node-2.0.4.tgz", - "integrity": "sha512-ZIzRpLJrOj7jjP2miAtgqIfmzbxa4ZOr5jJc601zklsfEx9oTzmmj2nVpIPRpNlRTIh8lc1kyViIY7BWSGNmKw==", - "dev": true, - "optional": true - }, - "duplexer3": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz", - "integrity": "sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=", - "dev": true - }, - "electron": { - "version": "9.1.2", - "resolved": "https://registry.npmjs.org/electron/-/electron-9.1.2.tgz", - "integrity": "sha512-xEYadr3XqIqJ4ktBPo0lhzPdovv4jLCpiUUGc2M1frUhFhwqXokwhPaTUcE+zfu5+uf/ONDnQApwjzznBsRrgQ==", - "dev": true, - "requires": { - "@electron/get": "^1.0.1", - "@types/node": "^12.0.12", - "extract-zip": "^1.0.3" - } - }, - "encodeurl": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", - "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=", - "dev": true, - "optional": true - }, - "end-of-stream": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", - "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", - "dev": true, - "requires": { - "once": "^1.4.0" - } - }, - "env-paths": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.0.tgz", - "integrity": "sha512-6u0VYSCo/OW6IoD5WCLLy9JUGARbamfSavcNXry/eu8aHVFei6CD3Sw+VGX5alea1i9pgPHW0mbu6Xj0uBh7gA==", - "dev": true - }, - "es6-error": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", - "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", - "dev": true, - "optional": true - }, - "escape-string-regexp": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", - "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", - "dev": true, - "optional": true - }, - "extract-zip": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.7.0.tgz", - "integrity": "sha512-xoh5G1W/PB0/27lXgMQyIhP5DSY/LhoCsOyZgb+6iMmRtCwVBo55uKaMoEYrDCKQhWvqEip5ZPKAc6eFNyf/MA==", - "dev": true, - "requires": { - "concat-stream": "^1.6.2", - "debug": "^2.6.9", - "mkdirp": "^0.5.4", - "yauzl": "^2.10.0" - }, - "dependencies": { - "debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "requires": { - "ms": "2.0.0" - } - }, - "ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true - } - } - }, - "fd-slicer": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", - "integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=", - "dev": true, - "requires": { - "pend": "~1.2.0" - } - }, - "fs-extra": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", - "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", - "dev": true, - "requires": { - "graceful-fs": "^4.2.0", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" - } - }, - "get-stream": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", - "integrity": "sha512-GMat4EJ5161kIy2HevLlr4luNjBgvmj413KaQA7jt4V8B4RDsfpHk7WQ9GVqfYyyx8OS/L66Kox+rJRNklLK7w==", - "dev": true, - "requires": { - "pump": "^3.0.0" - } - }, - "global-agent": { - "version": "2.1.12", - "resolved": "https://registry.npmjs.org/global-agent/-/global-agent-2.1.12.tgz", - "integrity": "sha512-caAljRMS/qcDo69X9BfkgrihGUgGx44Fb4QQToNQjsiWh+YlQ66uqYVAdA8Olqit+5Ng0nkz09je3ZzANMZcjg==", - "dev": true, - "optional": true, - "requires": { - "boolean": "^3.0.1", - "core-js": "^3.6.5", - "es6-error": "^4.1.1", - "matcher": "^3.0.0", - "roarr": "^2.15.3", - "semver": "^7.3.2", - "serialize-error": "^7.0.1" - } - }, - "global-tunnel-ng": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/global-tunnel-ng/-/global-tunnel-ng-2.7.1.tgz", - "integrity": "sha512-4s+DyciWBV0eK148wqXxcmVAbFVPqtc3sEtUE/GTQfuU80rySLcMhUmHKSHI7/LDj8q0gDYI1lIhRRB7ieRAqg==", - "dev": true, - "optional": true, - "requires": { - "encodeurl": "^1.0.2", - "lodash": "^4.17.10", - "npm-conf": "^1.1.3", - "tunnel": "^0.0.6" - } - }, - "globalthis": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.1.tgz", - "integrity": "sha512-mJPRTc/P39NH/iNG4mXa9aIhNymaQikTrnspeCa2ZuJ+mH2QN/rXwtX3XwKrHqWgUQFbNZKtHM105aHzJalElw==", - "dev": true, - "optional": true, - "requires": { - "define-properties": "^1.1.3" - } - }, - "got": { - "version": "9.6.0", - "resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz", - "integrity": "sha512-R7eWptXuGYxwijs0eV+v3o6+XH1IqVK8dJOEecQfTmkncw9AV4dcw/Dhxi8MdlqPthxxpZyizMzyg8RTmEsG+Q==", - "dev": true, - "requires": { - "@sindresorhus/is": "^0.14.0", - "@szmarczak/http-timer": "^1.1.2", - "cacheable-request": "^6.0.0", - "decompress-response": "^3.3.0", - "duplexer3": "^0.1.4", - "get-stream": "^4.1.0", - "lowercase-keys": "^1.0.1", - "mimic-response": "^1.0.1", - "p-cancelable": "^1.0.0", - "to-readable-stream": "^1.0.0", - "url-parse-lax": "^3.0.0" - } - }, - "graceful-fs": { - "version": "4.2.4", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz", - "integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw==", - "dev": true - }, - "http-cache-semantics": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", - "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==", - "dev": true - }, - "inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true - }, - "ini": { - "version": "1.3.5", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", - "dev": true, - "optional": true - }, - "isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true - }, - "json-buffer": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.0.tgz", - "integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=", - "dev": true - }, - "json-stringify-safe": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", - "dev": true, - "optional": true - }, - "jsonfile": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", - "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", - "dev": true, - "requires": { - "graceful-fs": "^4.1.6" - } - }, - "keyv": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/keyv/-/keyv-3.1.0.tgz", - "integrity": "sha512-9ykJ/46SN/9KPM/sichzQ7OvXyGDYKGTaDlKMGCAlg2UK8KRy4jb0d8sFc+0Tt0YYnThq8X2RZgCg74RPxgcVA==", - "dev": true, - "requires": { - "json-buffer": "3.0.0" - } - }, - "lodash": { - "version": "4.17.19", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", - "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==", - "dev": true, - "optional": true - }, - "lowercase-keys": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.1.tgz", - "integrity": "sha512-G2Lj61tXDnVFFOi8VZds+SoQjtQC3dgokKdDG2mTm1tx4m50NUHBOZSBwQQHyy0V12A0JTG4icfZQH+xPyh8VA==", - "dev": true - }, - "matcher": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/matcher/-/matcher-3.0.0.tgz", - "integrity": "sha512-OkeDaAZ/bQCxeFAozM55PKcKU0yJMPGifLwV4Qgjitu+5MoAfSQN4lsLJeXZ1b8w0x+/Emda6MZgXS1jvsapng==", - "dev": true, - "optional": true, - "requires": { - "escape-string-regexp": "^4.0.0" - } - }, - "mimic-response": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", - "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==", - "dev": true - }, - "minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, - "mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", - "dev": true, - "requires": { - "minimist": "^1.2.5" - } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - }, - "normalize-url": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz", - "integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ==", - "dev": true - }, - "npm-conf": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/npm-conf/-/npm-conf-1.1.3.tgz", - "integrity": "sha512-Yic4bZHJOt9RCFbRP3GgpqhScOY4HH3V2P8yBj6CeYq118Qr+BLXqT2JvpJ00mryLESpgOxf5XlFv4ZjXxLScw==", - "dev": true, - "optional": true, - "requires": { - "config-chain": "^1.1.11", - "pify": "^3.0.0" - } - }, - "object-keys": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", - "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", - "dev": true, - "optional": true - }, - "once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, - "requires": { - "wrappy": "1" - } - }, - "p-cancelable": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-1.1.0.tgz", - "integrity": "sha512-s73XxOZ4zpt1edZYZzvhqFa6uvQc1vwUa0K0BdtIZgQMAJj9IbebH+JkgKZc9h+B05PKHLOTl4ajG1BmNrVZlw==", - "dev": true - }, - "pend": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", - "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=", - "dev": true - }, - "pify": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz", - "integrity": "sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY=", - "dev": true, - "optional": true - }, - "prepend-http": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/prepend-http/-/prepend-http-2.0.0.tgz", - "integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=", - "dev": true - }, - "process-nextick-args": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", - "dev": true - }, - "progress": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", - "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", - "dev": true - }, - "proto-list": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz", - "integrity": "sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk=", - "dev": true, - "optional": true - }, - "pump": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz", - "integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==", - "dev": true, - "requires": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, - "readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "responselike": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/responselike/-/responselike-1.0.2.tgz", - "integrity": "sha1-kYcg7ztjHFZCvgaPFa3lpG9Loec=", - "dev": true, - "requires": { - "lowercase-keys": "^1.0.0" - } - }, - "roarr": { - "version": "2.15.3", - "resolved": "https://registry.npmjs.org/roarr/-/roarr-2.15.3.tgz", - "integrity": "sha512-AEjYvmAhlyxOeB9OqPUzQCo3kuAkNfuDk/HqWbZdFsqDFpapkTjiw+p4svNEoRLvuqNTxqfL+s+gtD4eDgZ+CA==", - "dev": true, - "optional": true, - "requires": { - "boolean": "^3.0.0", - "detect-node": "^2.0.4", - "globalthis": "^1.0.1", - "json-stringify-safe": "^5.0.1", - "semver-compare": "^1.0.0", - "sprintf-js": "^1.1.2" - } - }, - "safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true - }, - "sanitize-filename": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/sanitize-filename/-/sanitize-filename-1.6.3.tgz", - "integrity": "sha512-y/52Mcy7aw3gRm7IrcGDFx/bCk4AhRh2eI9luHOQM86nZsqwiRkkq2GekHXBBD+SmPidc8i2PqtYZl+pWJ8Oeg==", - "dev": true, - "requires": { - "truncate-utf8-bytes": "^1.0.0" - } - }, - "semver": { - "version": "7.3.2", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", - "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", - "dev": true, - "optional": true - }, - "semver-compare": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/semver-compare/-/semver-compare-1.0.0.tgz", - "integrity": "sha1-De4hahyUGrN+nvsXiPavxf9VN/w=", - "dev": true, - "optional": true - }, - "serialize-error": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-7.0.1.tgz", - "integrity": "sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw==", - "dev": true, - "optional": true, - "requires": { - "type-fest": "^0.13.1" - } - }, - "sprintf-js": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.2.tgz", - "integrity": "sha512-VE0SOVEHCk7Qc8ulkWw3ntAzXuqf7S2lvwQaDLRnUeIEaKNQJzV6BwmLKhOqT61aGhfUMrXeaBk+oDGCzvhcug==", - "dev": true, - "optional": true - }, - "string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, - "requires": { - "safe-buffer": "~5.1.0" - } - }, - "sumchecker": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-3.0.1.tgz", - "integrity": "sha512-MvjXzkz/BOfyVDkG0oFOtBxHX2u3gKbMHIF/dXblZsgD3BWOFLmHovIpZY7BykJdAjcqRCBi1WYBNdEC9yI7vg==", - "dev": true, - "requires": { - "debug": "^4.1.0" - } - }, - "to-readable-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-1.0.0.tgz", - "integrity": "sha512-Iq25XBt6zD5npPhlLVXGFN3/gyR2/qODcKNNyTMd4vbm39HUaOiAM4PMq0eMVC/Tkxz+Zjdsc55g9yyz+Yq00Q==", - "dev": true - }, - "truncate-utf8-bytes": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", - "integrity": "sha1-QFkjkJWS1W94pYGENLC3hInKXys=", - "dev": true, - "requires": { - "utf8-byte-length": "^1.0.1" - } - }, - "tunnel": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", - "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", - "dev": true, - "optional": true - }, - "type-fest": { - "version": "0.13.1", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.13.1.tgz", - "integrity": "sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg==", - "dev": true, - "optional": true - }, - "typedarray": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", - "dev": true - }, - "universalify": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", - "dev": true - }, - "url-parse-lax": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-3.0.0.tgz", - "integrity": "sha1-FrXK/Afb42dsGxmZF3gj1lA6yww=", - "dev": true, - "requires": { - "prepend-http": "^2.0.0" - } - }, - "utf8-byte-length": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", - "integrity": "sha1-9F8VDExm7uloGGUFq5P8u4rWv2E=", - "dev": true - }, - "util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true - }, - "wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true - }, - "yauzl": { - "version": "2.10.0", - "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", - "integrity": "sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=", - "dev": true, - "requires": { - "buffer-crc32": "~0.2.3", - "fd-slicer": "~1.1.0" - } - } - } -} diff --git a/electron/package.json b/electron/package.json deleted file mode 100644 index 7b3d951..0000000 --- a/electron/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "flataero", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "start": "electron .", - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "", - "license": "ISC", - "devDependencies": { - "electron": "^9.1.2" - } -} diff --git a/electron/views/index.html b/electron/views/index.html deleted file mode 100644 index 43bc44c..0000000 --- a/electron/views/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - Hello World! - - - - -

Hello World!

- We are using node , - Chrome , - and Electron . - - \ No newline at end of file diff --git a/flat b/flat index 1cc47ba..7f1ed30 160000 --- a/flat +++ b/flat @@ -1 +1 @@ -Subproject commit 1cc47ba2dcb8c33923f1a666c837de73ba39d4f5 +Subproject commit 7f1ed30d9ff70bd43d626c6ebcf81c024fed14e4 diff --git a/swift.swiftformat b/swift.swiftformat new file mode 100644 index 0000000..7de9a64 --- /dev/null +++ b/swift.swiftformat @@ -0,0 +1,25 @@ +--swiftversion 5.1 + +# format +--allman true +--indent 2 +--maxwidth 80 + +# options +--self remove # redundantSelf +--importgrouping testable-bottom # sortedImports +--trimwhitespace always +--indentcase false +--ifdef no-indent #indent +--wraparguments before-first # wrapArguments +--wrapparameters before-first # wrapArguments +--closingparen same-line # wrapArguments +--funcattributes prev-line # wrapAttributes +--typeattributes prev-line # wrapAttributes + +# rules +--rules todos,anyObjectProtocol,redundantParens,redundantReturn,redundantSelf,sortedImports,strongifiedSelf,trailingCommas,trailingSpace,wrapArguments,wrapMultilineStatementBraces,indent,wrapAttributes,void,fileHeader +--disable trailingclosures + +--exclude **/*_generated.swift +--exclude **/*.grpc.swift \ No newline at end of file