Skip to content

Commit

Permalink
Merge pull request #32 from NghiaTranUIT/task/artify-31
Browse files Browse the repository at this point in the history
Improve Fetch photo
  • Loading branch information
NghiaTranUIT committed Jun 7, 2018
2 parents b609934 + a4c01da commit e10e564
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ @implementation GaussianEffect
+ (NSImage *)imageByApplyingLightEffectToImage:(NSImage*)inputImage
{
NSColor *tintColor = [NSColor colorWithWhite:1.0 alpha:0.3];
return [self imageByApplyingBlurToImage:inputImage withRadius:60 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil];
return [self imageByApplyingBlurToImage:inputImage withRadius:80 tintColor:tintColor saturationDeltaFactor:1.8 maskImage:nil];
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ extension GaussianAlgorithm {
final.lockFocus()

// Background
let backgroundOrigin = NSPoint.zero
backgroundImage.draw(in: CGRect(origin: backgroundOrigin, size: size))
let backgroundOrigin = CGPoint(x: 0, y: (size.height - backgroundImage.pointSize.height) / 2)
let backgroundRect = CGRect(origin: backgroundOrigin, size: backgroundImage.pointSize)
backgroundImage.draw(in: backgroundRect)

// Prepare
let imageOrigin = NSPoint(x: (size.width - image.pointSize.width) / 2,
Expand Down
7 changes: 7 additions & 0 deletions artify-core/artify-core/Extension/Observable+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@

import Foundation
import RxSwift

extension Observable {

func mapToVoid() -> Observable<Void> {
return self.map { _ in }
}
}
6 changes: 4 additions & 2 deletions artify-core/artify-core/Models/FilePayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ struct FilePayload {
let photo: Photo
let kind: Kind
let prefix: String?

let override: Bool

// MARK: - Public
init(image: NSImage, photo: Photo, kind: Kind = .jpg, prefix: String? = nil) {
init(image: NSImage, photo: Photo, kind: Kind = .jpg, prefix: String? = nil, override: Bool = true) {
self.image = image
self.photo = photo
self.kind = kind
self.prefix = prefix
self.override = override
}

var fileExtension: String {
Expand Down
6 changes: 5 additions & 1 deletion artify-core/artify-core/Services/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ final class FileStorage: FileHandler {

func saveImageIfNeed(_ payload: FilePayload) -> URL {
let path = appFolder.appendingPathComponent(payload.fileName)
guard !isPhotoFileExist(payload.fileName) else {

// Override file if need
if !payload.override && isPhotoFileExist(payload.fileName) {
return path
}

// Write
try? payload.dataRepresentation.write(to: path, options: .atomic)
return path
}
Expand Down
18 changes: 17 additions & 1 deletion artify-core/artify-core/ViewModels/StatusBarViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public final class StatusBarViewModel: StatusBarViewModelType, StatusBarViewMode
public var input: StatusBarViewModelInput { return self }
public var output: StatusBarViewModelOutput { return self }

struct Constant {
static let FetchInterval: RxTimeInterval = 4 * 60 * 60 // 4 hours
}

// MARK: - Variable
private let bag = DisposeBag()

Expand Down Expand Up @@ -72,7 +76,19 @@ public final class StatusBarViewModel: StatusBarViewModelType, StatusBarViewMode
.disposed(by: bag)

// Get feature
getFeatureWallpaperPublisher.asObserver()
let getFeature = getFeatureWallpaperPublisher.asObserver()

// Wake up
let appWakeup = NSWorkspace.shared.notificationCenter.rx
.notification(NSWorkspace.didWakeNotification, object: nil)
.mapToVoid()

// Interval
let interval = Observable<Int>.interval(Constant.FetchInterval, scheduler: MainScheduler.instance).mapToVoid()

// Get feature
Observable.merge([getFeature, appWakeup, interval])
.observeOn(MainScheduler.instance)
.map { _ in self.menus.value.index(where: { $0.kind == Menu.Kind.getFeature } )! }
.map { self.menuItems.value[$0] }
.subscribe(onNext: {[weak self] (menu) in
Expand Down

0 comments on commit e10e564

Please sign in to comment.