Skip to content

Commit

Permalink
Merge pull request #140 from brightdigit/release/3.0.0-beta.1
Browse files Browse the repository at this point in the history
Release/3.0.0 beta.1
  • Loading branch information
leogdion authored Oct 8, 2020
2 parents a0d4825 + 7e31b63 commit b67a0e2
Show file tree
Hide file tree
Showing 20 changed files with 237 additions and 583 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
os: osx
osx_image: xcode11.3
osx_image: xcode12.2
before_install:
- bash -e ./Scripts/before_install.sh
script:
Expand Down
3 changes: 0 additions & 3 deletions Gemfile

This file was deleted.

258 changes: 31 additions & 227 deletions Speculid.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

78 changes: 0 additions & 78 deletions Speculid.xcodeproj/xcshareddata/xcschemes/Speculid.xcscheme

This file was deleted.

10 changes: 5 additions & 5 deletions Speculid/BookmarkURLCollectionObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public class BookmarkURLCollectionObject: ObservableObject, Sandbox {
public func bookmarkURL(fromURL url: URL) throws -> URL {
var isStale: Bool = false
let fromURLResult: Result<URL, Error>
let fromURLCurrentResult = Self.shared.bookmarks?[url.path].map {
data in
Result {
try URL(resolvingBookmarkData: data, options: .withSecurityScope, relativeTo: nil, bookmarkDataIsStale: &isStale)
let fromURLCurrentResult = Self.shared.bookmarks?[url.path]
.map { data in
Result {
try URL(resolvingBookmarkData: data, options: .withSecurityScope, relativeTo: nil, bookmarkDataIsStale: &isStale)
}
}
}
if isStale {
saveBookmark(url)
}
Expand Down
82 changes: 62 additions & 20 deletions Speculid/ClassicDocument.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,89 @@ extension UTType {
}
}

struct ClassicDocument: FileDocument {
var document: SpeculidMutableSpecificationsFile

init(document: SpeculidSpecificationsFile = SpeculidSpecificationsFile()) {
self.document = SpeculidMutableSpecificationsFile(source: document)
class ClassicDocument: FileDocument, SpeculidSpecificationsFileProtocol, ObservableObject {
@Published public var assetDirectoryRelativePath: String
@Published public var sourceImageRelativePath: String
@Published public var geometry: Geometry?
@Published public var background: NSColor?
@Published public var removeAlpha: Bool
@Published public var url: URL?

// var document: SpeculidMutableSpecificationsFile

init(source: SpeculidSpecificationsFile = SpeculidSpecificationsFile()) {
assetDirectoryRelativePath = source.assetDirectoryRelativePath
sourceImageRelativePath = source.sourceImageRelativePath
geometry = source.geometry
background = source.background
removeAlpha = source.removeAlpha
}

static var readableContentTypes: [UTType] { [.speculidImageDocument] }
static var writableContentTypes: [UTType] { [.speculidImageDocument] }

init(fileWrapper: FileWrapper, contentType _: UTType) throws {
required init(configuration: ReadConfiguration) throws {
let decoder = JSONDecoder()
guard let data = fileWrapper.regularFileContents
guard let data = configuration.file.regularFileContents
else {
throw CocoaError(.fileReadCorruptFile)
}
let document = try decoder.decode(SpeculidSpecificationsFile.self, from: data)
self.document = SpeculidMutableSpecificationsFile(source: document)
let source = try decoder.decode(SpeculidSpecificationsFile.self, from: data)

assetDirectoryRelativePath = source.assetDirectoryRelativePath
sourceImageRelativePath = source.sourceImageRelativePath
geometry = source.geometry
background = source.background
removeAlpha = source.removeAlpha
}

func write(to fileWrapper: inout FileWrapper, contentType _: UTType) throws {
let document = SpeculidSpecificationsFile(source: self.document)
// func write(to fileWrapper: inout FileWrapper, contentType _: UTType) throws {
// let document = SpeculidSpecificationsFile(source: self.document)
// let encoder = JSONEncoder()
// let data = try encoder.encode(document)
// fileWrapper = FileWrapper(regularFileWithContents: data)
// }

func fileWrapper(configuration _: WriteConfiguration) throws -> FileWrapper {
debugPrint(assetDirectoryRelativePath)
let document = SpeculidSpecificationsFile(source: self)
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .withoutEscapingSlashes]

let data = try encoder.encode(document)
fileWrapper = FileWrapper(regularFileWithContents: data)
let wrapper = FileWrapper(regularFileWithContents: data)
if let url = self.url {
try wrapper.write(to: url, options: .withNameUpdating, originalContentsURL: nil)
}

return wrapper
}

func build(fromURL url: URL, inSandbox sandbox: Sandbox) {
let document: SpeculidDocument
do {
document = try SpeculidDocument(sandboxedFromFile: self.document, withURL: url, decoder: JSONDecoder(), withManager: sandbox)
document = try SpeculidDocument(sandboxedFromFile: self, withURL: url, decoder: JSONDecoder(), withManager: sandbox)
} catch {
debugPrint(error)
debugPrint(error.localizedDescription)
return
}

let destinationFileNames = document.assetFile.document.images.map {
asset in
(asset, document.destinationName(forImage: asset))
let file = SpeculidSpecificationsFile(source: self)
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .withoutEscapingSlashes]

if let url = self.url, let data = try? encoder.encode(file) {
try? data.write(to: url)
}

// self.fileWrapper(configuration: WriteConfiguration)

let destinationFileNames = document.assetFile.document.images
.map { asset in
(asset, document.destinationName(forImage: asset))
}

let urlMap = destinationFileNames.map { asset, fileName in
(asset, fileName, document.destinationURL(forFileName: fileName))
}
Expand All @@ -58,20 +100,20 @@ struct ClassicDocument: FileDocument {
}

func processImages(fromURL url: URL, management: Sandbox, document: SpeculidDocument, sandboxMap: [(AssetSpecificationProtocol, String, URL)]) {
let assetDirectoryURL = url.deletingLastPathComponent().appendingPathComponent(self.document.assetDirectoryRelativePath)
let assetDirectoryURL = url.deletingLastPathComponent().appendingPathComponent(assetDirectoryRelativePath)

let imageSpecificationBuilder = SpeculidImageSpecificationBuilder()
let imageSpecifications: [ImageSpecification]
let imageSpecifications: [ImageSpecificationObject]
do {
imageSpecifications = try sandboxMap.map { (asset, _, url) -> ImageSpecification in
imageSpecifications = try sandboxMap.map { (asset, _, url) -> ImageSpecificationObject in
try imageSpecificationBuilder.imageSpecification(forURL: url, withSpecifications: document.specificationsFile, andAsset: asset)
}
} catch {
debugPrint(error)
return // callback(error)
}

let service = Service()
let service = ServiceObject()
let sourceURL: URL
do {
sourceURL = try management.bookmarkURL(fromURL: document.sourceImageURL)
Expand Down
26 changes: 15 additions & 11 deletions Speculid/ClassicObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SpeculidKit
import SwiftUI

class ClassicObject: ObservableObject {
let url: URL?
@Published var url: URL?
@Published var geometryValue: Float = 0.0
@Published var assetDirectoryRelativePath: String = ""
@Published var sourceImageRelativePath: String = ""
Expand All @@ -13,7 +13,7 @@ class ClassicObject: ObservableObject {
@Published var resizeOption = ResizeOption.none.rawValue
@Published var addBackground: Bool = false

var document: ClassicDocument
@Published var document: ClassicDocument

var cancellables = [AnyCancellable]()
var assetDirectoryURL: URL? {
Expand All @@ -36,13 +36,13 @@ class ClassicObject: ObservableObject {
self.url = url
self.document = document

assetDirectoryRelativePath = self.document.document.assetDirectoryRelativePath
sourceImageRelativePath = self.document.document.sourceImageRelativePath
addBackground = self.document.document.background != nil
backgroundColor = self.document.document.background.map(Color.init) ?? .clear
geometryValue = self.document.document.geometry?.value ?? 0.0
resizeOption = ResizeOption(geometryType: self.document.document.geometry?.dimension).rawValue
removeAlpha = self.document.document.removeAlpha
assetDirectoryRelativePath = self.document.assetDirectoryRelativePath
sourceImageRelativePath = self.document.sourceImageRelativePath
addBackground = self.document.background != nil
backgroundColor = self.document.background.map(Color.init) ?? .clear
geometryValue = self.document.geometry?.value ?? 0.0
resizeOption = ResizeOption(geometryType: self.document.geometry?.dimension).rawValue
removeAlpha = self.document.removeAlpha

let nscolorPub = $addBackground.combineLatest($backgroundColor) {
$0 ? NSColor($1) : nil
Expand All @@ -64,11 +64,15 @@ class ClassicObject: ObservableObject {
assign($removeAlpha, documentProperty: \.removeAlpha)
assign(nscolorPub, documentProperty: \.background)
assign(geoPub, documentProperty: \.geometry)
assign($url, documentProperty: \.url)
}

func assign<PublisherType: Publisher, ValueType>(_ publisher: PublisherType, documentProperty: WritableKeyPath<SpeculidMutableSpecificationsFile, ValueType>) where PublisherType.Output == ValueType, PublisherType.Failure == Never {
func assign<PublisherType: Publisher, ValueType>(
_ publisher: PublisherType,
documentProperty: WritableKeyPath<ClassicDocument, ValueType>
) where PublisherType.Output == ValueType, PublisherType.Failure == Never {
publisher.sink { value in
self.document.document[keyPath: documentProperty] = value
self.document[keyPath: documentProperty] = value
}.store(in: &cancellables)
}
}
Loading

0 comments on commit b67a0e2

Please sign in to comment.