@krate/app 0.0.0-stage → 0.5.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +88 -2
- package/dist/automation.d.ts +11 -0
- package/dist/automation.d.ts.map +1 -0
- package/dist/automation.js +27 -0
- package/dist/badge.d.ts +13 -0
- package/dist/badge.d.ts.map +1 -0
- package/dist/badge.js +34 -0
- package/dist/chrome.d.ts +90 -0
- package/dist/chrome.d.ts.map +1 -0
- package/dist/chrome.js +133 -0
- package/dist/client.d.ts +26 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +545 -0
- package/dist/clipboard.d.ts +19 -0
- package/dist/clipboard.d.ts.map +1 -0
- package/dist/clipboard.js +51 -0
- package/dist/cookies.d.ts +44 -0
- package/dist/cookies.d.ts.map +1 -0
- package/dist/cookies.js +45 -0
- package/dist/crash.d.ts +35 -0
- package/dist/crash.d.ts.map +1 -0
- package/dist/crash.js +28 -0
- package/dist/db.d.ts +14 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +23 -0
- package/dist/dialog.d.ts +36 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +23 -0
- package/dist/downloads.d.ts +35 -0
- package/dist/downloads.d.ts.map +1 -0
- package/dist/downloads.js +30 -0
- package/dist/driver.d.ts +190 -0
- package/dist/driver.d.ts.map +1 -0
- package/dist/driver.js +637 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +11 -0
- package/dist/events.d.ts +6 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +47 -0
- package/dist/extension.d.ts +10 -0
- package/dist/extension.d.ts.map +1 -0
- package/dist/extension.js +25 -0
- package/dist/fakehost.d.ts +18 -0
- package/dist/fakehost.d.ts.map +1 -0
- package/dist/fakehost.js +199 -0
- package/dist/fs.d.ts +26 -0
- package/dist/fs.d.ts.map +1 -0
- package/dist/fs.js +38 -0
- package/dist/host.d.ts +4 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +25 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/kv.d.ts +6 -0
- package/dist/kv.d.ts.map +1 -0
- package/dist/kv.js +19 -0
- package/dist/lifecycle.d.ts +22 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +85 -0
- package/dist/login.d.ts +10 -0
- package/dist/login.d.ts.map +1 -0
- package/dist/login.js +8 -0
- package/dist/media.d.ts +50 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +70 -0
- package/dist/menu.d.ts +71 -0
- package/dist/menu.d.ts.map +1 -0
- package/dist/menu.js +114 -0
- package/dist/mock.d.ts +14 -0
- package/dist/mock.d.ts.map +1 -0
- package/dist/mock.js +47 -0
- package/dist/notify.d.ts +25 -0
- package/dist/notify.d.ts.map +1 -0
- package/dist/notify.js +32 -0
- package/dist/offscreen.d.ts +24 -0
- package/dist/offscreen.d.ts.map +1 -0
- package/dist/offscreen.js +27 -0
- package/dist/os.d.ts +20 -0
- package/dist/os.d.ts.map +1 -0
- package/dist/os.js +43 -0
- package/dist/page.d.ts +69 -0
- package/dist/page.d.ts.map +1 -0
- package/dist/page.js +61 -0
- package/dist/permission.d.ts +5 -0
- package/dist/permission.d.ts.map +1 -0
- package/dist/permission.js +18 -0
- package/dist/port.d.ts +35 -0
- package/dist/port.d.ts.map +1 -0
- package/dist/port.js +159 -0
- package/dist/power.d.ts +19 -0
- package/dist/power.d.ts.map +1 -0
- package/dist/power.js +35 -0
- package/dist/remote.d.ts +156 -0
- package/dist/remote.d.ts.map +1 -0
- package/dist/remote.js +115 -0
- package/dist/screen.d.ts +25 -0
- package/dist/screen.d.ts.map +1 -0
- package/dist/screen.js +23 -0
- package/dist/shortcut.d.ts +2 -0
- package/dist/shortcut.d.ts.map +1 -0
- package/dist/shortcut.js +44 -0
- package/dist/testing.d.ts +6 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +9 -0
- package/dist/theme.d.ts +12 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +13 -0
- package/dist/tray.d.ts +18 -0
- package/dist/tray.d.ts.map +1 -0
- package/dist/tray.js +23 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/updater.d.ts +36 -0
- package/dist/updater.d.ts.map +1 -0
- package/dist/updater.js +58 -0
- package/dist/window.d.ts +154 -0
- package/dist/window.d.ts.map +1 -0
- package/dist/window.js +205 -0
- package/dist/wire.d.ts +26 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +328 -0
- package/dist/worker-host.d.ts +6 -0
- package/dist/worker-host.d.ts.map +1 -0
- package/dist/worker-host.js +36 -0
- package/dist/worker.d.ts +62 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +86 -0
- package/package.json +188 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 kratejs
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,89 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @krate/app
|
|
2
|
+
|
|
3
|
+
Client runtime and host bindings for Krate desktop apps. UI code (TSX in the
|
|
4
|
+
system webview) imports host functions; the compiler rewrites those imports into
|
|
5
|
+
calls into this package. See `packages/native/PROTOCOL.md` for the wire format.
|
|
6
|
+
|
|
7
|
+
- `@krate/app`: `call`, `stream`, `hostSignal.signal(name)`, `KrateError`, `app`.
|
|
8
|
+
- `@krate/app/client`: `createClient({ fetch?, origin?, windowId?, createSignal? })`,
|
|
9
|
+
the transport used by generated stubs.
|
|
10
|
+
- `@krate/app/host`: `hostSignal(initial)` for host-side TS code.
|
|
11
|
+
- `@krate/app/testing`: `mockHost(moduleId, impl)`, `resetHostMocks()`,
|
|
12
|
+
`createFakeHost(registry)` (an in-memory fetch speaking the protocol).
|
|
13
|
+
- `@krate/app/driver` (Node only): `launch()` starts the real app under
|
|
14
|
+
`krate native test` and drives its pages, host calls and native events; see
|
|
15
|
+
docs/native/testing.
|
|
16
|
+
|
|
17
|
+
## Signals
|
|
18
|
+
|
|
19
|
+
`signal(name)` returns a callable getter (`Count()`) with `.subscribe(fn)`. The
|
|
20
|
+
value is `undefined` until the first frame arrives. To make reads reactive,
|
|
21
|
+
pass the runtime's factory once at startup:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { createSignal } from "@krate/runtime";
|
|
25
|
+
import { createClient, setClient } from "@krate/app";
|
|
26
|
+
setClient(createClient({ createSignal }));
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`@krate/runtime` is not imported by this package, so there is no dependency
|
|
30
|
+
cycle and no hard dependency.
|
|
31
|
+
|
|
32
|
+
## Codec notes
|
|
33
|
+
|
|
34
|
+
The wire format, including the escape rule for all four tags (`$b`, `$d`, `$m`,
|
|
35
|
+
`$s`), is specified in `packages/native/PROTOCOL.md`; `src/wire.ts` implements
|
|
36
|
+
it. The golden vectors in `packages/native/wire/testdata` are shared with the Go
|
|
37
|
+
codec and run by `test/shared-vectors.test.ts`. A Go `map` arrives as a plain
|
|
38
|
+
object, not a `Map`; a `Map` or `Set` argument is accepted by Go as an object
|
|
39
|
+
(string keys) / array. Calls with binary arguments are never deduplicated.
|
|
40
|
+
|
|
41
|
+
## SDK modules
|
|
42
|
+
|
|
43
|
+
These wrap the Go SDK (`packages/native/sdk`). Each call is a host id
|
|
44
|
+
`krate/<area>.<name>`; `packages/native/sdk/ids.go` lists every id with its
|
|
45
|
+
permission and types, and a Go test checks these files against it. The app's
|
|
46
|
+
`permissions` list in `app.json` decides which ids work; a call without its
|
|
47
|
+
permission rejects with `KrateError` code `permission_denied` and
|
|
48
|
+
`data.permission`. See the docs page "Native SDK: data" for the tables.
|
|
49
|
+
|
|
50
|
+
- `@krate/app/os`: `appDataDir`, `cacheDir`, `configDir`, `logDir`, `tempDir`,
|
|
51
|
+
`info`, `openExternal`, `secretSet`, `secretGet`, `secretDelete`.
|
|
52
|
+
- `@krate/app/fs`: `readFile`, `readText`, `readDir`, `stat`, `exists`,
|
|
53
|
+
`writeFile`, `writeText`, `mkdir`, `remove`, `rename` (scoped to the app
|
|
54
|
+
directories and paths the user granted in a dialog).
|
|
55
|
+
- `@krate/app/db`: `query`, `exec`, `transaction` on the app's SQLite database.
|
|
56
|
+
- `@krate/app/kv`: `get`, `set`, `delete`, `keys`.
|
|
57
|
+
- `@krate/app/permission`: `query`, `isPermissionDenied`, `deniedPermission`.
|
|
58
|
+
|
|
59
|
+
## Desktop SDK (UI half)
|
|
60
|
+
|
|
61
|
+
`@krate/app/updater` (`check`, `download`, `apply`, `relaunch`, `update`) needs the
|
|
62
|
+
`updater` permission and `native.updater` in the config.
|
|
63
|
+
|
|
64
|
+
`@krate/app/window`, `/dialog`, `/clipboard`, `/menu`, `/tray`, `/shortcut`,
|
|
65
|
+
`/notify` and `/app` call the host functions `krate/<area>.<Name>` and subscribe
|
|
66
|
+
to the streams `krate/<area>.events` (`onMenu(id, fn)`, `onClick`, `onEvent`,
|
|
67
|
+
`onCloseRequested`, `onAction`, `onSecondInstance`). Each id is gated by the
|
|
68
|
+
same `permissions` list as the data modules (a missing permission rejects with
|
|
69
|
+
`permission_denied`; `tray`, `shortcut` and `clipboard:read` are off unless
|
|
70
|
+
listed); see the SDK pages in the Native docs.
|
|
71
|
+
|
|
72
|
+
`@krate/app/chrome` controls window chrome: title bar styles, backdrops and vibrancy, the
|
|
73
|
+
Windows caption buttons, traffic lights, document state, sheets, native tabs, thumbnail buttons,
|
|
74
|
+
jump lists, the share menu and the dock. Calls a platform lacks reject with `unsupported`; see
|
|
75
|
+
the Window chrome page in the Native docs.
|
|
76
|
+
|
|
77
|
+
`@krate/app/page` (print, `printToPdf`, `find`, `zoom`, `setZoom`, `capture`),
|
|
78
|
+
`/downloads` (`configure`, `list`, `cancel`, `onEvent`, `onDone`) and `/cookies`
|
|
79
|
+
(`list`, `get`, `set`, `delete`, `clearSiteData`) control the web contents of a view, the
|
|
80
|
+
downloads the page starts and the cookies; they need the `page`, `downloads` and
|
|
81
|
+
`cookies` permissions (off unless listed or derived). See [Web
|
|
82
|
+
contents](https://krate.js.org/docs/native/webcontents/).
|
|
83
|
+
|
|
84
|
+
`@krate/app/window` also splits a window into several webviews: `main().addView({ path,
|
|
85
|
+
side, size, minWidth, permissions })` returns a `View` (`remove`, `focus`, `navigate`,
|
|
86
|
+
`post`), `window.setLayout(split(...))` and `window.layout()` set and read the pane
|
|
87
|
+
tree, `onViewEvent` reports added, navigated, removed and closed views, and
|
|
88
|
+
`onViewMessage` receives what another view `post`ed. See the Views page of the Native docs.
|
|
2
89
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface AutomationEndpoint {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
kind: "cdp" | "webkit-inspector" | "safari" | "";
|
|
4
|
+
url: string;
|
|
5
|
+
port: number;
|
|
6
|
+
cdp: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function automationEndpoint(): Promise<AutomationEndpoint>;
|
|
9
|
+
export declare function cdp<T = unknown>(method: string, params?: Record<string, unknown>, view?: string): Promise<T>;
|
|
10
|
+
export declare function cdpEvents<T = unknown>(event: string, view?: string, signal?: AbortSignal): AsyncIterable<T>;
|
|
11
|
+
//# sourceMappingURL=automation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"automation.d.ts","sourceRoot":"","sources":["../src/automation.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,kBAAkB;IAEjC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,KAAK,GAAG,kBAAkB,GAAG,QAAQ,GAAG,EAAE,CAAC;IAEjD,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IAEb,GAAG,EAAE,OAAO,CAAC;CACd;AAED,wBAAgB,kBAAkB,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAEhE;AAKD,wBAAgB,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EAAE,IAAI,SAAK,GAAG,OAAO,CAAC,CAAC,CAAC,CAE5G;AAKD,wBAAgB,SAAS,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,SAAK,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC,CAAC,CAAC,CAEvG"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// The remote debugging endpoint and DevTools protocol commands, for tests and
|
|
2
|
+
// debugging sessions. Needs the "automation" permission, and works only when
|
|
3
|
+
// the app runs in dev or was built with native.debug.
|
|
4
|
+
//
|
|
5
|
+
// WebView2 (Windows) speaks the Chrome DevTools Protocol: Playwright attaches
|
|
6
|
+
// with chromium.connectOverCDP(endpoint.url) and Puppeteer with
|
|
7
|
+
// puppeteer.connect({ browserURL: endpoint.url }), and cdp() sends one method
|
|
8
|
+
// in process. WebKitGTK (Linux) serves the WebKit remote inspector over HTTP:
|
|
9
|
+
// a browser can open it, Playwright and Puppeteer cannot drive it, and cdp()
|
|
10
|
+
// rejects with code "unsupported". WKWebView (macOS) is inspectable from
|
|
11
|
+
// Safari's Develop menu and has no network endpoint.
|
|
12
|
+
import { call, stream } from "./index.js";
|
|
13
|
+
export function automationEndpoint() {
|
|
14
|
+
return call("krate/automation.endpoint", []);
|
|
15
|
+
}
|
|
16
|
+
// cdp runs a DevTools protocol method, for example
|
|
17
|
+
// cdp("Page.captureScreenshot", { format: "png" }), in a window or view
|
|
18
|
+
// ("" is the main window) and resolves to the method's result object.
|
|
19
|
+
export function cdp(method, params = {}, view = "") {
|
|
20
|
+
return call("krate/automation.cdp", [method, params, view]);
|
|
21
|
+
}
|
|
22
|
+
// cdpEvents yields the parameters of each protocol event with this name, for
|
|
23
|
+
// example cdpEvents("Page.loadEventFired"), until the loop is left or the
|
|
24
|
+
// signal aborts.
|
|
25
|
+
export function cdpEvents(event, view = "", signal) {
|
|
26
|
+
return stream("krate/automation.cdpEvents", [event, view], { signal });
|
|
27
|
+
}
|
package/dist/badge.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type ProgressState = "none" | "normal" | "indeterminate" | "error" | "paused";
|
|
2
|
+
export interface BadgeProgress {
|
|
3
|
+
state: ProgressState;
|
|
4
|
+
value: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function setBadge(badge: string | number | null): Promise<void>;
|
|
7
|
+
export declare function clearBadge(): Promise<void>;
|
|
8
|
+
export declare function getBadge(): Promise<string>;
|
|
9
|
+
export declare function setProgress(state: ProgressState, value?: number): Promise<void>;
|
|
10
|
+
export declare function clearProgress(): Promise<void>;
|
|
11
|
+
export declare function getProgress(): Promise<BadgeProgress>;
|
|
12
|
+
export declare function setUrgent(on: boolean): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=badge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"badge.d.ts","sourceRoot":"","sources":["../src/badge.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,eAAe,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErF,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,aAAa,CAAC;IAErB,KAAK,EAAE,MAAM,CAAC;CACf;AAKD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAGrE;AAED,wBAAgB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1C;AAGD,wBAAgB,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,CAE1C;AAKD,wBAAgB,WAAW,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,SAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1E;AAED,wBAAgB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAE7C;AAED,wBAAgB,WAAW,IAAI,OAAO,CAAC,aAAa,CAAC,CAEpD;AAID,wBAAgB,SAAS,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAEpD"}
|
package/dist/badge.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Badge and progress on the app icon (dock, taskbar, launcher).
|
|
2
|
+
// Needs the "badge" permission.
|
|
3
|
+
import { call } from "./index.js";
|
|
4
|
+
// set shows a count or short text on the app icon; "", 0 or null removes it.
|
|
5
|
+
// Linux launchers can only show numbers and reject other text with code
|
|
6
|
+
// "unsupported". Windows shows up to two or three glyphs ("99+" above 99).
|
|
7
|
+
export function setBadge(badge) {
|
|
8
|
+
const text = badge === null || badge === 0 ? "" : String(badge);
|
|
9
|
+
return call("krate/badge.set", [text]);
|
|
10
|
+
}
|
|
11
|
+
export function clearBadge() {
|
|
12
|
+
return setBadge("");
|
|
13
|
+
}
|
|
14
|
+
// get resolves the text last set, "" when none.
|
|
15
|
+
export function getBadge() {
|
|
16
|
+
return call("krate/badge.get", []);
|
|
17
|
+
}
|
|
18
|
+
// setProgress shows progress. value is 0..1 for "normal", "error" and
|
|
19
|
+
// "paused"; macOS draws error and paused like normal, Linux launchers show
|
|
20
|
+
// every determinate state as a plain bar.
|
|
21
|
+
export function setProgress(state, value = 0) {
|
|
22
|
+
return call("krate/badge.setProgress", [state, value]);
|
|
23
|
+
}
|
|
24
|
+
export function clearProgress() {
|
|
25
|
+
return setProgress("none");
|
|
26
|
+
}
|
|
27
|
+
export function getProgress() {
|
|
28
|
+
return call("krate/badge.progress", []);
|
|
29
|
+
}
|
|
30
|
+
// setUrgent bounces the dock icon, flashes the taskbar button or marks the
|
|
31
|
+
// launcher entry urgent. false cancels it.
|
|
32
|
+
export function setUrgent(on) {
|
|
33
|
+
return call("krate/badge.setUrgent", [on]);
|
|
34
|
+
}
|
package/dist/chrome.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type SubscribeOptions } from "./events.js";
|
|
2
|
+
export type TitleBarStyle = "native" | "hidden" | "none";
|
|
3
|
+
export type Backdrop = "none" | "mica" | "micaAlt" | "acrylic";
|
|
4
|
+
export type Vibrancy = "titlebar" | "selection" | "menu" | "popover" | "sidebar" | "headerView" | "sheet" | "windowBackground" | "hudWindow" | "fullScreenUI" | "tooltip" | "contentBackground" | "underWindowBackground" | "underPageBackground";
|
|
5
|
+
export type TabbingMode = "auto" | "preferred" | "disallowed";
|
|
6
|
+
export type ActivationPolicy = "regular" | "accessory" | "prohibited";
|
|
7
|
+
export interface TitleBarOverlay {
|
|
8
|
+
color?: string;
|
|
9
|
+
symbolColor?: string;
|
|
10
|
+
height?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ChromeState {
|
|
13
|
+
titleBar: TitleBarStyle;
|
|
14
|
+
transparent: boolean;
|
|
15
|
+
backdrop: string;
|
|
16
|
+
vibrancy: string;
|
|
17
|
+
overlay: TitleBarOverlay | null;
|
|
18
|
+
trafficLight: {
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
} | null;
|
|
22
|
+
documentEdited: boolean;
|
|
23
|
+
representedFile: string;
|
|
24
|
+
tabbingId: string;
|
|
25
|
+
tabbingMode: string;
|
|
26
|
+
tabs: number;
|
|
27
|
+
sheet: boolean;
|
|
28
|
+
thumbButtons: number;
|
|
29
|
+
nativeRegions: boolean;
|
|
30
|
+
features: string[];
|
|
31
|
+
}
|
|
32
|
+
export interface ThumbButton {
|
|
33
|
+
id: string;
|
|
34
|
+
tooltip?: string;
|
|
35
|
+
icon?: Uint8Array;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
hidden?: boolean;
|
|
38
|
+
dismissOnClick?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface JumpTask {
|
|
41
|
+
title: string;
|
|
42
|
+
args?: string[];
|
|
43
|
+
description?: string;
|
|
44
|
+
iconPath?: string;
|
|
45
|
+
iconIndex?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface ShareItems {
|
|
48
|
+
text?: string;
|
|
49
|
+
urls?: string[];
|
|
50
|
+
files?: string[];
|
|
51
|
+
}
|
|
52
|
+
export type ChromeEventKind = "new-tab" | "tabs-changed" | "thumb-click" | "sheet-ended";
|
|
53
|
+
export interface ChromeEvent {
|
|
54
|
+
window: string;
|
|
55
|
+
kind: ChromeEventKind;
|
|
56
|
+
id: string;
|
|
57
|
+
}
|
|
58
|
+
export declare class ChromeWindow {
|
|
59
|
+
readonly id: string;
|
|
60
|
+
constructor(id: string);
|
|
61
|
+
private cmd;
|
|
62
|
+
state(): Promise<ChromeState>;
|
|
63
|
+
setTitleBar(style: TitleBarStyle): Promise<void>;
|
|
64
|
+
setBackdrop(name: Backdrop): Promise<void>;
|
|
65
|
+
setVibrancy(material: Vibrancy | ""): Promise<void>;
|
|
66
|
+
setTitleBarOverlay(overlay: TitleBarOverlay | null): Promise<void>;
|
|
67
|
+
setTrafficLightPosition(x: number, y: number): Promise<void>;
|
|
68
|
+
startDrag(): Promise<void>;
|
|
69
|
+
toggleMaximize(): Promise<void>;
|
|
70
|
+
setDocumentEdited(on: boolean): Promise<void>;
|
|
71
|
+
setRepresentedFile(path: string): Promise<void>;
|
|
72
|
+
attachSheet(child: string | ChromeWindow): Promise<void>;
|
|
73
|
+
endSheet(): Promise<void>;
|
|
74
|
+
setTabbing(identifier: string, mode?: TabbingMode): Promise<void>;
|
|
75
|
+
mergeAllWindows(): Promise<void>;
|
|
76
|
+
moveTabToNewWindow(): Promise<void>;
|
|
77
|
+
tabs(): Promise<string[]>;
|
|
78
|
+
setThumbButtons(buttons: ThumbButton[]): Promise<void>;
|
|
79
|
+
onNewTab(fn: () => void, opts?: SubscribeOptions): () => void;
|
|
80
|
+
onThumbClick(fn: (id: string) => void, opts?: SubscribeOptions): () => void;
|
|
81
|
+
}
|
|
82
|
+
export declare function mainChrome(): ChromeWindow;
|
|
83
|
+
export declare function getChrome(id: string): ChromeWindow;
|
|
84
|
+
export declare function share(window: string | ChromeWindow, items: ShareItems): Promise<void>;
|
|
85
|
+
export declare function setJumpList(tasks: JumpTask[]): Promise<void>;
|
|
86
|
+
export declare function clearJumpList(): Promise<void>;
|
|
87
|
+
export declare function setActivationPolicy(policy: ActivationPolicy): Promise<void>;
|
|
88
|
+
export declare function setDockVisible(on: boolean): Promise<void>;
|
|
89
|
+
export declare function onChromeEvent(fn: (e: ChromeEvent) => void, opts?: SubscribeOptions): () => void;
|
|
90
|
+
//# sourceMappingURL=chrome.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chrome.d.ts","sourceRoot":"","sources":["../src/chrome.ts"],"names":[],"mappings":"AAaA,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/D,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AACzD,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;AAC/D,MAAM,MAAM,QAAQ,GAChB,UAAU,GACV,WAAW,GACX,MAAM,GACN,SAAS,GACT,SAAS,GACT,YAAY,GACZ,OAAO,GACP,kBAAkB,GAClB,WAAW,GACX,cAAc,GACd,SAAS,GACT,mBAAmB,GACnB,uBAAuB,GACvB,qBAAqB,CAAC;AAC1B,MAAM,MAAM,WAAW,G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;IAK7D,YAAY,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,IAAI;CAK5E;AAKD,wBAAgB,UAAU,IAAI,YAAY,CAEzC;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,YAAY,CAElD;AAID,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAGrF;AAGD,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAK5D;AAED,wBAAgB,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAE7C;AAGD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAE3E;AAGD,wBAAgB,cAAc,CAAC,EAAE,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAEzD;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,WAAW,KAAK,IAAI,EAAE,IAAI,CAAC,EAAE,gBAAgB,GAAG,MAAM,IAAI,CAE/F"}
|
package/dist/chrome.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Window chrome: title bar styles and drag regions, backdrops and vibrancy,
|
|
2
|
+
// the caption buttons over a hidden title bar, traffic lights, document
|
|
3
|
+
// state, sheets, native tabs, taskbar thumbnail buttons and jump lists, the
|
|
4
|
+
// share menu and the dock. Window operations need the "window" permission,
|
|
5
|
+
// jump lists and the dock "app", and the share menu "share".
|
|
6
|
+
//
|
|
7
|
+
// Most of it belongs to one platform. An operation the platform lacks rejects
|
|
8
|
+
// with code "unsupported"; ask first with app.supports("chrome:<feature>").
|
|
9
|
+
//
|
|
10
|
+
// Drag regions are marked in the page: add the data-krate-drag attribute to
|
|
11
|
+
// an element, or the CSS property -webkit-app-region (or app-region) with the
|
|
12
|
+
// value drag. no-drag (data-krate-drag="false") keeps a part clickable.
|
|
13
|
+
import { call } from "./index.js";
|
|
14
|
+
import { subscribe } from "./events.js";
|
|
15
|
+
// ChromeWindow controls the chrome of one window by its id.
|
|
16
|
+
export class ChromeWindow {
|
|
17
|
+
constructor(id) {
|
|
18
|
+
this.id = id;
|
|
19
|
+
}
|
|
20
|
+
cmd(name, ...args) {
|
|
21
|
+
return call(`krate/chrome.${name}`, [this.id, ...args]);
|
|
22
|
+
}
|
|
23
|
+
state() {
|
|
24
|
+
return call("krate/chrome.state", [this.id]);
|
|
25
|
+
}
|
|
26
|
+
setTitleBar(style) {
|
|
27
|
+
return this.cmd("setTitleBar", style);
|
|
28
|
+
}
|
|
29
|
+
// Windows 11 system backdrop. Leave the page background transparent for it
|
|
30
|
+
// to show.
|
|
31
|
+
setBackdrop(name) {
|
|
32
|
+
return this.cmd("setBackdrop", name);
|
|
33
|
+
}
|
|
34
|
+
// macOS vibrancy material behind the page; "" removes it.
|
|
35
|
+
setVibrancy(material) {
|
|
36
|
+
return this.cmd("setVibrancy", material);
|
|
37
|
+
}
|
|
38
|
+
// The OS caption buttons over a hidden title bar (Windows); null removes.
|
|
39
|
+
setTitleBarOverlay(overlay) {
|
|
40
|
+
return this.cmd("setTitleBarOverlay", overlay === null ? null : { ...overlay });
|
|
41
|
+
}
|
|
42
|
+
// Moves the macOS window buttons.
|
|
43
|
+
setTrafficLightPosition(x, y) {
|
|
44
|
+
return this.cmd("setTrafficLightPosition", x, y);
|
|
45
|
+
}
|
|
46
|
+
// Starts a native window move from the press that is happening. Pages
|
|
47
|
+
// normally mark drag regions in markup instead.
|
|
48
|
+
startDrag() {
|
|
49
|
+
return this.cmd("startDrag");
|
|
50
|
+
}
|
|
51
|
+
toggleMaximize() {
|
|
52
|
+
return this.cmd("toggleMaximize");
|
|
53
|
+
}
|
|
54
|
+
// macOS: the dot in the close button for unsaved changes.
|
|
55
|
+
setDocumentEdited(on) {
|
|
56
|
+
return this.cmd("setDocumentEdited", on);
|
|
57
|
+
}
|
|
58
|
+
// macOS: the file whose icon the title bar shows; "" clears it.
|
|
59
|
+
setRepresentedFile(path) {
|
|
60
|
+
return this.cmd("setRepresentedFile", path);
|
|
61
|
+
}
|
|
62
|
+
// macOS: shows another window of the app as a sheet attached to this one.
|
|
63
|
+
attachSheet(child) {
|
|
64
|
+
return this.cmd("attachSheet", typeof child === "string" ? child : child.id);
|
|
65
|
+
}
|
|
66
|
+
endSheet() {
|
|
67
|
+
return this.cmd("endSheet");
|
|
68
|
+
}
|
|
69
|
+
// macOS: windows with the same identifier tab together.
|
|
70
|
+
setTabbing(identifier, mode = "preferred") {
|
|
71
|
+
return this.cmd("setTabbing", identifier, mode);
|
|
72
|
+
}
|
|
73
|
+
mergeAllWindows() {
|
|
74
|
+
return this.cmd("mergeAllWindows");
|
|
75
|
+
}
|
|
76
|
+
moveTabToNewWindow() {
|
|
77
|
+
return this.cmd("moveTabToNewWindow");
|
|
78
|
+
}
|
|
79
|
+
// Ids of the windows in this window's tab group, in tab order.
|
|
80
|
+
tabs() {
|
|
81
|
+
return call("krate/chrome.tabs", [this.id]);
|
|
82
|
+
}
|
|
83
|
+
// Windows: replaces the taskbar thumbnail buttons (at most 7). Clicks
|
|
84
|
+
// arrive as "thumb-click" events.
|
|
85
|
+
setThumbButtons(buttons) {
|
|
86
|
+
return this.cmd("setThumbButtons", buttons.map((b) => ({ ...b, icon: b.icon ?? new Uint8Array(0) })));
|
|
87
|
+
}
|
|
88
|
+
onNewTab(fn, opts) {
|
|
89
|
+
return onChromeEvent((e) => {
|
|
90
|
+
if (e.window === this.id && e.kind === "new-tab")
|
|
91
|
+
fn();
|
|
92
|
+
}, opts);
|
|
93
|
+
}
|
|
94
|
+
onThumbClick(fn, opts) {
|
|
95
|
+
return onChromeEvent((e) => {
|
|
96
|
+
if (e.window === this.id && e.kind === "thumb-click")
|
|
97
|
+
fn(e.id);
|
|
98
|
+
}, opts);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// Named mainChrome, getChrome and onChromeEvent (not main, get and onEvent) so
|
|
102
|
+
// that a page can use this module and @krate/app/window together: the bundler
|
|
103
|
+
// does not yet keep same-named exports of two modules apart.
|
|
104
|
+
export function mainChrome() {
|
|
105
|
+
return new ChromeWindow("main");
|
|
106
|
+
}
|
|
107
|
+
export function getChrome(id) {
|
|
108
|
+
return new ChromeWindow(id);
|
|
109
|
+
}
|
|
110
|
+
// Shows the system share menu for items, anchored on a window (macOS). It
|
|
111
|
+
// resolves when the menu is shown. Needs the "share" permission.
|
|
112
|
+
export function share(window, items) {
|
|
113
|
+
const id = typeof window === "string" ? window : window.id;
|
|
114
|
+
return call("krate/chrome.share", [id, { text: "", urls: [], files: [], ...items }]);
|
|
115
|
+
}
|
|
116
|
+
// Windows: replaces the tasks of the taskbar jump list (at most 20).
|
|
117
|
+
export function setJumpList(tasks) {
|
|
118
|
+
return call("krate/chrome.setJumpList", [tasks.map((t) => ({ args: [], description: "", iconPath: "", iconIndex: 0, ...t }))]);
|
|
119
|
+
}
|
|
120
|
+
export function clearJumpList() {
|
|
121
|
+
return call("krate/chrome.clearJumpList");
|
|
122
|
+
}
|
|
123
|
+
// macOS: "accessory" makes a menu-bar-only app with no dock icon.
|
|
124
|
+
export function setActivationPolicy(policy) {
|
|
125
|
+
return call("krate/chrome.setActivationPolicy", [policy]);
|
|
126
|
+
}
|
|
127
|
+
// macOS: show or hide the dock icon.
|
|
128
|
+
export function setDockVisible(on) {
|
|
129
|
+
return call("krate/chrome.setDockVisible", [on]);
|
|
130
|
+
}
|
|
131
|
+
export function onChromeEvent(fn, opts) {
|
|
132
|
+
return subscribe("krate/chrome.events", fn, opts);
|
|
133
|
+
}
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { CallOptions, ReadonlyHostSignal } from "./types.js";
|
|
2
|
+
export type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
|
|
3
|
+
export interface ClientOptions {
|
|
4
|
+
fetch?: FetchLike;
|
|
5
|
+
origin?: string;
|
|
6
|
+
windowId?: string;
|
|
7
|
+
createSignal?: <T>(initial: T) => [() => T, (v: T) => void];
|
|
8
|
+
}
|
|
9
|
+
export interface Client {
|
|
10
|
+
call<T = unknown>(fn: string, args?: unknown[], opts?: CallOptions): Promise<T>;
|
|
11
|
+
stream<T = unknown>(fn: string, args?: unknown[], opts?: CallOptions): AsyncIterable<T> & AsyncIterator<T>;
|
|
12
|
+
signal<T = unknown>(name: string): ReadonlyHostSignal<T, T | undefined>;
|
|
13
|
+
close(): void;
|
|
14
|
+
}
|
|
15
|
+
export declare function createClient(options?: ClientOptions): Client;
|
|
16
|
+
export interface HostBridge {
|
|
17
|
+
call(id: string, args?: unknown[]): Promise<unknown>;
|
|
18
|
+
stream(id: string, args?: unknown[]): AsyncIterable<unknown>;
|
|
19
|
+
signal(id: string): {
|
|
20
|
+
get(): unknown;
|
|
21
|
+
subscribe(fn: (v: any) => void): () => void;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare function hostBridge(): HostBridge | undefined;
|
|
25
|
+
export declare function createHostClient(bridge: HostBridge): Client;
|
|
26
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGlE,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEjF,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,SAAS,CAAC;IAElB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAIlB,YAAY,CAAC,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