Skip to content

Commit

Permalink
Release 2.0.0 (#2)
Browse files Browse the repository at this point in the history
* Format code

* Increase test coverage

* Update `ci.yml`

* Update `README.md`

* Add `codecov.yml`

* Add templates
  • Loading branch information
ns-vasilev authored Sep 19, 2023
1 parent 4c4a35a commit e84c3d3
Show file tree
Hide file tree
Showing 39 changed files with 1,359 additions and 250 deletions.
41 changes: 41 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
name: "🐛 Bug Report"
about: Report a reproducible bug or regression.
title: 'Bug: '
labels: 'bug'

---

<!--
Please provide a clear and concise description of what the bug is. Include
screenshots if needed. Please test using the latest version of the relevant
React packages to make sure your issue has not already been fixed.
-->

Application version:

## Steps To Reproduce

1.
2.

<!--
Your bug will get fixed much faster if we can run your code and it doesn't
have dependencies other than React. Issues without reproduction steps or
code examples may be immediately closed as not actionable.
-->

Link to code example:

<!--
Please provide a CodeSandbox (https://codesandbox.io/s/new), a link to a
repository on GitHub, or provide a minimal code example that reproduces the
problem. You may provide a screenshot of the application if you think it is
relevant to your bug report. Here are some tips for providing a minimal
example: https://stackoverflow.com/help/mcve.
-->

## The current behavior


## The expected behavior
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: 🛠 Feature request
about: If you have a feature request for the Nexus, file it here.
labels: 'type: enhancement'
---

**Feature description**
Clearly and concisely describe the feature.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.
9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/bug_template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## Bug description
Clearly and concisely describe the problem.

## Solution description
Describe your code changes in detail for reviewers. Explain the technical solution you have provided and how it fixes the issue case.

## Covered unit test cases
- [x] yes
- [x] no
12 changes: 12 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/feature_template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## Feature description
Clearly and concisely describe the feature.

## Solution description
Describe your code changes in detail for reviewers.

## Areas affected and ensured
List out the areas affected by your code changes.

## Covered unit test cases
- [x] yes
- [x] no
22 changes: 20 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@ on:
branches:
- main
- dev
paths:
- ".github/workflows/**"
- "Package.swift"
- "Source/**"
- "Tests/**"
pull_request:
branches: [ main ]
paths:
- '.swiftlint.yml'
- ".github/workflows/**"
- "Package.swift"
- "Source/**"
- "Tests/**"

concurrency:
group: ci
Expand All @@ -26,10 +36,18 @@ jobs:
- destination: "OS=16.1,name=iPhone 14 Pro"
name: "iOS"
scheme: "Nexus"
sdk: iphonesimulator
- destination: "OS=9.1,name=Apple Watch Series 8 (45mm)"
name: "watchOS"
scheme: "Nexus"
sdk: watchsimulator
steps:
- uses: actions/checkout@v3
- name: ${{ matrix.name }}
run: xcodebuild test -scheme "${{ matrix.scheme }}" -destination "${{ matrix.destination }}" clean
run: xcodebuild test -scheme "${{ matrix.scheme }}" -destination "${{ matrix.destination }}" clean -enableCodeCoverage YES -resultBundlePath "./${{ matrix.sdk }}.xcresult" | xcpretty -r junit
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
xcode: true
xcode_archive_path: "./${{ matrix.sdk }}.xcresult"
3 changes: 0 additions & 3 deletions .swiftlint → .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ disabled_rules:
opt_in_rules: # some rules are only opt-in
- anyobject_protocol
- array_init
- attributes
- closure_body_length
- closure_end_indentation
- closure_spacing
- collection_alignment
- conditional_returns_on_newline
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
Expand Down Expand Up @@ -128,7 +126,6 @@ nesting:
statement_level:
warning: 10


type_name:
max_length:
warning: 40
Expand Down
102 changes: 102 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/Nexus.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Nexus"
BuildableName = "Nexus"
BlueprintName = "Nexus"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NexusTests"
BuildableName = "NexusTests"
BlueprintName = "NexusTests"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES"
onlyGenerateCoverageForSpecifiedTargets = "YES">
<CodeCoverageTargets>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Nexus"
BuildableName = "Nexus"
BlueprintName = "Nexus"
ReferencedContainer = "container:">
</BuildableReference>
</CodeCoverageTargets>
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NexusTests"
BuildableName = "NexusTests"
BlueprintName = "NexusTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "Nexus"
BuildableName = "Nexus"
BlueprintName = "Nexus"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let package = Package(
.iOS(.v13),
.watchOS(.v7),
],
products: [.library(name: "Nexus", targets: ["Nexus"]),],
products: [.library(name: "Nexus", targets: ["Nexus"])],
dependencies: [],
targets: [
.target(name: "Nexus", dependencies: []),
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<a href="https://developer.apple.com/swift"><img alt="Swift5.7" src="https://img.shields.io/badge/language-Swift5.7-orange.svg"/></a>
<a href="https://github.com/space-code/concurrency"><img alt="CI" src="https://github.com/space-code/nexus/actions/workflows/ci.yml/badge.svg?branch=main"></a>
<a href="https://github.com/apple/swift-package-manager" alt="Nexus on Swift Package Manager"><img src="https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg" /></a>
<a href="https://codecov.io/gh/space-code/nexus"><img alt="CodeCov" src="https://codecov.io/github/space-code/nexus/graph/badge.svg?token=4MP7MPTQS5"></a>
</p>

## Description
Expand All @@ -23,7 +24,7 @@ Nexus is a wrapper around `WatchConnectivity` that simplifies the interaction be

## Usage

1. Define a message model, like this:
1. Define a message model like this:
```swift
import Nexus

Expand Down Expand Up @@ -51,7 +52,7 @@ communicationService.receiveMessage(TestMessage.self)
.store(in: &disposables)
```

3. Send a message to Apple Watch or iPhone
3. Send a message to Apple Watch or iPhone:
```swift
import Nexus

Expand All @@ -73,7 +74,7 @@ Once you have your Swift package set up, adding `nexus` as a dependency is as ea

```swift
dependencies: [
.package(url: "https://github.com/space-code/nexus.git", .upToNextMajor(from: "1.0.0"))
.package(url: "https://github.com/space-code/nexus.git", .upToNextMajor(from: "2.0.0"))
]
```

Expand All @@ -95,4 +96,4 @@ Please feel free to help out with this project! If you see something that could
Nikita Vasilev, [email protected]

## License
nexus is available under the MIT license. See the LICENSE file for more info.
nexus is available under the MIT license. See the LICENSE file for more info.
34 changes: 34 additions & 0 deletions Sources/Nexus/Classes/Core/Interfaces/INotificationCenter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Nexus
// Copyright © 2023 Space Code. All rights reserved.
//

import Foundation

// MARK: - INotificationCenter

/// A notification dispatch mechanism that enables the broadcast of information to registered observers.
public protocol INotificationCenter {
/// Creates a notification with a given name and sender and posts it to the notification center.
///
/// - Parameters:
/// - aName: The name of the notification.
/// - anObject: The object posting the notification.
func post(name aName: NSNotification.Name, object anObject: Any?)

/// Returns a publisher that emits events when broadcasting notifications.
///
/// - Parameters:
/// - name: The name of the notification to publish.
/// - object: The object posting the named notification. If nil, the publisher emits elements
/// for any object producing a notification with the given name.
///
/// - Returns: A Publisher that emits events when broadcasting notifications.
func publisher(for name: Notification.Name, object: AnyObject?) -> NotificationCenter.Publisher
}

extension INotificationCenter {
func publisher(for name: Notification.Name) -> NotificationCenter.Publisher {
publisher(for: name, object: nil)
}
}
45 changes: 45 additions & 0 deletions Sources/Nexus/Classes/Core/Interfaces/IWCSession.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Nexus
// Copyright © 2023 Space Code. All rights reserved.
//

import Foundation
import WatchConnectivity

// MARK: - IWCSession

/// A type that initiates communication between a WatchKit extension and its companion iOS app.
public protocol IWCSession: AnyObject {
/// The current activation state of the session.
var activationState: WCSessionActivationState { get }

#if os(iOS)
/// A Boolean value indicating whether the currently paired and active Apple Watch has installed the app.
var isWatchAppInstalled: Bool { get }
#else
/// A Boolean value indicating whether the companion has installed the app.
var isCompanionAppInstalled: Bool { get }
#endif

/// The delegate for the session object.
var delegate: WCSessionDelegate? { get set }

/// Activates the session asynchronously.
func activate()

/// Sends a message immediately to the paired and active device and optionally handles a response.
///
/// - Parameters:
/// - message: A dictionary of property list values that you want to send.
/// You define the contents of the dictionary that your counterpart supports.
/// This parameter must not be nil.
/// - replyHandler: A reply handler for receiving a response from the counterpart.
/// Specify nil if you do not want to receive a reply.
/// - errorHandler: A block that is executed when an error occurs.
/// Specify nil if you do not care about error information.
func sendMessage(_ message: [String: Any], replyHandler: (([String: Any]) -> Void)?, errorHandler: ((Error) -> Void)?)
}

// MARK: - WCSession + IWCSession

extension WCSession: IWCSession {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Nexus
// Copyright © 2023 Space Code. All rights reserved.
//

import Foundation

/// A type that identifies compatible session communication.
public protocol ISessionCompatibleProvider {
/// A Boolean value indicating whether the current iOS device is able to use a session object.
var isSupported: Bool { get }
}
Loading

0 comments on commit e84c3d3

Please sign in to comment.