PlainApp
API 参考

应用

通过 app.capabilities 判断功能支持,通过 app.access 和宿主权限判断访问授权。示例使用合成数据,调用前请替换路径、ID、输入和筛选条件。

类型定义

graphql
type Mutation {
  clearAppCache: Boolean!
  restartHttpServer(httpPort: Int, httpsPort: Int): HttpServerState!
  relaunchApp: Boolean!
  requestAccess(feature: AccessFeature!): Boolean!
  setTempValue(key: String!, value: String!): KeyValuePair!
  updateDeviceName(name: String!): Boolean!
}

type Query {
  appCacheSize: Long!
  appUpdate: AppUpdate!
  httpServer: HttpServer!
  app: App!
}

type Subscription {
  httpServerChanged: HttpServer!
  deviceNameUpdated: String!
  accessUpdated: Boolean!
  contentChanged: Boolean!
}

enum AccessFeature {
	IMAGES
	VIDEOS
	AUDIO
	DOCS
	FILES
	CONTACTS
	SMS
	CALLS
	CALL_PHONE
	PHONE_NUMBER
	APPS
	NOTIFICATIONS
	CLIPBOARD
	ADB
}

type App {
	clientId: ID!
	httpPort: Int!
	httpsPort: Int!
	deviceName: String!
	developerMode: Boolean!
	urlToken: String!
	tlsCertificateSha256: String
	appDir: String!
	deviceType: DeviceType!
	capabilities: [Capability!]!
	buildChannel: AppChannelType!
	access: [AccessFeature!]!
	downloadsDir: String!
	debug: Boolean!
}

enum AppChannelType {
	GITHUB
	GOOGLE
	FDROID
}

type AppUpdate {
	currentVersion: String!
	latestVersion: String
	releaseName: String!
	publishedAt: Instant
	hasUpdate: Boolean!
	url: String
}

enum Capability {
	ADB
	BLE
	WIFI_AWARE
	APP_RELAUNCH
	MEDIA_TRASH
	MEDIA_DELETE
	MEDIA_MOVE
	MEDIA_FAVORITE
	APP_UPDATES
	MIRROR_AUDIO
	MEDIA_SCAN
	TELEPHONY
	PACKAGES
	SCREEN_MIRROR
	NOTIFICATIONS
	CLIPBOARD
	DISK_MANAGER
	HTTP_SERVER
}

enum DeviceType {
	COMPUTER
	PHONE
	TABLET
	TV
	NAS
	OTHER
}

type HttpServer {
	state: HttpServerState!
	addresses: [String!]!
	onlineClients: [ID!]!
	remoteAccess: Boolean!
	mdnsHostname: String!
}

type HttpServerState {
	revision: Long!
	restarting: Boolean!
	httpPort: Int!
	httpsPort: Int!
	error: String!
}

scalar Instant

type KeyValuePair {
	key: String!
	value: String!
}

scalar Long

操作

mutation

clearAppCache

删除可随时重建的应用缓存文件。

graphql
mutation clearAppCache {
  clearAppCache
}
mutation

restartHttpServer

修改 HTTP/HTTPS 端口并等待新监听器就绪。需要 HTTP_SERVER 能力。返回实际端口;若当前地址改变,请连接新端口。

graphql
mutation restartHttpServer($httpPort: Int, $httpsPort: Int) {
  restartHttpServer(httpPort: $httpPort, httpsPort: $httpsPort) { revision restarting httpPort httpsPort error }
}
query

appCacheSize

返回应用缓存占用的字节数。

graphql
query appCacheSize {
  appCacheSize
}
query

appUpdate

读取可用的应用更新信息。

graphql
query appUpdate {
  appUpdate { currentVersion latestVersion releaseName publishedAt hasUpdate url }
}
query

httpServer

查看 HTTP/HTTPS 服务状态、局域网地址、在线客户端和远程访问状态。需要已认证的调用方及 HTTP_SERVER 能力。

graphql
query httpServer {
  httpServer { addresses onlineClients remoteAccess mdnsHostname }
}
subscription

httpServerChanged

订阅接入时,以及监听器、网络、在线客户端或设置变化后,接收 HTTP 服务的当前快照。需要已认证的调用者和 HTTP_SERVER 支持。离开页面时取消订阅,返回时重新订阅。

graphql
subscription httpServerChanged {
  httpServerChanged { addresses onlineClients remoteAccess mdnsHostname }
}
subscription

deviceNameUpdated

接收更新后的设备显示名称。

graphql
subscription deviceNameUpdated {
  deviceNameUpdated
}
subscription

accessUpdated

接收设备功能授权变更信号。

graphql
subscription accessUpdated {
  accessUpdated
}
subscription

contentChanged

接收已存储内容的变更信号。

graphql
subscription contentChanged {
  contentChanged
}
mutation

relaunchApp

重启设备上的 PlainApp 进程。

graphql
# The app restarts itself; the response only acknowledges that the
# request was accepted, since the connection dies with the process.
mutation relaunchApp {
  relaunchApp
}
mutation

requestAccess

为支持的功能申请设备授权;可能需要用户在设备上操作。

graphql
mutation requestAccess($feature: AccessFeature!) {
  requestAccess(feature: $feature)
}
mutation

setTempValue

设置并返回临时内存键值对,不写入持久化 Key Value 数据。

graphql
mutation setTempValue($key: String!, $value: String!) {
  setTempValue(key: $key, value: $value) { key value }
}
mutation

updateDeviceName

修改 Web 界面显示的设备名称,并向已配对设备广播。

graphql
# Renaming the device also re-publishes the mDNS advertisement, so a
# client that waits for the new name to appear does see it.
mutation updateDeviceName($name: String!) {
  updateDeviceName(name: $name)
}
query

app

读取应用标识、配置、能力和授权信息。app.urlToken 属于当前调用会话,用于加密资源链接,不是 GraphQL 认证 token。

graphql
# Everything a client needs to reach this device: its identity, the
# port it listens on and the token that authorises it.
query app {
  app { clientId httpPort httpsPort deviceName developerMode urlToken tlsCertificateSha256 appDir }
}