Skip to content

Commit 96baa07

Browse files
authored
Dev/foundation (#14)
* First version of CodeEditExtension API Signed-off-by: Wouter01 <[email protected]> * Extension Settings Window + (temporary) move to SwiftUI App Lifecycle * - Fixed environment - Added extension Navigators to CodeEdit Window * Added openWindow environment value for extensions Signed-off-by: Wouter01 <[email protected]> * Fixed examples Signed-off-by: Wouter01 <[email protected]> * added some documentation Signed-off-by: Wouter01 <[email protected]> * removed old target Signed-off-by: Wouter01 <[email protected]> * CodeEditExtension protocol changes - Added default body implementation - Added ObservableObject requirement - Moved from @main struct to @main final class Signed-off-by: Wouter01 <[email protected]> * Added documentation Signed-off-by: Wouter01 <[email protected]> * Removed shared instance due to bug Signed-off-by: Wouter01 <[email protected]> * Added extensionURL support Signed-off-by: Wouter01 <[email protected]> * updated sidebar api Signed-off-by: Wouter01 <[email protected]> * refaactored files Signed-off-by: Wouter01 <[email protected]> * removed old sidebar implementation Signed-off-by: Wouter01 <[email protected]> * small improvements Signed-off-by: Wouter01 <[email protected]> * Small improvements to Extensionkind enum Signed-off-by: Wouter01 <[email protected]> * made var weak Signed-off-by: Wouter01 <[email protected]> * Removed old stuff Signed-off-by: Wouter01 <[email protected]> * Moved icon into sidebar modifier Signed-off-by: Wouter01 <[email protected]> * Update Signed-off-by: Wouter01 <[email protected]> * update dependency Signed-off-by: Wouter01 <[email protected]> * Added docs Signed-off-by: Wouter01 <[email protected]> * removed deprecated code Signed-off-by: Wouter01 <[email protected]> * add swiftlint and fix warnings Signed-off-by: Wouter01 <[email protected]> * fix warnings Signed-off-by: Wouter01 <[email protected]> * Update tests.sh * small fixes Signed-off-by: Wouter01 <[email protected]> * add some more documentation Signed-off-by: Wouter01 <[email protected]> * change swiftlint to swiftlintplugin package Signed-off-by: Wouter01 <[email protected]> * update docs Signed-off-by: Wouter01 <[email protected]> --------- Signed-off-by: Wouter01 <[email protected]>
1 parent f5fc60e commit 96baa07

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1502
-149
lines changed

.github/scripts/tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ export LC_CTYPE=en_US.UTF-8
1616
set -o pipefail && arch -"${ARCH}" xcodebuild \
1717
-scheme CodeEditKit \
1818
-destination "platform=macos,arch=${ARCH}" \
19+
-skipPackagePluginValidation \
1920
clean test | xcpretty

.swiftlint.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
disabled_rules:
2-
- todo
3-
- trailing_comma
4-
- nesting
2+
- force_cast
3+
4+
line_length: 160
55

66
type_name:
7+
allowed_symbols: ['_']
78
excluded:
89
- ID
910

1011
identifier_name:
1112
min_length: 2
1213
allowed_symbols: ['_']
1314
excluded:
14-
- c
1515
- id
16-
- vc

Package.resolved

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
1-
// swift-tools-version:5.6
1+
// swift-tools-version:5.7
22

33
import PackageDescription
44

55
let package = Package(
66
name: "CodeEditKit",
7+
platforms: [
8+
.macOS(.v13)
9+
],
710
products: [
811
.library(
912
name: "CodeEditKit",
1013
type: .dynamic,
11-
targets: ["CodeEditKit"]),
14+
targets: ["CodeEditKit"])
15+
],
16+
dependencies: [
17+
.package(url: "https://github.com/ChimeHQ/ConcurrencyPlus", branch: "main"),
18+
.package(url: "https://github.com/ChimeHQ/LanguageClient", from: "0.5.0"),
19+
.package(url: "https://github.com/ChimeHQ/ProcessService", from: "0.2.6"),
20+
.package(
21+
url: "https://github.com/lukepistrol/SwiftLintPlugin",
22+
from: "0.2.2"
23+
),
24+
.package(
25+
url: "https://github.com/Flight-School/AnyCodable",
26+
from: "0.6.0"
27+
)
1228
],
13-
dependencies: [],
1429
targets: [
1530
.target(
1631
name: "CodeEditKit",
17-
dependencies: []),
32+
dependencies: ["AnyCodable", "ConcurrencyPlus", "LanguageClient", .product(name: "ProcessServiceClient", package: "ProcessService")],
33+
plugins: [.plugin(name: "SwiftLint", package: "SwiftLintPlugin")]
34+
),
1835
.testTarget(
1936
name: "CodeEditKitTests",
20-
dependencies: ["CodeEditKit"]),
37+
dependencies: ["CodeEditKit"])
2138
]
2239
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Wouter Hennen on 30/12/2022.
6+
//
7+
8+
import Foundation
9+
import AppKit
10+
11+
@propertyWrapper
12+
public struct CodableColorArray {
13+
public var wrappedValue: [NSColor]
14+
15+
public init(wrappedValue: [NSColor]) {
16+
self.wrappedValue = wrappedValue
17+
}
18+
}
19+
20+
extension CodableColorArray: Codable {
21+
public init(from decoder: Decoder) throws {
22+
let container = try decoder.singleValueContainer()
23+
let data = try container.decode(Data.self)
24+
25+
guard let color = try NSKeyedUnarchiver.unarchivedArrayOfObjects(ofClass: NSColor.self, from: data) else {
26+
throw DecodingError.dataCorruptedError(
27+
in: container,
28+
debugDescription: "Invalid color"
29+
)
30+
}
31+
wrappedValue = color
32+
}
33+
34+
public func encode(to encoder: Encoder) throws {
35+
var container = encoder.singleValueContainer()
36+
let data = try NSKeyedArchiver.archivedData(withRootObject: wrappedValue, requiringSecureCoding: true)
37+
try container.encode(data)
38+
}
39+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// File 2.swift
3+
//
4+
//
5+
// Created by Wouter Hennen on 06/12/2022.
6+
//
7+
8+
import Foundation
9+
10+
@propertyWrapper
11+
public struct Encoded<T: Encodable> {
12+
public var wrappedValue: T
13+
14+
public init(wrappedValue: T) {
15+
self.wrappedValue = wrappedValue
16+
}
17+
18+
public var errorDescription: String? {
19+
do {
20+
_ = try JSONEncoder().encode(wrappedValue)
21+
return nil
22+
} catch {
23+
return error.localizedDescription
24+
}
25+
}
26+
27+
public var projectedValue: Data? {
28+
try? JSONEncoder().encode(wrappedValue)
29+
}
30+
}
31+
32+
@propertyWrapper
33+
public struct Decoded<T: Decodable> {
34+
public var wrappedValue: Data
35+
36+
public init(wrappedValue: Data) {
37+
self.wrappedValue = wrappedValue
38+
}
39+
40+
public var errorDescription: String? {
41+
do {
42+
_ = try JSONDecoder().decode(T.self, from: wrappedValue)
43+
return nil
44+
} catch {
45+
return error.localizedDescription
46+
}
47+
}
48+
49+
public var projectedValue: T? {
50+
try? JSONDecoder().decode(T.self, from: wrappedValue)
51+
}
52+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Wouter Hennen on 03/01/2023.
6+
//
7+
8+
import Foundation
9+
import ExtensionKit
10+
11+
struct EmptyAppExtensionScene: AppExtensionScene {
12+
var body: Never {
13+
fatalError()
14+
}
15+
}
16+
17+
public extension CodeEditExtension {
18+
var body: some AppExtensionScene {
19+
EmptyAppExtensionScene()
20+
}
21+
}
22+
23+
public extension CodeEditExtension where Self: SettingsExtension {
24+
var body: some AppExtensionScene {
25+
settingsScene
26+
}
27+
}
28+
29+
public extension CodeEditExtension where Self: SidebarExtension {
30+
var body: some AppExtensionScene {
31+
sidebarScenes
32+
}
33+
}
34+
35+
public extension CodeEditExtension where Self: SettingsExtension & SidebarExtension {
36+
@AppExtensionSceneBuilder
37+
var body: some AppExtensionScene {
38+
settingsScene
39+
sidebarScenes
40+
}
41+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Wouter Hennen on 30/12/2022.
6+
//
7+
8+
import ExtensionKit
9+
import ExtensionFoundation
10+
11+
public protocol CodeEditExtension: AppExtension {
12+
13+
/// UI scenes of the extension.
14+
associatedtype Body: AppExtensionScene
15+
16+
/// Extension Configuration.
17+
associatedtype Configuration = AppExtensionSceneConfiguration
18+
19+
/// A brief description of the extension. Should be max a few words.
20+
var description: String { get }
21+
22+
/// A list of Entitlements the app needs, e.g. Network Access.
23+
var entitlements: [Entitlement] { get }
24+
25+
/// UI scenes of the extension.
26+
/// Use the default implementation.
27+
var body: Body { get }
28+
}
29+
30+
extension CodeEditExtension {
31+
32+
var extensionURL: URL {
33+
Bundle.main.bundleURL
34+
}
35+
36+
func gatherAvailableExtensions() -> [ExtensionKind] {
37+
var extensions: [ExtensionKind] = []
38+
39+
if self is any SettingsExtension {
40+
extensions.append(.settings)
41+
}
42+
43+
if let self = self as? any SidebarExtension {
44+
extensions.append(contentsOf: self.availableExtensions)
45+
}
46+
47+
return extensions
48+
}
49+
}
50+
51+
public extension CodeEditExtension where Self: AnyObject {
52+
/// XPC Configuration for communication with CodeEdit.
53+
/// Use the default implementation.
54+
var configuration: AppExtensionSceneConfiguration {
55+
AppExtensionSceneConfiguration(self.body, configuration: SettingsExtensionConfiguration(self))
56+
}
57+
}
58+
59+
struct SettingsExtensionConfiguration<E: CodeEditExtension & AnyObject>: AppExtensionConfiguration {
60+
public func accept(connection: NSXPCConnection) -> Bool {
61+
guard let appExtension else {
62+
return false
63+
}
64+
65+
connection.exportedInterface = .init(with: XPCWrappable.self)
66+
connection.exportedObject = XPCWrapper(appExtension)
67+
connection.resume()
68+
69+
return true
70+
}
71+
72+
weak var appExtension: E?
73+
74+
public init(_ appExtension: E) {
75+
self.appExtension = appExtension
76+
}
77+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Logging.swift
3+
//
4+
//
5+
// Created by Wouter Hennen on 22/05/2023.
6+
//
7+
8+
import Foundation
9+
10+
public func print(_ items: Any..., separator: String = " ", terminator: String = "\n") {
11+
let formedString = items.map { String(describing: $0) }.joined(separator: separator)
12+
NSLog(formedString)
13+
}

0 commit comments

Comments
 (0)