Skip to content

Dev/foundation #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a10b1b0
First version of CodeEditExtension API
Wouter01 Dec 30, 2022
8ced3f7
Extension Settings Window + (temporary) move to SwiftUI App Lifecycle
Wouter01 Jan 2, 2023
b5180a9
- Fixed environment
Wouter01 Jan 2, 2023
96750ce
Added openWindow environment value for extensions
Wouter01 Jan 3, 2023
218de3f
Fixed examples
Wouter01 Jan 3, 2023
f57fbff
added some documentation
Wouter01 Jan 3, 2023
54dbb48
removed old target
Wouter01 Jan 3, 2023
a8cbc5b
CodeEditExtension protocol changes
Wouter01 Jan 3, 2023
c4e6cc7
Added documentation
Wouter01 Jan 3, 2023
5d1acd0
Merge branch 'main' into dev/foundation
Wouter01 Jan 3, 2023
e2ecf2a
Removed shared instance due to bug
Wouter01 Jan 3, 2023
483ea10
Added extensionURL support
Wouter01 Mar 24, 2023
29530a9
updated sidebar api
Wouter01 Mar 24, 2023
e187e16
refaactored files
Wouter01 Mar 24, 2023
1833d85
removed old sidebar implementation
Wouter01 Mar 24, 2023
1d28eae
small improvements
Wouter01 Mar 25, 2023
bd43313
Small improvements to Extensionkind enum
Wouter01 Mar 25, 2023
33b6942
made var weak
Wouter01 Mar 25, 2023
02bef66
Removed old stuff
Wouter01 Mar 26, 2023
104c545
Moved icon into sidebar modifier
Wouter01 Mar 26, 2023
6e27b8f
Update
Wouter01 May 22, 2023
2aeca8c
update dependency
Wouter01 May 22, 2023
e09f094
Added docs
Wouter01 May 23, 2023
b451296
removed deprecated code
Wouter01 May 23, 2023
fd5cbba
add swiftlint and fix warnings
Wouter01 May 23, 2023
bbda072
fix warnings
Wouter01 May 23, 2023
2114c61
Merge branch 'main' into dev/foundation
Wouter01 May 23, 2023
2160012
Update tests.sh
Wouter01 May 23, 2023
f7452da
small fixes
Wouter01 May 23, 2023
2d7f534
add some more documentation
Wouter01 May 23, 2023
faa2a7b
change swiftlint to swiftlintplugin package
Wouter01 May 23, 2023
b0e0c5b
update docs
Wouter01 May 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/scripts/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export LC_CTYPE=en_US.UTF-8
set -o pipefail && arch -"${ARCH}" xcodebuild \
-scheme CodeEditKit \
-destination "platform=macos,arch=${ARCH}" \
-skipPackagePluginValidation \
clean test | xcpretty
9 changes: 4 additions & 5 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
disabled_rules:
- todo
- trailing_comma
- nesting
- force_cast

line_length: 160

type_name:
allowed_symbols: ['_']
excluded:
- ID

identifier_name:
min_length: 2
allowed_symbols: ['_']
excluded:
- c
- id
- vc
95 changes: 95 additions & 0 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 22 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
// swift-tools-version:5.6
// swift-tools-version:5.7

import PackageDescription

let package = Package(
name: "CodeEditKit",
platforms: [
.macOS(.v13)
],
products: [
.library(
name: "CodeEditKit",
type: .dynamic,
targets: ["CodeEditKit"]),
targets: ["CodeEditKit"])
],
dependencies: [
.package(url: "https://github.com/ChimeHQ/ConcurrencyPlus", branch: "main"),
.package(url: "https://github.com/ChimeHQ/LanguageClient", from: "0.5.0"),
.package(url: "https://github.com/ChimeHQ/ProcessService", from: "0.2.6"),
.package(
url: "https://github.com/lukepistrol/SwiftLintPlugin",
from: "0.2.2"
),
.package(
url: "https://github.com/Flight-School/AnyCodable",
from: "0.6.0"
)
],
dependencies: [],
targets: [
.target(
name: "CodeEditKit",
dependencies: []),
dependencies: ["AnyCodable", "ConcurrencyPlus", "LanguageClient", .product(name: "ProcessServiceClient", package: "ProcessService")],
plugins: [.plugin(name: "SwiftLint", package: "SwiftLintPlugin")]
),
.testTarget(
name: "CodeEditKitTests",
dependencies: ["CodeEditKit"]),
dependencies: ["CodeEditKit"])
]
)
39 changes: 39 additions & 0 deletions Sources/CodeEditKit/CodableColorArray.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// File.swift
//
//
// Created by Wouter Hennen on 30/12/2022.
//

import Foundation
import AppKit

@propertyWrapper
public struct CodableColorArray {
public var wrappedValue: [NSColor]

public init(wrappedValue: [NSColor]) {
self.wrappedValue = wrappedValue
}
}

