Skip to content

Commit

Permalink
Patch 1.0.1
Browse files Browse the repository at this point in the history
feat:
- Added macOS support
- Added Cocoapods support
  • Loading branch information
FulcrumOne committed Mar 10, 2024
1 parent fecd1af commit 4be5f0d
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
branches:
- master
workflow_dispatch:

jobs:
build:
runs-on: macOS-latest
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Mijick

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.
18 changes: 18 additions & 0 deletions MijickTimer.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Pod::Spec.new do |s|
s.name = 'MijickTimer'
s.summary = 'Modern API for Timer'
s.description = 'MijickTimer is a free, open-source library for the Swift language that makes the process of managing timers much easier and clearer.'

s.version = '1.0.1'
s.ios.deployment_target = '13.0'
s.osx.deployment_target = '10.15'
s.swift_version = '5.0'

s.source_files = 'Sources/**/*'
s.frameworks = 'SwiftUI', 'Foundation', 'Combine'

s.homepage = 'https://github.com/Mijick/Timer.git'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Mijick' => '[email protected]' }
s.source = { :git => 'https://github.com/Mijick/Timer.git', :tag => s.version.to_s }
end
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import PackageDescription
let package = Package(
name: "MijickTimer",
platforms: [
.iOS(.v13)
.iOS(.v13),
.macOS(.v10_15)
],
products: [
.library(name: "MijickTimer", targets: ["MijickTimer"]),
Expand Down
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Timer is a free and open-source library dedicated for Swift that makes the proce
| **Platforms** | **Minimum Swift Version** |
|:----------|:----------|
| iOS 13+ | 5.0 |
| iPadOS 13+ | 5.0 |
| macOS 10.15+ | 5.0 |

### ⏳ Installation

Expand All @@ -74,8 +76,26 @@ Once you have your Swift package set up, adding Timer as a dependency is as easy
dependencies: [
.package(url: "https://github.com/Mijick/Timer", branch(“main”))
]
```
```

#### [Cocoapods][cocoapods]
Cocoapods is a dependency manager for Swift and Objective-C Cocoa projects that helps to scale them elegantly.

Installation steps:
- Install CocoaPods 1.10.0 (or later)
- [Generate CocoaPods][generate_cocoapods] for your project
```Swift
pod init
```
- Add CocoaPods dependency into your `Podfile`
```Swift
pod 'MijickTimer'
```
- Install dependency and generate `.xcworkspace` file
```Swift
pod install
```
- Use new XCode project file `.xcworkspace`
<br>

# Usage
Expand Down Expand Up @@ -160,17 +180,22 @@ Timer is released under the MIT license. See [LICENSE][License] for details.
<br>
[Navigattie] - Easier and cleaner way of navigating through your app
<br>
[CalendarView] - Create your own calendar object in no time
<br>
[GridView] - Lay out your data with no effort




[MIT]: https://en.wikipedia.org/wiki/MIT_License
[SPM]: https://www.swift.org/package-manager
[cocoapods]: https://cocoapods.org/
[generate_cocoapods]: https://github.com/square/cocoapods-generate
[Demo]: https://github.com/Mijick/Timer-Demo
[License]: https://github.com/Mijick/Timer/blob/main/LICENSE
[PopupView]: https://github.com/Mijick/PopupView
[Navigattie]: https://github.com/Mijick/Navigattie
[CalendarView]: https://github.com/Mijick/CalendarView
[GridView]: https://github.com/Mijick/GridView
14 changes: 14 additions & 0 deletions Sources/Internal/Extensions/NotificationCenter++.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,25 @@ import SwiftUI

extension NotificationCenter {
static func addAppStateNotifications(_ observer: Any, onDidEnterBackground backgroundNotification: Selector, onWillEnterForeground foregroundNotification: Selector) {
#if os(iOS)
Self.default.addObserver(observer, selector: (backgroundNotification), name: UIApplication.didEnterBackgroundNotification, object: nil)
Self.default.addObserver(observer, selector: (foregroundNotification), name: UIApplication.willEnterForegroundNotification, object: nil)

#elseif os(macOS)
Self.default.addObserver(observer, selector: (backgroundNotification), name: NSApplication.didResignActiveNotification, object: nil)
Self.default.addObserver(observer, selector: (foregroundNotification), name: NSApplication.willBecomeActiveNotification, object: nil)

#endif
}
static func removeAppStateChangedNotifications(_ observer: Any) {
#if os(iOS)
Self.default.removeObserver(observer, name: UIApplication.didEnterBackgroundNotification, object: nil)
Self.default.removeObserver(observer, name: UIApplication.willEnterForegroundNotification, object: nil)

#elseif os(macOS)
Self.default.removeObserver(observer, name: NSApplication.didResignActiveNotification, object: nil)
Self.default.removeObserver(observer, name: NSApplication.willBecomeActiveNotification, object: nil)

#endif
}
}
21 changes: 19 additions & 2 deletions Sources/Internal/MTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,31 @@ private extension MTimer {
}
private extension MTimer {
func updateInternalTimer(_ start: Bool) { DispatchQueue.main.async { [self] in switch start {
case true: internalTimer = .scheduledTimer(withTimeInterval: publisherTime, repeats: true, block: handleTimeChange); internalTimer?.tolerance = publisherTimeTolerance
case false: internalTimer?.invalidate()
case true: updateInternalTimerStart()
case false: updateInternalTimerStop()
}}}
func updateObservers(_ start: Bool) { switch start {
case true: addObservers()
case false: removeObservers()
}}
}
private extension MTimer {
func updateInternalTimerStart() {
internalTimer = .scheduledTimer(withTimeInterval: publisherTime, repeats: true, block: handleTimeChange)
internalTimer?.tolerance = publisherTimeTolerance
updateInternalTimerStartAddToRunLoop()
}
func updateInternalTimerStop() { internalTimer?.invalidate() }
}
private extension MTimer {
/// **CONTEXT**: On macOS, when the mouse is down in a menu item or other tracking loop, the timer will not start.
/// **DECISION**: Adding a timer the RunLoop seems to fix the issue issue.
func updateInternalTimerStartAddToRunLoop() {
#if os(macOS)
if let internalTimer { RunLoop.main.add(internalTimer, forMode: .common) }
#endif
}
}

// MARK: - Handling Time Change
private extension MTimer {
Expand Down

0 comments on commit 4be5f0d

Please sign in to comment.