forked from pock/pock
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove any tracking dependency remnants (crashlytics), remove any upd…
…ate check remnants, add modified PockKit pod for better swiping
- Loading branch information
1 parent
7339227
commit 82448ad
Showing
15 changed files
with
585 additions
and
41 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
Oops, something went wrong.