Skip to content

Commit

Permalink
Remove any tracking dependency remnants (crashlytics), remove any upd…
Browse files Browse the repository at this point in the history
…ate check remnants, add modified PockKit pod for better swiping
  • Loading branch information
konstantintuev committed Jan 15, 2021
1 parent 7339227 commit 82448ad
Show file tree
Hide file tree
Showing 15 changed files with 585 additions and 41 deletions.
16 changes: 0 additions & 16 deletions Pock.xcworkspace/contents.xcworkspacedata

This file was deleted.

8 changes: 0 additions & 8 deletions Pock.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings

This file was deleted.

4 changes: 2 additions & 2 deletions Pock/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import Cocoa
import Defaults
import Preferences
import Fabric
import Crashlytics
//import Fabric
//import Crashlytics
import Magnet
@_exported import PockKit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ final class GeneralPreferencePane: NSViewController, PreferencePane {
@IBOutlet weak var checkForUpdatesButton: NSButton!

/// Endpoint
/// TODO: maybe add an update check UR
#if DEBUG
private let latestVersionURLString: String = "https://pock.dev/api/dev/latestRelease.json"
private let latestVersionURLString: String = ""
#else
private let latestVersionURLString: String = "https://pock.dev/api/latestRelease.json"
private let latestVersionURLString: String = ""
#endif

/// Updates
Expand Down Expand Up @@ -136,6 +137,11 @@ extension GeneralPreferencePane {
}

func hasLatestVersion(completion: @escaping (String?, URL?) -> Void) {
//while there is no update url, just report no update available
if (latestVersionURLString.isEmpty) {
completion(nil, nil)
return
}
let latestVersionURL: URL = URL(string: latestVersionURLString)!
let request = URLRequest(url: latestVersionURL, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 60.0)
URLSession.shared.invalidateAndCancel()
Expand Down
19 changes: 19 additions & 0 deletions PockKit/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2019 Pock <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
46 changes: 46 additions & 0 deletions PockKit/PockKit.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Be sure to run `pod lib lint PockKit.podspec' to ensure this is a
# valid spec before submitting.
#

Pod::Spec.new do |s|
s.name = 'PockKit'
s.version = '0.1.3'
s.summary = 'Core framework for building Pock widgets'

s.description = <<-DESC
PockKit is the core framework for building Pock widgets.
Documentation will be available soon on https://kit.pock.dev/docs/
DESC

s.homepage = 'https://kit.pock.dev'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'pigigaldi' => '[email protected]' }
s.source = { :git => 'https://github.com/pigigaldi/PockKit.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/pigigaldi'

s.platform = :osx
s.osx.deployment_target = '10.12.2'
s.swift_version = '5'

s.frameworks = 'Foundation'
s.frameworks = 'AppKit'

s.exclude_files = ['docs/**/*']

s.subspec 'Protocols' do |ss|
ss.source_files = 'PockKit/Protocols/**/*'
end

s.subspec 'Sources' do |ss|
ss.dependency 'PockKit/3rd'
ss.source_files = 'PockKit/Sources/**/*'
end

s.subspec '3rd' do |ss|
ss.source_files = 'PockKit/3rd/**/*'
end

s.dependency 'SnapKit'

end
170 changes: 170 additions & 0 deletions PockKit/PockKit/3rd/ScrollingTextView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/// ref.: https://gist.github.com/NicholasBellucci/b5e9d31c47f335c36aa043f5f39eedb2

import Cocoa

open class ScrollingTextView: NSView {

/// Text to scroll
open var text: NSString?

/// Font for scrolling text
open var font: NSFont?

/// Scrolling text color
open var textColor: NSColor = .headerTextColor

/// Determines if the text should be delayed before starting scroll
open var isDelayed: Bool = true

/// Spacing between the tail and head of the scrolling text
open var spacing: CGFloat = 20

/// Amount of time the text is delayed before scrolling
open var delay: TimeInterval = 2 {
didSet {
updateTraits()
}
}

/// Amount of scroll the text should do before stop
/// - Values:
/// - 0 = Infinite
open var numberOfLoop: Int = 0 {
didSet {
updateTraits()
}
}
private(set) var loopCount: Int = 0

/// Length of the scrolling text view
open var length: CGFloat = 0 {
didSet {
updateTraits()
}
}

/// Speed at which the text scrolls. This number is divided by 100.
open var speed: Double = 4 {
didSet {
updateTraits()
}
}

private var timer: Timer?
private var point = NSPoint(x: 0, y: 0)
private var timeInterval: TimeInterval?

public private(set) var stringSize = NSSize(width: 0, height: 0) {
didSet {
point.x = 0
}
}

private var timerSpeed: Double? {
return speed / 100
}

public private(set) lazy var textFontAttributes: [NSAttributedString.Key: Any] = {
return [NSAttributedString.Key.font: font ?? NSFont.systemFont(ofSize: 14)]
}()

/**
Sets up the scrolling text view
- Parameters:
- string: The string that will be used as the text in the view
*/
open func setup(string: String) {
text = string as NSString
let _stringSize = text?.size(withAttributes: textFontAttributes) ?? .zero
stringSize = _stringSize
setNeedsDisplay(NSRect(x: 0, y: 0, width: frame.width, height: frame.height))
updateTraits()
}

open func set(speed: Double) {
setSpeed(newInterval: speed)
}
}

private extension ScrollingTextView {
func setSpeed(newInterval: TimeInterval) {
loopCount = 0
clearTimer()
timeInterval = newInterval

guard let timeInterval = timeInterval else { return }
if timer == nil, timeInterval > 0.0, text != nil {
if #available(OSX 10.12, *) {
timer = Timer.scheduledTimer(timeInterval: newInterval, target: self, selector: #selector(update(_:)), userInfo: nil, repeats: true)

guard let timer = timer else { return }
RunLoop.main.add(timer, forMode: RunLoop.Mode.common)
} else {
// Fallback on earlier versions
}
} else {
clearTimer()
point.x = 0
}
}

func updateTraits() {
clearTimer()

if stringSize.width > length {
guard let speed = timerSpeed else { return }
if #available(OSX 10.12, *), isDelayed {
timer = Timer.scheduledTimer(withTimeInterval: delay, repeats: false, block: { [weak self] timer in
self?.setSpeed(newInterval: speed)
})
} else {
setSpeed(newInterval: speed)
}
} else {
setSpeed(newInterval: 0.0)
}
}

func clearTimer() {
timer?.invalidate()
timer = nil
}

@objc
func update(_ sender: Timer) {
point.x = point.x - 1
setNeedsDisplay(NSRect(x: 0, y: 0, width: frame.width, height: frame.height))
if Int(point.x) == 0 {
let shouldStop = numberOfLoop > 0 && loopCount == numberOfLoop
print("Loop count: \(loopCount). Should stop: \(shouldStop)")
if shouldStop {
point.x = 0
setSpeed(newInterval: 0)
setNeedsDisplay(NSRect(x: 0, y: 0, width: frame.width, height: frame.height))
}
loopCount += 1
}
}
}

extension ScrollingTextView {
override open func draw(_ dirtyRect: NSRect) {
if point.x + stringSize.width < 0 {
point.x += stringSize.width + spacing
}

textFontAttributes[NSAttributedString.Key.foregroundColor] = textColor
text?.draw(at: point, withAttributes: textFontAttributes)

if point.x < 0 {
var otherPoint = point
otherPoint.x += stringSize.width + spacing
text?.draw(at: otherPoint, withAttributes: textFontAttributes)
}
}

override open func layout() {
super.layout()
point.y = (frame.height - stringSize.height) / 2
}
}
22 changes: 22 additions & 0 deletions PockKit/PockKit/Protocols/PKWidget.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// PKWidget.swift
// PockKit
//
// Created by Pierluigi Galdi on 19/05/2019.
// Copyright © 2019 Pierluigi Galdi. All rights reserved.
//

import Foundation
import AppKit

@objc (PKWidget) public protocol PKWidget: class {
var identifier: NSTouchBarItem.Identifier { get }
var customizationLabel: String { get set }
var view: NSView! { get set }

init()
@objc optional func viewWillAppear()
@objc optional func viewDidAppear()
@objc optional func viewWillDisappear()
@objc optional func viewDidDisappear()
}
Loading

0 comments on commit 82448ad

Please sign in to comment.