Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ jobs:
uses: actions/upload-artifact@v7
with:
name: android-test-results
path: SDK/Android/*/build/reports/tests
path: |
SDK/Android/*/build/reports/tests
SDK/Plugins/*/Android/build/reports/tests
retention-days: 7

docs:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ WebBridge/dist/
SDK/Android/**/.gradle/
SDK/Android/**/.kotlin/
SDK/Android/**/build/
SDK/Plugins/**/.kotlin/
SDK/Plugins/**/build/
SDK/Android/local.properties
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ NectoMac/Sources/NectoCLIService The control socket contract shared by Necto.a
NectoMac/Sources/NectoMacService Mac providers, routing, device connections and control server
SDK/iOS/Sources/NectoSDK The SDK and listener embedded in a connected app
SDK/iOS/Tests/ SDK tests and the standalone consumer fixture
SDK/Android/ Kotlin SDK, plugin modules and sample app, built by Gradle
SDK/Android/ Kotlin bridge and sample app, built by Gradle
SDK/Plugins/<Name>/ One plugin: Panel/ is the built panel, iOS/ the Swift sources, Android/ the Gradle module
Necto/ macOS shell, built by Necto.xcodeproj
ExampleApp/ iOS sample app, built by Necto.xcodeproj
WebPackages/BuiltInPlugins/ src/ is source, Plugins/ is the committed build output
Expand Down
13 changes: 5 additions & 8 deletions NectoAppTests/NectoThemeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ struct NectoThemeTests {
@Test("Shared and shipped styles match native colors in both appearances", arguments: [false, true])
func renderedColors(isDark: Bool) async throws {
let root = URL(filePath: #filePath).deletingLastPathComponent().deletingLastPathComponent()
let sources = root.appending(path: "SDK/iOS/Sources")
let modules = try FileManager.default.contentsOfDirectory(at: sources, includingPropertiesForKeys: nil)
let panels = try modules.flatMap { module -> [URL] in
let directory = module.appending(path: "Panels")
guard FileManager.default.fileExists(atPath: directory.path) else { return [] }
return try FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: nil)
.filter { $0.hasDirectoryPath }.map { $0.appending(path: "assets/index.css") }
}
let plugins = root.appending(path: "SDK/Plugins")
let panels = try FileManager.default.contentsOfDirectory(at: plugins, includingPropertiesForKeys: nil)
.map { $0.appending(path: "Panel") }
.filter { FileManager.default.fileExists(atPath: $0.path) }
.map { $0.appending(path: "assets/index.css") }
let styles = [root.appending(path: "WebPackages/Bridge/theme.css")] + panels + [
root.appending(path: "WebPackages/BuiltInPlugins/Plugins/plugin-sample/assets/index.css"),
root.appending(path: "WebPackages/BuiltInPlugins/Plugins/shell-demo/assets/index.css"),
Expand Down
40 changes: 26 additions & 14 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,50 +33,62 @@ let package = Package(
.target(
name: "NectoNetworkPlugin",
dependencies: ["NectoModel", "NectoSDK"],
path: "SDK/iOS/Sources/NectoNetworkPlugin",
resources: [.copy("Panels")]
path: "SDK/Plugins/Network",
exclude: ["Android"],
sources: ["iOS"],
resources: [.copy("Panel")]
),
.target(
name: "NectoEventsPlugin",
dependencies: ["NectoModel", "NectoSDK"],
path: "SDK/iOS/Sources/NectoEventsPlugin",
resources: [.copy("Panels")]
path: "SDK/Plugins/Events",
exclude: ["Android"],
sources: ["iOS"],
resources: [.copy("Panel")]
),
.target(
name: "NectoFilesPlugin",
dependencies: ["NectoModel", "NectoSDK"],
path: "SDK/iOS/Sources/NectoFilesPlugin",
resources: [.copy("Panels")]
path: "SDK/Plugins/Files",
exclude: ["Android"],
sources: ["iOS"],
resources: [.copy("Panel")]
),
.target(
name: "NectoPreferencesPlugin",
dependencies: ["NectoModel", "NectoSDK"],
path: "SDK/iOS/Sources/NectoPreferencesPlugin",
resources: [.copy("Panels")]
path: "SDK/Plugins/Preferences",
exclude: ["Android"],
sources: ["iOS"],
resources: [.copy("Panel")]
),
.target(
name: "NectoPerformancePlugin",
dependencies: ["NectoModel", "NectoSDK"],
path: "SDK/iOS/Sources/NectoPerformancePlugin",
resources: [.copy("Panels")]
path: "SDK/Plugins/Performance",
exclude: ["Android"],
sources: ["iOS"],
resources: [.copy("Panel")]
),
.target(
name: "NectoUIControlPlugin",
dependencies: ["NectoModel", "NectoSDK"],
path: "SDK/iOS/Sources/NectoUIControlPlugin",
resources: [.copy("Panels")]
path: "SDK/Plugins/UIControl",
exclude: ["Android"],
sources: ["iOS"],
resources: [.copy("Panel")]
),
// CPU, memory and frame-rate capture for apps that explicitly opt in.
.target(
name: "NectoProcessMetricPlugin",
dependencies: ["NectoPerformancePlugin", "NectoModel", "NectoSDK"],
path: "SDK/iOS/Sources/NectoProcessMetricPlugin"
path: "SDK/Plugins/ProcessMetric/iOS"
),
// Capture stays separate from the reporting API and starts only on registration.
.target(
name: "NectoURLSessionCapturePlugin",
dependencies: ["NectoNetworkPlugin", "NectoModel", "NectoSDK"],
path: "SDK/iOS/Sources/NectoURLSessionCapturePlugin"
path: "SDK/Plugins/URLSessionCapture/iOS"
),
.testTarget(
name: "NectoModelTests",
Expand Down
6 changes: 3 additions & 3 deletions SDK/Android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ One session is served at a time.
still scrolls the list it starts in.
- **Panels** are packaged as Java resources: `necto/panels/<id>`, with a `files.txt`
index.
- The build generates them from the built iOS panels in
`SDK/iOS/Sources/<PluginModule>/Panels`.
- The build generates them from the built panel beside each module,
`SDK/Plugins/<Name>/Panel`, the same directory the Swift package copies.
- It overrides only the Control and Preferences manifests, which describe Android
behaviour. They live in each owning plugin's `src/main/panel-manifests`, and the build fails
when their contracts drift from the iOS ones.
when their contracts drift from the panel's own.
- **Requests from Necto** are bounded by the 64 KiB inbound frame, which reaches
`files.write` and `preferences.set` with a large string. A larger request closes
the session, the request fails with `PROVIDER_FAILED`, and Necto reconnects within a
Expand Down
53 changes: 24 additions & 29 deletions SDK/Android/buildSrc/src/main/kotlin/NectoPanelResources.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import groovy.json.JsonSlurper
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.PathSensitive
Expand All @@ -18,22 +15,23 @@ import org.gradle.api.tasks.TaskAction
import java.io.File

/**
* Packages built web panels as Java resources under [root]/<id>, each with a files.txt
* Packages a built web panel as Java resources under [root]/[id], with a files.txt
* index, because resource folders cannot be listed at run time (an APK is not a
* directory).
*
* Panels are read from the repository's built output, so Android carries the same panel
* code as iOS. A manifest in [manifests] named <id>.json replaces the panel's own, for
* wording that differs on Android; it must declare the same operations, so a contract
* cannot drift from the panel it rides with.
* The panel is read from the repository's built output, the same directory the Swift
* package copies, so Android carries the same panel code as iOS. A manifest in
* [manifests] named <id>.json replaces the panel's own, for wording that differs on
* Android; it must declare the same operations, so a contract cannot drift from the
* panel it rides with.
*/
abstract class NectoPanelResources : DefaultTask() {
@get:InputFiles
@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val panels: ConfigurableFileCollection
abstract val panel: DirectoryProperty

@get:Input
abstract val ids: ListProperty<String>
abstract val id: Property<String>

@get:InputDirectory
@get:PathSensitive(PathSensitivity.RELATIVE)
Expand All @@ -48,27 +46,24 @@ abstract class NectoPanelResources : DefaultTask() {

@TaskAction
fun generate() {
val destinationRoot = output.get().asFile.resolve(root.get())
val id = id.get()
val panel = panel.get().asFile
if (!panel.resolve("manifest.json").isFile) throw GradleException("No built panel at $panel")
output.get().asFile.deleteRecursively()
for (id in ids.get()) {
val panel = panels.files.singleOrNull { it.name == id }
?: throw GradleException("Expected one built panel for $id")
if (!panel.resolve("manifest.json").isFile) throw GradleException("No built panel at $panel")
val destination = destinationRoot.resolve(id)
val paths = panel.walkTopDown()
.filter { it.isFile && !it.name.startsWith(".") }
.map { it.relativeTo(panel).invariantSeparatorsPath }
.sorted()
.toList()
paths.forEach { path -> panel.resolve(path).copyTo(destination.resolve(path)) }
manifests.orNull?.asFile?.resolve("$id.json")?.takeIf { it.isFile }?.let { override ->
if (contract(override) != contract(panel.resolve("manifest.json"))) {
throw GradleException("$override must declare the same operations as $panel/manifest.json")
}
override.copyTo(destination.resolve("manifest.json"), overwrite = true)
val destination = output.get().asFile.resolve(root.get()).resolve(id)
val paths = panel.walkTopDown()
.filter { it.isFile && !it.name.startsWith(".") }
.map { it.relativeTo(panel).invariantSeparatorsPath }
.sorted()
.toList()
paths.forEach { path -> panel.resolve(path).copyTo(destination.resolve(path)) }
manifests.orNull?.asFile?.resolve("$id.json")?.takeIf { it.isFile }?.let { override ->
if (contract(override) != contract(panel.resolve("manifest.json"))) {
throw GradleException("$override must declare the same operations as $panel/manifest.json")
}
destination.resolve("files.txt").writeText(paths.joinToString("\n", postfix = "\n"))
override.copyTo(destination.resolve("manifest.json"), overwrite = true)
}
destination.resolve("files.txt").writeText(paths.joinToString("\n", postfix = "\n"))
}

/** Which operations a manifest declares and how they bind; wording and schemas may differ. */
Expand Down
4 changes: 2 additions & 2 deletions SDK/Android/sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ kotlin {

// Built from WebPackages/BuiltInPlugins: the same plugin-sample panel ExampleApp carries.
val generatePanelResources by tasks.registering(NectoPanelResources::class) {
panels.from(rootProject.layout.projectDirectory.dir("../../WebPackages/BuiltInPlugins/Plugins/plugin-sample"))
ids.set(listOf("plugin-sample"))
panel.set(rootProject.layout.projectDirectory.dir("../../WebPackages/BuiltInPlugins/Plugins/plugin-sample"))
id.set("plugin-sample")
root.set("panels")
output.set(layout.buildDirectory.dir("generated/panelResources"))
}
Expand Down
14 changes: 14 additions & 0 deletions SDK/Android/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ include(":necto-core", ":necto-plugin-support", ":necto-events-plugin", ":necto-
if (providers.gradleProperty("necto.skipAndroid").orNull != "true") {
include(":necto-android", ":necto-files-plugin", ":necto-ui-control-plugin", ":necto-process-metric-plugin", ":necto-datastore-preferences-plugin", ":sample")
}

// A plugin lives beside its panel and its iOS counterpart, in SDK/Plugins/<Name>/Android.
mapOf(
"necto-events-plugin" to "Events",
"necto-network-plugin" to "Network",
"necto-okhttp-capture-plugin" to "OkHttpCapture",
"necto-files-plugin" to "Files",
"necto-performance-plugin" to "Performance",
"necto-process-metric-plugin" to "ProcessMetric",
"necto-ui-control-plugin" to "UIControl",
"necto-datastore-preferences-plugin" to "Preferences",
).forEach { (name, plugin) ->
findProject(":$name")?.projectDir = file("../Plugins/$plugin/Android")
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ tasks.test {
}

val generatePanelResources by tasks.registering(NectoPanelResources::class) {
panels.from(rootProject.fileTree("../iOS/Sources") {
include("*/Panels/event-log/manifest.json")
}.files.map { it.parentFile })
ids.set(listOf("event-log"))
panel.set(layout.projectDirectory.dir("../Panel"))
id.set("event-log")
root.set("necto/panels")
output.set(layout.buildDirectory.dir("generated/panelResources"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public final class NectoEventsPlugin: NectoPlugin, NectoEventReporting, @uncheck

public let id = "event-log"

public var panel: NectoPluginPanel? { NectoPluginPanel(bundle: .module, subdirectory: "Panels/event-log") }
public var panel: NectoPluginPanel? { NectoPluginPanel(bundle: .module) }


private let lock = NSLock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ dependencies {
}

val generatePanelResources by tasks.registering(NectoPanelResources::class) {
panels.from(rootProject.fileTree("../iOS/Sources") {
include("*/Panels/files/manifest.json")
}.files.map { it.parentFile })
ids.set(listOf("files"))
panel.set(layout.projectDirectory.dir("../Panel"))
id.set("files")
root.set("necto/panels")
output.set(layout.buildDirectory.dir("generated/panelResources"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public final class NectoFilesPlugin: NectoPlugin, @unchecked Sendable {

public let id = "files"

public var panel: NectoPluginPanel? { NectoPluginPanel(bundle: .module, subdirectory: "Panels/files") }
public var panel: NectoPluginPanel? { NectoPluginPanel(bundle: .module) }

private let roots: [Root]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ tasks.test {
}

val generatePanelResources by tasks.registering(NectoPanelResources::class) {
panels.from(rootProject.fileTree("../iOS/Sources") {
include("*/Panels/network-logger/manifest.json")
}.files.map { it.parentFile })
ids.set(listOf("network-logger"))
panel.set(layout.projectDirectory.dir("../Panel"))
id.set("network-logger")
root.set("necto/panels")
output.set(layout.buildDirectory.dir("generated/panelResources"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class NectoNetworkPlugin: NectoPlugin, NectoNetworkReporting, @unch

public let id = "network-logger"

public var panel: NectoPluginPanel? { NectoPluginPanel(bundle: .module, subdirectory: "Panels/network-logger") }
public var panel: NectoPluginPanel? { NectoPluginPanel(bundle: .module) }


private let lock = NSLock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ tasks.test {
}

val generatePanelResources by tasks.registering(NectoPanelResources::class) {
panels.from(rootProject.fileTree("../iOS/Sources") {
include("*/Panels/performance-monitor/manifest.json")
}.files.map { it.parentFile })
ids.set(listOf("performance-monitor"))
panel.set(layout.projectDirectory.dir("../Panel"))
id.set("performance-monitor")
root.set("necto/panels")
output.set(layout.buildDirectory.dir("generated/panelResources"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public final class NectoPerformancePlugin: NectoPlugin, NectoPerformanceReportin

public let id = "performance-monitor"

public var panel: NectoPluginPanel? { NectoPluginPanel(bundle: .module, subdirectory: "Panels/performance-monitor") }
public var panel: NectoPluginPanel? { NectoPluginPanel(bundle: .module) }

private let metrics: [NectoMetric]
private let sampler: (any NectoPerformanceSampling)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ dependencies {
}

val generatePanelResources by tasks.registering(NectoPanelResources::class) {
panels.from(rootProject.fileTree("../iOS/Sources") {
include("*/Panels/preferences/manifest.json")
}.files.map { it.parentFile })
ids.set(listOf("preferences"))
panel.set(layout.projectDirectory.dir("../Panel"))
id.set("preferences")
manifests.set(layout.projectDirectory.dir("src/main/panel-manifests"))
root.set("necto/panels")
output.set(layout.buildDirectory.dir("generated/panelResources"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class NectoPreferencesPlugin: NectoPlugin, @unchecked Sendable {

public let id = "preferences"

public var panel: NectoPluginPanel? { NectoPluginPanel(bundle: .module, subdirectory: "Panels/preferences") }
public var panel: NectoPluginPanel? { NectoPluginPanel(bundle: .module) }


/// Named stores this plugin will open, beyond `standard`. An app that keeps its
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ dependencies {
}

val generatePanelResources by tasks.registering(NectoPanelResources::class) {
panels.from(rootProject.fileTree("../iOS/Sources") {
include("*/Panels/control/manifest.json")
}.files.map { it.parentFile })
ids.set(listOf("control"))
panel.set(layout.projectDirectory.dir("../Panel"))
id.set("control")
manifests.set(layout.projectDirectory.dir("src/main/panel-manifests"))
root.set("necto/panels")
output.set(layout.buildDirectory.dir("generated/panelResources"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public struct NectoControlTarget: Sendable {
/// UIKit support is included; other UI implementations can supply the same contract.
public final class NectoUIControlPlugin: NectoPlugin, @unchecked Sendable {
public let id = "control"
public var panel: NectoPluginPanel? { NectoPluginPanel(bundle: .module, subdirectory: "Panels/control") }
public var panel: NectoPluginPanel? { NectoPluginPanel(bundle: .module) }

private let actionTargets: @Sendable () async -> [NectoControlTarget]
private let readAccessibility: @Sendable () async -> [NectoAccessibilityItem]
Expand Down
2 changes: 1 addition & 1 deletion WebPackages/BuiltInPlugins/src/control/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { defineConfig } from "vite";
export default defineConfig({
base: "./",
build: {
outDir: "../../../../SDK/iOS/Sources/NectoUIControlPlugin/Panels/control",
outDir: "../../../../SDK/Plugins/UIControl/Panel",
emptyOutDir: true,
rollupOptions: {
output: {
Expand Down
Loading
Loading