extension CodableColorArray: Codable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let data = try container.decode(Data.self)

guard let color = try NSKeyedUnarchiver.unarchivedArrayOfObjects(ofClass: NSColor.self, from: data) else {
throw DecodingError.dataCorruptedError(
in: container,
debugDescription: "Invalid color"
)
}
wrappedValue = color
}

public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
let data = try NSKeyedArchiver.archivedData(withRootObject: wrappedValue, requiringSecureCoding: true)
try container.encode(data)
}
}
52 changes: 52 additions & 0 deletions Sources/CodeEditKit/CodableWrappers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// File 2.swift
//
//
// Created by Wouter Hennen on 06/12/2022.
//

import Foundation

@propertyWrapper
public struct Encoded<T: Encodable> {
public var wrappedValue: T

public init(wrappedValue: T) {
self.wrappedValue = wrappedValue
}

public var errorDescription: String? {
do {
_ = try JSONEncoder().encode(wrappedValue)
return nil
} catch {
return error.localizedDescription
}
}

public var projectedValue: Data? {
try? JSONEncoder().encode(wrappedValue)
}
}

@propertyWrapper
public struct Decoded<T: Decodable> {
public var wrappedValue: Data

public init(wrappedValue: Data) {
self.wrappedValue = wrappedValue
}

public var errorDescription: String? {
do {
_ = try JSONDecoder().decode(T.self, from: wrappedValue)
return nil
} catch {
return error.localizedDescription
}
}

public var projectedValue: T? {
try? JSONDecoder().decode(T.self, from: wrappedValue)
}
}
41 changes: 41 additions & 0 deletions Sources/CodeEditKit/CodeEditExtension+Body.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// File.swift
//
//
// Created by Wouter Hennen on 03/01/2023.
//

import Foundation
import ExtensionKit

struct EmptyAppExtensionScene: AppExtensionScene {
var body: Never {
fatalError()
}
}

public extension CodeEditExtension {
var body: some AppExtensionScene {
EmptyAppExtensionScene()
}
}

public extension CodeEditExtension where Self: SettingsExtension {
var body: some AppExtensionScene {
settingsScene
}
}

public extension CodeEditExtension where Self: SidebarExtension {
var body: some AppExtensionScene {
sidebarScenes
}
}

public extension CodeEditExtension where Self: SettingsExtension & SidebarExtension {
@AppExtensionSceneBuilder
var body: some AppExtensionScene {
settingsScene
sidebarScenes
}
}
77 changes: 77 additions & 0 deletions Sources/CodeEditKit/CodeEditExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
//
// File.swift
//
//
// Created by Wouter Hennen on 30/12/2022.
//

import ExtensionKit
import ExtensionFoundation

public protocol CodeEditExtension: AppExtension {

/// UI scenes of the extension.
associatedtype Body: AppExtensionScene

/// Extension Configuration.
associatedtype Configuration = AppExtensionSceneConfiguration

/// A brief description of the extension. Should be max a few words.
var description: String { get }

/// A list of Entitlements the app needs, e.g. Network Access.
var entitlements: [Entitlement] { get }

/// UI scenes of the extension.
/// Use the default implementation.
var body: Body { get }
}

extension CodeEditExtension {

var extensionURL: URL {
Bundle.main.bundleURL
}

func gatherAvailableExtensions() -> [ExtensionKind] {
var extensions: [ExtensionKind] = []

if self is any SettingsExtension {
extensions.append(.settings)
}

if let self = self as? any SidebarExtension {
extensions.append(contentsOf: self.availableExtensions)
}

return extensions
}
}

public extension CodeEditExtension where Self: AnyObject {
/// XPC Configuration for communication with CodeEdit.
/// Use the default implementation.
var configuration: AppExtensionSceneConfiguration {
AppExtensionSceneConfiguration(self.body, configuration: SettingsExtensionConfiguration(self))
}
}

struct SettingsExtensionConfiguration<E: CodeEditExtension & AnyObject>: AppExtensionConfiguration {
public func accept(connection: NSXPCConnection) -> Bool {
guard let appExtension else {
return false
}

connection.exportedInterface = .init(with: XPCWrappable.self)
connection.exportedObject = XPCWrapper(appExtension)
connection.resume()

return true
}

weak var appExtension: E?

public init(_ appExtension: E) {
self.appExtension = appExtension
}
}
13 changes: 13 additions & 0 deletions Sources/CodeEditKit/Debugging/Logging.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Logging.swift
//
//
// Created by Wouter Hennen on 22/05/2023.
//

import Foundation

public func print(_ items: Any..., separator: String = " ", terminator: String = "\n") {
let formedString = items.map { String(describing: $0) }.joined(separator: separator)
NSLog(formedString)
}
Loading