winui-svelte 0.0.7 → 0.0.8

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.
Files changed (513) hide show
  1. package/API.md +565 -19
  2. package/README.md +21 -5
  3. package/dist/app/activate.d.ts.map +1 -1
  4. package/dist/app/activate.js +3 -0
  5. package/dist/app/activate.js.map +1 -1
  6. package/dist/app/activation/index.d.ts +3 -0
  7. package/dist/app/activation/index.d.ts.map +1 -1
  8. package/dist/app/activation/index.js +2 -0
  9. package/dist/app/activation/index.js.map +1 -1
  10. package/dist/app/activation/login.d.ts +2 -1
  11. package/dist/app/activation/login.d.ts.map +1 -1
  12. package/dist/app/activation/login.js +2 -1
  13. package/dist/app/activation/login.js.map +1 -1
  14. package/dist/app/activation/native.js +1 -2
  15. package/dist/app/activation/native.js.map +1 -1
  16. package/dist/app/activation/packaged.d.ts +49 -0
  17. package/dist/app/activation/packaged.d.ts.map +1 -0
  18. package/dist/app/activation/packaged.js +90 -0
  19. package/dist/app/activation/packaged.js.map +1 -0
  20. package/dist/app/activation/receive.d.ts +11 -2
  21. package/dist/app/activation/receive.d.ts.map +1 -1
  22. package/dist/app/activation/receive.js +11 -4
  23. package/dist/app/activation/receive.js.map +1 -1
  24. package/dist/app/activation/registration.d.ts +3 -3
  25. package/dist/app/activation/registration.js +7 -7
  26. package/dist/app/activation/registration.js.map +1 -1
  27. package/dist/app/activation/scheme.d.ts +10 -0
  28. package/dist/app/activation/scheme.d.ts.map +1 -1
  29. package/dist/app/activation/scheme.js +17 -0
  30. package/dist/app/activation/scheme.js.map +1 -1
  31. package/dist/app/index.d.ts +4 -2
  32. package/dist/app/index.d.ts.map +1 -1
  33. package/dist/app/index.js +3 -1
  34. package/dist/app/index.js.map +1 -1
  35. package/dist/app/instance-running.d.ts +15 -0
  36. package/dist/app/instance-running.d.ts.map +1 -0
  37. package/dist/app/instance-running.js +20 -0
  38. package/dist/app/instance-running.js.map +1 -0
  39. package/dist/app/jump-list/native.d.ts.map +1 -1
  40. package/dist/app/jump-list/native.js +1 -2
  41. package/dist/app/jump-list/native.js.map +1 -1
  42. package/dist/app/native-messaging/browsers.d.ts +19 -0
  43. package/dist/app/native-messaging/browsers.d.ts.map +1 -0
  44. package/dist/app/native-messaging/browsers.js +17 -0
  45. package/dist/app/native-messaging/browsers.js.map +1 -0
  46. package/dist/app/native-messaging/index.d.ts +41 -0
  47. package/dist/app/native-messaging/index.d.ts.map +1 -0
  48. package/dist/app/native-messaging/index.js +84 -0
  49. package/dist/app/native-messaging/index.js.map +1 -0
  50. package/dist/app/native.d.ts +0 -6
  51. package/dist/app/native.d.ts.map +1 -1
  52. package/dist/app/native.js +1 -24
  53. package/dist/app/native.js.map +1 -1
  54. package/dist/app/notification-source.d.ts.map +1 -1
  55. package/dist/app/notification-source.js +1 -2
  56. package/dist/app/notification-source.js.map +1 -1
  57. package/dist/app/shell/native.js +1 -2
  58. package/dist/app/shell/native.js.map +1 -1
  59. package/dist/app/single-instance.d.ts +27 -1
  60. package/dist/app/single-instance.d.ts.map +1 -1
  61. package/dist/app/single-instance.js +32 -10
  62. package/dist/app/single-instance.js.map +1 -1
  63. package/dist/automation/native.d.ts.map +1 -1
  64. package/dist/automation/native.js +1 -2
  65. package/dist/automation/native.js.map +1 -1
  66. package/dist/bindings/.dynwinrt-js-types +198 -0
  67. package/dist/bindings/.dynwinrt-managed +1 -1
  68. package/dist/bindings/index.d.ts +15 -0
  69. package/dist/bindings/index.js +20 -0
  70. package/dist/bindings/index.mjs +2902 -2882
  71. package/dist/bindings/index.proxy.js +10 -0
  72. package/dist/bindings/windows/application-model/activation/ActivationKind.d.ts +49 -0
  73. package/dist/bindings/windows/application-model/activation/ActivationKind.js +50 -0
  74. package/dist/bindings/windows/application-model/activation/ApplicationExecutionState.d.ts +9 -0
  75. package/dist/bindings/windows/application-model/activation/ApplicationExecutionState.js +10 -0
  76. package/dist/bindings/windows/application-model/activation/IActivatedEventArgs.d.ts +36 -0
  77. package/dist/bindings/windows/application-model/activation/IActivatedEventArgs.js +149 -0
  78. package/dist/bindings/windows/application-model/activation/IActivatedEventArgsWithUser.d.ts +28 -0
  79. package/dist/bindings/windows/application-model/activation/IActivatedEventArgsWithUser.js +119 -0
  80. package/dist/bindings/windows/application-model/activation/IApplicationViewActivatedEventArgs.d.ts +27 -0
  81. package/dist/bindings/windows/application-model/activation/IApplicationViewActivatedEventArgs.js +116 -0
  82. package/dist/bindings/windows/application-model/activation/IProtocolActivatedEventArgsWithCallerPackageFamilyNameAndData.d.ts +31 -0
  83. package/dist/bindings/windows/application-model/activation/IProtocolActivatedEventArgsWithCallerPackageFamilyNameAndData.js +131 -0
  84. package/dist/bindings/windows/application-model/activation/IViewSwitcherProvider.d.ts +28 -0
  85. package/dist/bindings/windows/application-model/activation/IViewSwitcherProvider.js +119 -0
  86. package/dist/bindings/windows/application-model/activation/ProtocolActivatedEventArgs.d.ts +25 -0
  87. package/dist/bindings/windows/application-model/activation/ProtocolActivatedEventArgs.js +166 -0
  88. package/dist/bindings/windows/application-model/activation/SplashScreen.d.ts +35 -0
  89. package/dist/bindings/windows/application-model/activation/SplashScreen.js +105 -0
  90. package/dist/bindings/windows/foundation/TypedEventHandler_WindowsApplicationModelActivationSplashScreen_Object_g7a7dbfa699cd28ff.d.ts +7 -0
  91. package/dist/bindings/windows/foundation/TypedEventHandler_WindowsApplicationModelActivationSplashScreen_Object_g7a7dbfa699cd28ff.js +7 -0
  92. package/dist/bindings/windows/ui/view-management/ActivationViewSwitcher.d.ts +12 -0
  93. package/dist/bindings/windows/ui/view-management/ActivationViewSwitcher.js +96 -0
  94. package/dist/chrome/context-menus/context-menu-schema.d.ts.map +1 -1
  95. package/dist/chrome/context-menus/context-menu-schema.js +1 -7
  96. package/dist/chrome/context-menus/context-menu-schema.js.map +1 -1
  97. package/dist/chrome/parse-or-throw.d.ts +7 -0
  98. package/dist/chrome/parse-or-throw.d.ts.map +1 -0
  99. package/dist/chrome/parse-or-throw.js +9 -0
  100. package/dist/chrome/parse-or-throw.js.map +1 -0
  101. package/dist/chrome/permissions/permission-schema.d.ts.map +1 -1
  102. package/dist/chrome/permissions/permission-schema.js +1 -7
  103. package/dist/chrome/permissions/permission-schema.js.map +1 -1
  104. package/dist/chrome/windows/chrome-windows.d.ts.map +1 -1
  105. package/dist/chrome/windows/chrome-windows.js +1 -7
  106. package/dist/chrome/windows/chrome-windows.js.map +1 -1
  107. package/dist/components/hand-written/items/keyed-rows.svelte.d.ts.map +1 -1
  108. package/dist/components/hand-written/items/keyed-rows.svelte.js +6 -0
  109. package/dist/components/hand-written/items/keyed-rows.svelte.js.map +1 -1
  110. package/dist/components/index.d.ts +1 -0
  111. package/dist/components/index.d.ts.map +1 -1
  112. package/dist/components/runtime.svelte.d.ts.map +1 -1
  113. package/dist/components/runtime.svelte.js +7 -0
  114. package/dist/components/runtime.svelte.js.map +1 -1
  115. package/dist/composition/expression.d.ts +1 -1
  116. package/dist/css/runtime/containers.d.ts.map +1 -1
  117. package/dist/css/runtime/containers.js +1 -17
  118. package/dist/css/runtime/containers.js.map +1 -1
  119. package/dist/css/runtime/native.d.ts.map +1 -1
  120. package/dist/css/runtime/native.js +40 -20
  121. package/dist/css/runtime/native.js.map +1 -1
  122. package/dist/css/translate/property-kit.d.ts +9 -0
  123. package/dist/css/translate/property-kit.d.ts.map +1 -1
  124. package/dist/css/translate/property-kit.js.map +1 -1
  125. package/dist/css/translate/transition-properties.d.ts +1 -1
  126. package/dist/css/translate/transition-properties.d.ts.map +1 -1
  127. package/dist/css/translate/transition-properties.js +32 -5
  128. package/dist/css/translate/transition-properties.js.map +1 -1
  129. package/dist/data-transfer/data-transfer.d.ts +3 -3
  130. package/dist/data-transfer/data-transfer.d.ts.map +1 -1
  131. package/dist/data-transfer/data-transfer.js.map +1 -1
  132. package/dist/data-transfer/drag-effects.d.ts +25 -2
  133. package/dist/data-transfer/drag-effects.d.ts.map +1 -1
  134. package/dist/data-transfer/drag-effects.js +27 -2
  135. package/dist/data-transfer/drag-effects.js.map +1 -1
  136. package/dist/data-transfer/drag-helper.d.ts +50 -0
  137. package/dist/data-transfer/drag-helper.d.ts.map +1 -0
  138. package/dist/data-transfer/drag-helper.js +156 -0
  139. package/dist/data-transfer/drag-helper.js.map +1 -0
  140. package/dist/data-transfer/drop-target.d.ts +6 -5
  141. package/dist/data-transfer/drop-target.d.ts.map +1 -1
  142. package/dist/data-transfer/drop-target.js +68 -20
  143. package/dist/data-transfer/drop-target.js.map +1 -1
  144. package/dist/data-transfer/index.d.ts +1 -0
  145. package/dist/data-transfer/index.d.ts.map +1 -1
  146. package/dist/data-transfer/index.js.map +1 -1
  147. package/dist/data-transfer/launcher.d.ts +4 -3
  148. package/dist/data-transfer/launcher.d.ts.map +1 -1
  149. package/dist/data-transfer/launcher.js +58 -9
  150. package/dist/data-transfer/launcher.js.map +1 -1
  151. package/dist/data-transfer/native.d.ts +66 -0
  152. package/dist/data-transfer/native.d.ts.map +1 -0
  153. package/dist/data-transfer/native.js +148 -0
  154. package/dist/data-transfer/native.js.map +1 -0
  155. package/dist/data-transfer/ole-data-object.d.ts +62 -0
  156. package/dist/data-transfer/ole-data-object.d.ts.map +1 -0
  157. package/dist/data-transfer/ole-data-object.js +162 -0
  158. package/dist/data-transfer/ole-data-object.js.map +1 -0
  159. package/dist/data-transfer/ole-drop-target.d.ts +54 -0
  160. package/dist/data-transfer/ole-drop-target.d.ts.map +1 -0
  161. package/dist/data-transfer/ole-drop-target.js +192 -0
  162. package/dist/data-transfer/ole-drop-target.js.map +1 -0
  163. package/dist/data-transfer/share-interop.d.ts.map +1 -1
  164. package/dist/data-transfer/share-interop.js +1 -1
  165. package/dist/data-transfer/share-interop.js.map +1 -1
  166. package/dist/data-transfer/shell-items.d.ts +10 -0
  167. package/dist/data-transfer/shell-items.d.ts.map +1 -0
  168. package/dist/data-transfer/shell-items.js +67 -0
  169. package/dist/data-transfer/shell-items.js.map +1 -0
  170. package/dist/data-transfer/window-drop.d.ts +35 -0
  171. package/dist/data-transfer/window-drop.d.ts.map +1 -0
  172. package/dist/data-transfer/window-drop.js +311 -0
  173. package/dist/data-transfer/window-drop.js.map +1 -0
  174. package/dist/devices/native.js +1 -2
  175. package/dist/devices/native.js.map +1 -1
  176. package/dist/enums.d.ts +3 -0
  177. package/dist/enums.d.ts.map +1 -1
  178. package/dist/enums.js +3 -0
  179. package/dist/enums.js.map +1 -1
  180. package/dist/input/index.d.ts +2 -0
  181. package/dist/input/index.d.ts.map +1 -1
  182. package/dist/input/index.js +1 -0
  183. package/dist/input/index.js.map +1 -1
  184. package/dist/input/modifier-keys.d.ts +24 -0
  185. package/dist/input/modifier-keys.d.ts.map +1 -0
  186. package/dist/input/modifier-keys.js +20 -0
  187. package/dist/input/modifier-keys.js.map +1 -0
  188. package/dist/media/pixel-buffer.d.ts.map +1 -1
  189. package/dist/media/pixel-buffer.js +1 -1
  190. package/dist/media/pixel-buffer.js.map +1 -1
  191. package/dist/messaging/web-view2/core.d.ts +56 -0
  192. package/dist/messaging/web-view2/core.d.ts.map +1 -1
  193. package/dist/messaging/web-view2/core.js +6 -0
  194. package/dist/messaging/web-view2/core.js.map +1 -1
  195. package/dist/messaging/web-view2/environment.d.ts +41 -0
  196. package/dist/messaging/web-view2/environment.d.ts.map +1 -0
  197. package/dist/messaging/web-view2/environment.js +91 -0
  198. package/dist/messaging/web-view2/environment.js.map +1 -0
  199. package/dist/messaging/web-view2/index.d.ts +9 -1
  200. package/dist/messaging/web-view2/index.d.ts.map +1 -1
  201. package/dist/messaging/web-view2/index.js +5 -0
  202. package/dist/messaging/web-view2/index.js.map +1 -1
  203. package/dist/messaging/web-view2/input.d.ts +68 -0
  204. package/dist/messaging/web-view2/input.d.ts.map +1 -0
  205. package/dist/messaging/web-view2/input.js +108 -0
  206. package/dist/messaging/web-view2/input.js.map +1 -0
  207. package/dist/messaging/web-view2/protocol.d.ts +24 -0
  208. package/dist/messaging/web-view2/protocol.d.ts.map +1 -0
  209. package/dist/messaging/web-view2/protocol.js +31 -0
  210. package/dist/messaging/web-view2/protocol.js.map +1 -0
  211. package/dist/messaging/web-view2/recovery.d.ts +65 -0
  212. package/dist/messaging/web-view2/recovery.d.ts.map +1 -0
  213. package/dist/messaging/web-view2/recovery.js +138 -0
  214. package/dist/messaging/web-view2/recovery.js.map +1 -0
  215. package/dist/messaging/web-view2/requests.d.ts +88 -0
  216. package/dist/messaging/web-view2/requests.d.ts.map +1 -0
  217. package/dist/messaging/web-view2/requests.js +169 -0
  218. package/dist/messaging/web-view2/requests.js.map +1 -0
  219. package/dist/messaging/web-view2/transport.d.ts.map +1 -1
  220. package/dist/messaging/web-view2/transport.js +1 -4
  221. package/dist/messaging/web-view2/transport.js.map +1 -1
  222. package/dist/native-identity.d.ts +10 -0
  223. package/dist/native-identity.d.ts.map +1 -0
  224. package/dist/native-identity.js +20 -0
  225. package/dist/native-identity.js.map +1 -0
  226. package/dist/renderer/host/host.d.ts.map +1 -1
  227. package/dist/renderer/host/host.js +33 -16
  228. package/dist/renderer/host/host.js.map +1 -1
  229. package/dist/renderer/host/structure-sync.d.ts +9 -0
  230. package/dist/renderer/host/structure-sync.d.ts.map +1 -0
  231. package/dist/renderer/host/structure-sync.js +24 -0
  232. package/dist/renderer/host/structure-sync.js.map +1 -0
  233. package/dist/security/data-protection-error.d.ts +14 -0
  234. package/dist/security/data-protection-error.d.ts.map +1 -0
  235. package/dist/security/data-protection-error.js +15 -0
  236. package/dist/security/data-protection-error.js.map +1 -0
  237. package/dist/security/index.d.ts +48 -0
  238. package/dist/security/index.d.ts.map +1 -0
  239. package/dist/security/index.js +32 -0
  240. package/dist/security/index.js.map +1 -0
  241. package/dist/security/native.d.ts +43 -0
  242. package/dist/security/native.d.ts.map +1 -0
  243. package/dist/security/native.js +170 -0
  244. package/dist/security/native.js.map +1 -0
  245. package/dist/security/protection-scope.d.ts +13 -0
  246. package/dist/security/protection-scope.d.ts.map +1 -0
  247. package/dist/security/protection-scope.js +11 -0
  248. package/dist/security/protection-scope.js.map +1 -0
  249. package/dist/store/states.d.ts +2 -2
  250. package/dist/store/windows-identity.d.ts +2 -6
  251. package/dist/store/windows-identity.d.ts.map +1 -1
  252. package/dist/store/windows-identity.js +2 -29
  253. package/dist/store/windows-identity.js.map +1 -1
  254. package/dist/store/windows-packages.d.ts +2 -2
  255. package/dist/store/windows-store.d.ts +2 -2
  256. package/dist/tray/click-detector.d.ts.map +1 -1
  257. package/dist/tray/click-detector.js.map +1 -1
  258. package/dist/tray/flyout-model.d.ts +4 -3
  259. package/dist/tray/flyout-model.d.ts.map +1 -1
  260. package/dist/tray/flyout-model.js +12 -2
  261. package/dist/tray/flyout-model.js.map +1 -1
  262. package/dist/tray/menu/icon.d.ts +17 -0
  263. package/dist/tray/menu/icon.d.ts.map +1 -0
  264. package/dist/tray/menu/icon.js +31 -0
  265. package/dist/tray/menu/icon.js.map +1 -0
  266. package/dist/tray/menu/index.d.ts +1 -1
  267. package/dist/tray/menu/index.d.ts.map +1 -1
  268. package/dist/tray/menu/index.js.map +1 -1
  269. package/dist/tray/menu/types.d.ts +23 -6
  270. package/dist/tray/menu/types.d.ts.map +1 -1
  271. package/dist/tray/menu/types.js.map +1 -1
  272. package/dist/tray/menu-svelte/menu-node.d.ts +4 -4
  273. package/dist/tray/native.d.ts +9 -4
  274. package/dist/tray/native.d.ts.map +1 -1
  275. package/dist/tray/native.js +10 -18
  276. package/dist/tray/native.js.map +1 -1
  277. package/dist/tray/personalize.d.ts +18 -0
  278. package/dist/tray/personalize.d.ts.map +1 -0
  279. package/dist/tray/personalize.js +42 -0
  280. package/dist/tray/personalize.js.map +1 -0
  281. package/dist/tray/standalone/icon-raster.d.ts +72 -0
  282. package/dist/tray/standalone/icon-raster.d.ts.map +1 -0
  283. package/dist/tray/standalone/icon-raster.js +161 -0
  284. package/dist/tray/standalone/icon-raster.js.map +1 -0
  285. package/dist/tray/standalone/index.d.ts +3 -2
  286. package/dist/tray/standalone/index.d.ts.map +1 -1
  287. package/dist/tray/standalone/index.js +1 -0
  288. package/dist/tray/standalone/index.js.map +1 -1
  289. package/dist/tray/standalone/menu-icons.d.ts +9 -0
  290. package/dist/tray/standalone/menu-icons.d.ts.map +1 -0
  291. package/dist/tray/standalone/menu-icons.js +280 -0
  292. package/dist/tray/standalone/menu-icons.js.map +1 -0
  293. package/dist/tray/standalone/native.d.ts +19 -6
  294. package/dist/tray/standalone/native.d.ts.map +1 -1
  295. package/dist/tray/standalone/native.js +58 -15
  296. package/dist/tray/standalone/native.js.map +1 -1
  297. package/dist/tray/standalone/standalone-tray.d.ts +4 -2
  298. package/dist/tray/standalone/standalone-tray.d.ts.map +1 -1
  299. package/dist/tray/standalone/standalone-tray.js +12 -2
  300. package/dist/tray/standalone/standalone-tray.js.map +1 -1
  301. package/dist/tray/themed-icon.d.ts.map +1 -1
  302. package/dist/tray/themed-icon.js +4 -28
  303. package/dist/tray/themed-icon.js.map +1 -1
  304. package/dist/tray/tray-core.d.ts.map +1 -1
  305. package/dist/tray/tray-core.js +5 -1
  306. package/dist/tray/tray-core.js.map +1 -1
  307. package/dist/tray/tray-extras.d.ts +26 -2
  308. package/dist/tray/tray-extras.d.ts.map +1 -1
  309. package/dist/web-apis/eye-dropper.d.ts.map +1 -1
  310. package/dist/web-apis/eye-dropper.js +8 -5
  311. package/dist/web-apis/eye-dropper.js.map +1 -1
  312. package/dist/web-apis/media-devices-source.d.ts +1 -1
  313. package/dist/web-apis/native.d.ts +0 -7
  314. package/dist/web-apis/native.d.ts.map +1 -1
  315. package/dist/web-apis/native.js +0 -19
  316. package/dist/web-apis/native.js.map +1 -1
  317. package/dist/win2d/activation-failure.d.ts +10 -0
  318. package/dist/win2d/activation-failure.d.ts.map +1 -0
  319. package/dist/win2d/activation-failure.js +30 -0
  320. package/dist/win2d/activation-failure.js.map +1 -0
  321. package/dist/win2d/element-lifecycle.d.ts.map +1 -1
  322. package/dist/win2d/element-lifecycle.js +6 -1
  323. package/dist/win2d/element-lifecycle.js.map +1 -1
  324. package/dist/win2d/manifest.d.ts +29 -0
  325. package/dist/win2d/manifest.d.ts.map +1 -0
  326. package/dist/win2d/manifest.js +67 -0
  327. package/dist/win2d/manifest.js.map +1 -0
  328. package/dist/win32/index.d.ts +3 -0
  329. package/dist/win32/index.d.ts.map +1 -0
  330. package/dist/win32/index.js +11 -0
  331. package/dist/win32/index.js.map +1 -0
  332. package/dist/win32-calls.d.ts +6 -0
  333. package/dist/win32-calls.d.ts.map +1 -1
  334. package/dist/win32-calls.js +6 -1
  335. package/dist/win32-calls.js.map +1 -1
  336. package/dist/win32-foreground.d.ts +20 -0
  337. package/dist/win32-foreground.d.ts.map +1 -1
  338. package/dist/win32-foreground.js +24 -4
  339. package/dist/win32-foreground.js.map +1 -1
  340. package/dist/win32-icons.d.ts.map +1 -1
  341. package/dist/win32-icons.js +1 -2
  342. package/dist/win32-icons.js.map +1 -1
  343. package/dist/win32-key-state.d.ts +31 -0
  344. package/dist/win32-key-state.d.ts.map +1 -0
  345. package/dist/win32-key-state.js +41 -0
  346. package/dist/win32-key-state.js.map +1 -0
  347. package/dist/window/anchor.d.ts +15 -0
  348. package/dist/window/anchor.d.ts.map +1 -1
  349. package/dist/window/anchor.js +23 -0
  350. package/dist/window/anchor.js.map +1 -1
  351. package/dist/window/apply-frame.d.ts +4 -2
  352. package/dist/window/apply-frame.d.ts.map +1 -1
  353. package/dist/window/apply-frame.js +2 -3
  354. package/dist/window/apply-frame.js.map +1 -1
  355. package/dist/window/bootstrap-core.d.ts +69 -0
  356. package/dist/window/bootstrap-core.d.ts.map +1 -0
  357. package/dist/window/bootstrap-core.js +93 -0
  358. package/dist/window/bootstrap-core.js.map +1 -0
  359. package/dist/window/bootstrap-mode.d.ts +21 -0
  360. package/dist/window/bootstrap-mode.d.ts.map +1 -0
  361. package/dist/window/bootstrap-mode.js +17 -0
  362. package/dist/window/bootstrap-mode.js.map +1 -0
  363. package/dist/window/bootstrap.d.ts +12 -28
  364. package/dist/window/bootstrap.d.ts.map +1 -1
  365. package/dist/window/bootstrap.js +18 -66
  366. package/dist/window/bootstrap.js.map +1 -1
  367. package/dist/window/cover.d.ts +43 -0
  368. package/dist/window/cover.d.ts.map +1 -0
  369. package/dist/window/cover.js +64 -0
  370. package/dist/window/cover.js.map +1 -0
  371. package/dist/window/create-window.d.ts +1 -1
  372. package/dist/window/create-window.d.ts.map +1 -1
  373. package/dist/window/create-window.js +1 -0
  374. package/dist/window/create-window.js.map +1 -1
  375. package/dist/window/dpi-awareness.d.ts +71 -0
  376. package/dist/window/dpi-awareness.d.ts.map +1 -0
  377. package/dist/window/dpi-awareness.js +127 -0
  378. package/dist/window/dpi-awareness.js.map +1 -0
  379. package/dist/window/foreground-native.d.ts.map +1 -1
  380. package/dist/window/foreground-native.js +3 -5
  381. package/dist/window/foreground-native.js.map +1 -1
  382. package/dist/window/index.d.ts +2 -0
  383. package/dist/window/index.d.ts.map +1 -1
  384. package/dist/window/index.js +1 -0
  385. package/dist/window/index.js.map +1 -1
  386. package/dist/window/native.d.ts.map +1 -1
  387. package/dist/window/native.js +1 -2
  388. package/dist/window/native.js.map +1 -1
  389. package/dist/window/package-identity.d.ts +17 -0
  390. package/dist/window/package-identity.d.ts.map +1 -0
  391. package/dist/window/package-identity.js +97 -0
  392. package/dist/window/package-identity.js.map +1 -0
  393. package/dist/window/system-dispatcher-queue.d.ts.map +1 -1
  394. package/dist/window/system-dispatcher-queue.js +1 -2
  395. package/dist/window/system-dispatcher-queue.js.map +1 -1
  396. package/dist/window/taskbar-calls.d.ts +1 -1
  397. package/dist/window/taskbar-native.d.ts.map +1 -1
  398. package/dist/window/taskbar-native.js +1 -2
  399. package/dist/window/taskbar-native.js.map +1 -1
  400. package/dist/window/window-handle.d.ts +25 -1
  401. package/dist/window/window-handle.d.ts.map +1 -1
  402. package/dist/window/window-handle.js +27 -1
  403. package/dist/window/window-handle.js.map +1 -1
  404. package/dist/window/window-host.svelte.d.ts +10 -1
  405. package/dist/window/window-host.svelte.d.ts.map +1 -1
  406. package/dist/window/window-host.svelte.js +38 -4
  407. package/dist/window/window-host.svelte.js.map +1 -1
  408. package/package.json +26 -4
  409. package/src/app/activate.ts +3 -0
  410. package/src/app/activation/index.ts +3 -0
  411. package/src/app/activation/login.ts +2 -1
  412. package/src/app/activation/native.ts +1 -1
  413. package/src/app/activation/packaged.ts +118 -0
  414. package/src/app/activation/receive.ts +24 -4
  415. package/src/app/activation/registration.ts +7 -7
  416. package/src/app/activation/scheme.ts +19 -0
  417. package/src/app/index.ts +4 -2
  418. package/src/app/instance-running.ts +22 -0
  419. package/src/app/jump-list/native.ts +1 -2
  420. package/src/app/native-messaging/browsers.ts +21 -0
  421. package/src/app/native-messaging/index.ts +124 -0
  422. package/src/app/native.ts +1 -32
  423. package/src/app/notification-source.ts +1 -3
  424. package/src/app/shell/native.ts +1 -1
  425. package/src/app/single-instance.ts +34 -10
  426. package/src/automation/native.ts +1 -2
  427. package/src/chrome/context-menus/context-menu-schema.ts +1 -12
  428. package/src/chrome/parse-or-throw.ts +14 -0
  429. package/src/chrome/permissions/permission-schema.ts +1 -12
  430. package/src/chrome/windows/chrome-windows.ts +1 -13
  431. package/src/components/hand-written/items/keyed-rows.svelte.ts +6 -0
  432. package/src/components/index.ts +1 -0
  433. package/src/components/runtime.svelte.ts +8 -0
  434. package/src/css/runtime/containers.ts +1 -20
  435. package/src/css/runtime/native.ts +46 -21
  436. package/src/css/translate/property-kit.ts +9 -0
  437. package/src/css/translate/transition-properties.ts +44 -10
  438. package/src/data-transfer/data-transfer.ts +3 -3
  439. package/src/data-transfer/drag-effects.ts +48 -4
  440. package/src/data-transfer/drag-helper.ts +216 -0
  441. package/src/data-transfer/drop-target.ts +90 -26
  442. package/src/data-transfer/index.ts +1 -0
  443. package/src/data-transfer/launcher.ts +65 -9
  444. package/src/data-transfer/native.ts +184 -0
  445. package/src/data-transfer/ole-data-object.ts +200 -0
  446. package/src/data-transfer/ole-drop-target.ts +263 -0
  447. package/src/data-transfer/share-interop.ts +1 -1
  448. package/src/data-transfer/shell-items.ts +81 -0
  449. package/src/data-transfer/window-drop.ts +411 -0
  450. package/src/devices/native.ts +1 -1
  451. package/src/enums.ts +3 -0
  452. package/src/input/index.ts +2 -0
  453. package/src/input/modifier-keys.ts +30 -0
  454. package/src/media/pixel-buffer.ts +1 -1
  455. package/src/messaging/web-view2/core.ts +64 -0
  456. package/src/messaging/web-view2/environment.ts +131 -0
  457. package/src/messaging/web-view2/index.ts +11 -0
  458. package/src/messaging/web-view2/input.ts +154 -0
  459. package/src/messaging/web-view2/protocol.ts +41 -0
  460. package/src/messaging/web-view2/recovery.ts +177 -0
  461. package/src/messaging/web-view2/requests.ts +238 -0
  462. package/src/messaging/web-view2/transport.ts +1 -5
  463. package/src/native-identity.ts +22 -0
  464. package/src/renderer/host/host.ts +39 -17
  465. package/src/renderer/host/structure-sync.ts +25 -0
  466. package/src/security/data-protection-error.ts +18 -0
  467. package/src/security/index.ts +57 -0
  468. package/src/security/native.ts +234 -0
  469. package/src/security/protection-scope.ts +13 -0
  470. package/src/store/windows-identity.ts +3 -35
  471. package/src/tray/click-detector.ts +6 -7
  472. package/src/tray/flyout-model.ts +14 -3
  473. package/src/tray/menu/icon.ts +40 -0
  474. package/src/tray/menu/index.ts +3 -0
  475. package/src/tray/menu/types.ts +27 -6
  476. package/src/tray/native.ts +20 -21
  477. package/src/tray/personalize.ts +57 -0
  478. package/src/tray/pointer-share.ts +3 -3
  479. package/src/tray/standalone/icon-raster.ts +208 -0
  480. package/src/tray/standalone/index.ts +4 -1
  481. package/src/tray/standalone/menu-icons.ts +317 -0
  482. package/src/tray/standalone/native.ts +78 -15
  483. package/src/tray/standalone/standalone-tray.ts +26 -5
  484. package/src/tray/themed-icon.ts +4 -36
  485. package/src/tray/tray-core.ts +6 -1
  486. package/src/tray/tray-extras.ts +31 -2
  487. package/src/web-apis/eye-dropper.ts +9 -5
  488. package/src/web-apis/native.ts +0 -20
  489. package/src/win2d/activation-failure.ts +35 -0
  490. package/src/win2d/element-lifecycle.ts +6 -1
  491. package/src/win2d/manifest.ts +78 -0
  492. package/src/win32/index.ts +19 -0
  493. package/src/win32-calls.ts +8 -1
  494. package/src/win32-foreground.ts +28 -4
  495. package/src/win32-icons.ts +7 -2
  496. package/src/win32-key-state.ts +48 -0
  497. package/src/window/anchor.ts +28 -0
  498. package/src/window/apply-frame.ts +6 -4
  499. package/src/window/bootstrap-core.ts +165 -0
  500. package/src/window/bootstrap-mode.ts +23 -0
  501. package/src/window/bootstrap.ts +20 -103
  502. package/src/window/cover.ts +100 -0
  503. package/src/window/create-window.ts +2 -0
  504. package/src/window/dpi-awareness.ts +162 -0
  505. package/src/window/foreground-native.ts +3 -5
  506. package/src/window/index.ts +2 -0
  507. package/src/window/native.ts +1 -1
  508. package/src/window/package-identity.ts +112 -0
  509. package/src/window/system-dispatcher-queue.ts +7 -2
  510. package/src/window/taskbar-native.ts +1 -2
  511. package/src/window/window-handle.ts +29 -1
  512. package/src/window/window-host.svelte.ts +58 -5
  513. package/web-types.json +11 -3
@@ -0,0 +1,131 @@
1
+ import { messageOf } from "./core.ts";
2
+ import type { CoreWebView2Like, EnvironmentLike, WebView2Like } from "./core.ts";
3
+ import { CoreWebView2Environment } from "#winui/microsoft/web/web-view2/core/CoreWebView2Environment";
4
+ import { CoreWebView2EnvironmentOptions } from "#winui/microsoft/web/web-view2/core/CoreWebView2EnvironmentOptions";
5
+
6
+ const ARGUMENT_SEPARATOR = " ";
7
+ const INVALID_STATE_CODE = /0x?8007139f/i;
8
+ const BUSY_CODE = /0x?800700aa/i;
9
+ const started = new WeakMap<object, Promise<CoreWebView2Like>>();
10
+
11
+ /** How an environment is built; every member is optional. */
12
+ export interface WebView2EnvironmentInit {
13
+ /** A fixed-version runtime's folder; the installed runtime when empty or absent. */
14
+ browserExecutableFolder?: string;
15
+
16
+ /** The profile folder of this environment; one browser process runs per folder. */
17
+ userDataFolder?: string;
18
+
19
+ /** Chromium switches, joined with spaces, such as `--autoplay-policy=no-user-gesture-required`. */
20
+ additionalBrowserArguments?: string[];
21
+
22
+ /** The browser's language, such as `en-US`. */
23
+ language?: string;
24
+ }
25
+
26
+ // WebView2 answers two different causes with 0x8007139F; the message names both
27
+ function explainFailure({ error, userDataFolder }: {
28
+ error: unknown;
29
+ userDataFolder: string;
30
+ }) {
31
+ const text = messageOf(error);
32
+ if (INVALID_STATE_CODE.test(text)) {
33
+ return new Error(
34
+ `WebView2 refused to start (0x8007139F): either this process cannot launch a browser (run it in an ordinary desktop session), or ${userDataFolder} is already in use with different environment options`,
35
+ { cause: error }
36
+ );
37
+ }
38
+
39
+ if (BUSY_CODE.test(text)) {
40
+ return new Error(`WebView2 profile folder ${userDataFolder} is open in another browser (0x800700AA); use one folder per running app`, { cause: error });
41
+ }
42
+
43
+ return error;
44
+ }
45
+
46
+ /**
47
+ * Builds a WebView2 environment: a profile folder of its own and the Chromium
48
+ * switches of its browser; pass it to `startWebView2`
49
+ * `WEBVIEW2_USER_DATA_FOLDER` overrides `userDataFolder` when it is set, so
50
+ * start the app with `initWindowsAppSdk({ webViewUserDataFolder: false })`
51
+ *
52
+ * @param init - The folder, the switches and the language.
53
+ * @returns The environment.
54
+ */
55
+ export async function createWebView2Environment(init: WebView2EnvironmentInit = {}) {
56
+ const { browserExecutableFolder = "", userDataFolder = "", additionalBrowserArguments = [], language = "" } = init;
57
+ const options = CoreWebView2EnvironmentOptions.create();
58
+ options.additionalBrowserArguments = additionalBrowserArguments.join(ARGUMENT_SEPARATOR);
59
+ const isLanguageSet = language !== "";
60
+ if (isLanguageSet) {
61
+ options.language = language;
62
+ }
63
+
64
+ try {
65
+ return await CoreWebView2Environment.createWithOptionsAsync(browserExecutableFolder, userDataFolder, options);
66
+ } catch (error) {
67
+ throw explainFailure({
68
+ error,
69
+ userDataFolder
70
+ });
71
+ }
72
+ }
73
+
74
+ async function start({ control, environment, profileName, isInPrivateMode }: {
75
+ control: WebView2Like;
76
+ environment: EnvironmentLike;
77
+ profileName: string | undefined;
78
+ isInPrivateMode: boolean;
79
+ }) {
80
+ const controllerOptions = environment.createCoreWebView2ControllerOptions();
81
+ const hasProfileName = profileName !== undefined;
82
+ if (hasProfileName) {
83
+ controllerOptions.profileName = profileName;
84
+ }
85
+
86
+ controllerOptions.isInPrivateModeEnabled = isInPrivateMode;
87
+ try {
88
+ await control.ensureCoreWebView2Async(environment, controllerOptions);
89
+ } catch (error) {
90
+ throw explainFailure({
91
+ error,
92
+ userDataFolder: environment.userDataFolder
93
+ });
94
+ }
95
+
96
+ return control.coreWebView2;
97
+ }
98
+
99
+ /**
100
+ * Starts the control's browser in `environment`, with the profile
101
+ * `profileName` of its folder, and resolves with the `CoreWebView2`
102
+ * The first start of a control wins: call this before anything that starts it
103
+ * with the default environment (`waitForCoreWebView2` and every helper that
104
+ * calls it); a second call resolves with the same core and starts nothing
105
+ * The control must be in a window for the browser to start
106
+ *
107
+ * @param options - The control, its environment, the profile and the private mode.
108
+ * @returns The control's `CoreWebView2`.
109
+ */
110
+ export function startWebView2({ control, environment, profileName, isInPrivateMode = false }: {
111
+ control: WebView2Like;
112
+ environment: EnvironmentLike;
113
+ profileName?: string;
114
+ isInPrivateMode?: boolean;
115
+ }) {
116
+ const existing = started.get(control);
117
+ const isStarted = existing !== undefined;
118
+ if (isStarted) {
119
+ return existing;
120
+ }
121
+
122
+ const pending = start({
123
+ control,
124
+ environment,
125
+ profileName,
126
+ isInPrivateMode
127
+ });
128
+ started.set(control, pending);
129
+ pending.catch(() => started.delete(control));
130
+ return pending;
131
+ }
@@ -2,13 +2,24 @@
2
2
  // Opt-in: nothing here loads until it is imported.
3
3
 
4
4
  export type {
5
+ ControllerOptionsLike,
5
6
  CoreWebView2Like,
7
+ EnvironmentLike,
8
+ ProcessFailedArguments,
6
9
  WebView2Like
7
10
  } from "./core.ts";
8
11
  export { addDocumentCreatedScript, executeScript, openDevTools, waitForCoreWebView2 } from "./core.ts";
12
+ export type { WebView2EnvironmentInit } from "./environment.ts";
13
+ export { createWebView2Environment, startWebView2 } from "./environment.ts";
9
14
  export type { Cookie, CookieInit } from "./cookies.ts";
10
15
  export { CookieSameSite, deleteCookie, getCookies, setCookie } from "./cookies.ts";
11
16
  export type { PermissionRequest } from "./policy.ts";
12
17
  export { onDownloadStarting, onNavigationStarting, onPermissionRequested, PermissionKind, PermissionState } from "./policy.ts";
13
18
  export type { WebView2Transport } from "./transport.ts";
14
19
  export { webView2Transport } from "./transport.ts";
20
+ export type { RequestFilter, WebRequest, WebResponse } from "./requests.ts";
21
+ export { blockRequests, onWebResourceRequested, ResourceContext, StatusCode } from "./requests.ts";
22
+ export { callDevToolsMethod, onDevToolsEvent } from "./protocol.ts";
23
+ export { dispatchKey, dispatchMouseClick, keyEventParameters, KeyEventType, MouseButton, TypeMode, typeText } from "./input.ts";
24
+ export type { WebView2Guard } from "./recovery.ts";
25
+ export { keepWebView2Alive, ProcessFailureKind } from "./recovery.ts";
@@ -0,0 +1,154 @@
1
+ import type { WebView2Like } from "./core.ts";
2
+ import { callDevToolsMethod } from "./protocol.ts";
3
+
4
+ /** The kind of a key event. */
5
+ export const KeyEventType = {
6
+ KEY_DOWN: "keyDown",
7
+ KEY_UP: "keyUp",
8
+ RAW_KEY_DOWN: "rawKeyDown",
9
+ CHAR: "char"
10
+ } as const;
11
+ /** One of the values of `KeyEventType`. */
12
+ export type KeyEventType = (typeof KeyEventType)[keyof typeof KeyEventType];
13
+
14
+ /** The mouse button of a click. */
15
+ export const MouseButton = {
16
+ LEFT: "left",
17
+ MIDDLE: "middle",
18
+ RIGHT: "right"
19
+ } as const;
20
+ /** One of the values of `MouseButton`. */
21
+ export type MouseButton = (typeof MouseButton)[keyof typeof MouseButton];
22
+
23
+ /** How `typeText` enters the text. */
24
+ export const TypeMode = {
25
+ /** A key down and a key up for every character. */
26
+ KEYS: "keys",
27
+ /** The first character as keys, the rest in one `Input.insertText`. */
28
+ INSERT_AFTER_FIRST: "insertAfterFirst"
29
+ } as const;
30
+ /** One of the values of `TypeMode`. */
31
+ export type TypeMode = (typeof TypeMode)[keyof typeof TypeMode];
32
+
33
+ const DISPATCH_KEY_EVENT = "Input.dispatchKeyEvent";
34
+ const DISPATCH_MOUSE_EVENT = "Input.dispatchMouseEvent";
35
+ const INSERT_TEXT = "Input.insertText";
36
+ const TEXT_KEY_TYPES = new Set<KeyEventType>([KeyEventType.KEY_DOWN, KeyEventType.CHAR]);
37
+
38
+ /** The parameters of `Input.dispatchKeyEvent`, built in one place. */
39
+ export function keyEventParameters({ type, key, text, modifiers = 0 }: {
40
+ type: KeyEventType;
41
+ key: string;
42
+ text?: string;
43
+ modifiers?: number;
44
+ }) {
45
+ const isSingleCharacter = Array.from(key).length === 1;
46
+ const typed = text ?? (isSingleCharacter ? key : undefined);
47
+ const hasText = typed !== undefined && TEXT_KEY_TYPES.has(type);
48
+ return {
49
+ type,
50
+ key,
51
+ modifiers,
52
+ ...hasText ? { text: typed } : {}
53
+ };
54
+ }
55
+
56
+ /** The parameters of `Input.dispatchMouseEvent`. */
57
+ function mouseEventParameters({ type, x, y, button, clickCount }: {
58
+ type: "mousePressed" | "mouseReleased" | "mouseMoved";
59
+ x: number;
60
+ y: number;
61
+ button: MouseButton;
62
+ clickCount: number;
63
+ }) {
64
+ return {
65
+ type,
66
+ x,
67
+ y,
68
+ button,
69
+ clickCount
70
+ };
71
+ }
72
+
73
+ /**
74
+ * Sends one trusted key event to the page; `text` defaults to `key` when it is
75
+ * one character
76
+ */
77
+ export async function dispatchKey({ control, key, type, text, modifiers }: {
78
+ control: WebView2Like;
79
+ key: string;
80
+ type: KeyEventType;
81
+ text?: string;
82
+ modifiers?: number;
83
+ }) {
84
+ await callDevToolsMethod({
85
+ control,
86
+ method: DISPATCH_KEY_EVENT,
87
+ parameters: keyEventParameters({
88
+ type,
89
+ key,
90
+ ...text === undefined ? {} : { text },
91
+ ...modifiers === undefined ? {} : { modifiers }
92
+ })
93
+ });
94
+ }
95
+
96
+ /** Sends a trusted mouse click (press and release) at a point of the page, in CSS pixels. */
97
+ export async function dispatchMouseClick({ control, x, y, button = MouseButton.LEFT, clickCount = 1 }: {
98
+ control: WebView2Like;
99
+ x: number;
100
+ y: number;
101
+ button?: MouseButton;
102
+ clickCount?: number;
103
+ }) {
104
+ function send(type: "mousePressed" | "mouseReleased") {
105
+ return callDevToolsMethod({
106
+ control,
107
+ method: DISPATCH_MOUSE_EVENT,
108
+ parameters: mouseEventParameters({
109
+ type,
110
+ x,
111
+ y,
112
+ button,
113
+ clickCount
114
+ })
115
+ });
116
+ }
117
+
118
+ await Promise.all([send("mousePressed"), send("mouseReleased")]);
119
+ }
120
+
121
+ /**
122
+ * Types `text` into the focused element with trusted key events, a character
123
+ * at a time (the key down and up go out together, in order)
124
+ */
125
+ export async function typeText({ control, text, mode = TypeMode.KEYS }: {
126
+ control: WebView2Like;
127
+ text: string;
128
+ mode?: TypeMode;
129
+ }) {
130
+ const characters = Array.from(text);
131
+ const isInsertingRest = mode === TypeMode.INSERT_AFTER_FIRST;
132
+ const keyed = isInsertingRest ? characters.slice(0, 1) : characters;
133
+ for (const character of keyed) {
134
+ await Promise.all(
135
+ [KeyEventType.KEY_DOWN, KeyEventType.KEY_UP].map(type => dispatchKey({
136
+ control,
137
+ key: character,
138
+ type
139
+ }))
140
+ );
141
+ }
142
+
143
+ const rest = characters.slice(1).join("");
144
+ const hasRest = isInsertingRest && rest !== "";
145
+ if (hasRest) {
146
+ await callDevToolsMethod({
147
+ control,
148
+ method: INSERT_TEXT,
149
+ parameters: {
150
+ text: rest
151
+ }
152
+ });
153
+ }
154
+ }
@@ -0,0 +1,41 @@
1
+ import { messageOf, waitForCoreWebView2 } from "./core.ts";
2
+ import type { WebView2Like } from "./core.ts";
3
+ import { jsonSchema } from "#src/messaging/json.js";
4
+ import type { Json } from "#src/messaging/json.js";
5
+
6
+ /**
7
+ * Calls a DevTools protocol method on the page and resolves with its result
8
+ * as JSON, checked; rejects with the protocol's error text
9
+ */
10
+ export async function callDevToolsMethod({ control, method, parameters = {} }: {
11
+ control: WebView2Like;
12
+ method: string;
13
+ parameters?: Readonly<Record<string, unknown>>;
14
+ }) {
15
+ const core = await waitForCoreWebView2(control);
16
+ try {
17
+ const text = await core.callDevToolsProtocolMethodAsync(method, JSON.stringify(parameters));
18
+ return jsonSchema.parse(JSON.parse(text));
19
+ } catch (error) {
20
+ throw new Error(`${method}: ${messageOf(error)}`, { cause: error });
21
+ }
22
+ }
23
+
24
+ /**
25
+ * Hands the parameters of every `event` of the DevTools protocol to `handler`
26
+ * as JSON, checked; resolves with the function that stops it
27
+ * The browser raises an event only after its domain is enabled
28
+ * (`callDevToolsMethod({ method: "Network.enable" })`), and an event still
29
+ * subscribed keeps the process from exiting
30
+ */
31
+ export async function onDevToolsEvent({ control, event, handler }: {
32
+ control: WebView2Like;
33
+ event: string;
34
+ handler(parameters: Json): void;
35
+ }) {
36
+ const core = await waitForCoreWebView2(control);
37
+ const receiver = core.getDevToolsProtocolEventReceiver(event);
38
+ return receiver.onDevToolsProtocolEventReceived((_sender, args) => {
39
+ handler(jsonSchema.parse(JSON.parse(args.parameterObjectAsJson)));
40
+ });
41
+ }
@@ -0,0 +1,177 @@
1
+ import { messageOf, waitForCoreWebView2 } from "./core.ts";
2
+ import type { CoreWebView2Like, WebView2Like } from "./core.ts";
3
+ import { CoreWebView2ProcessFailedKind } from "#winui/microsoft/web/web-view2/core/CoreWebView2ProcessFailedKind";
4
+
5
+ /** What went wrong in the browser, as `keepWebView2Alive` tells the app. */
6
+ export const ProcessFailureKind = {
7
+ BROWSER_EXITED: "browserExited",
8
+ RENDER_EXITED: "renderExited",
9
+ UNRESPONSIVE: "unresponsive",
10
+ OTHER: "other"
11
+ } as const;
12
+ /** One of the values of `ProcessFailureKind`. */
13
+ export type ProcessFailureKind = (typeof ProcessFailureKind)[keyof typeof ProcessFailureKind];
14
+
15
+ const KINDS = new Map<number, ProcessFailureKind>([
16
+ [CoreWebView2ProcessFailedKind.BrowserProcessExited, ProcessFailureKind.BROWSER_EXITED],
17
+ [CoreWebView2ProcessFailedKind.RenderProcessExited, ProcessFailureKind.RENDER_EXITED],
18
+ [CoreWebView2ProcessFailedKind.FrameRenderProcessExited, ProcessFailureKind.RENDER_EXITED],
19
+ [CoreWebView2ProcessFailedKind.RenderProcessUnresponsive, ProcessFailureKind.UNRESPONSIVE]
20
+ ]);
21
+ const DEFAULT_MAX_CRASHES = 3;
22
+ const DEFAULT_WINDOW_MILLISECONDS = 30_000;
23
+
24
+ /** The control that `keepWebView2Alive` watches, and the means to stop or restart it. */
25
+ export interface WebView2Guard {
26
+ /**
27
+ * Tries again after the guard gave up (`onGaveUp`): forgets the failures
28
+ * so far and rebuilds the control, as for a browser that exited
29
+ * Does nothing while a recovery is running or after `dispose`
30
+ */
31
+ retry(): Promise<void>;
32
+ /** Stops listening; a recovery already running finishes. */
33
+ dispose(): void;
34
+ }
35
+
36
+ function quietly(action: () => void) {
37
+ try {
38
+ action();
39
+ } catch {
40
+ // A dead core may throw while its handler is removed; there is nothing left to undo
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Keeps a `WebView2` working through the browser's crashes, with no action
46
+ * from the user
47
+ *
48
+ * It runs `setup` with the core of `control`, then watches the control's
49
+ * `CoreProcessFailed`:
50
+ *
51
+ * - the browser process exiting leaves the control dead, so it calls
52
+ * `rebuild`, which must resolve with a new control that is already
53
+ * started (`startWebView2`), then runs `setup` with the new core
54
+ * - any other process failing (a renderer, a utility process) reloads the
55
+ * page in place
56
+ * - more than `maxCrashes` failures within `windowMilliseconds` stop the
57
+ * loop: `onGaveUp` is called once, and nothing more happens until
58
+ * `retry()`
59
+ * - a failure while a recovery is running is ignored, so one is never run twice
60
+ *
61
+ * Everything bound to the old core is lost with it: scripts from
62
+ * `addDocumentCreatedScript`, the handlers (`onNavigationStarting`,
63
+ * `onPermissionRequested`, `onWebResourceRequested`), a `webView2Transport`
64
+ * and its messaging; put them in `setup`, which runs again after every rebuild
65
+ * Cookies and storage live in the profile folder and survive; a page that is
66
+ * only reloaded keeps the scripts and handlers, and loses its own state
67
+ *
68
+ * A failure of `rebuild` or `setup` gives up, with the error's text as the
69
+ * reason
70
+ *
71
+ * @param options - The control and the policy.
72
+ * @returns The guard.
73
+ */
74
+ export function keepWebView2Alive({
75
+ control,
76
+ setup,
77
+ rebuild,
78
+ maxCrashes = DEFAULT_MAX_CRASHES,
79
+ windowMilliseconds = DEFAULT_WINDOW_MILLISECONDS,
80
+ onRecovering,
81
+ onGaveUp
82
+ }: {
83
+ control: WebView2Like;
84
+ setup(core: CoreWebView2Like): void | Promise<void>;
85
+ rebuild(): Promise<WebView2Like>;
86
+ maxCrashes?: number;
87
+ windowMilliseconds?: number;
88
+ onRecovering?(failure: { readonly kind: ProcessFailureKind }): void;
89
+ onGaveUp?(failure: { readonly reason: string }): void;
90
+ }) {
91
+ let current = control;
92
+ let unsubscribe: (() => void) | undefined;
93
+ let failures: number[] = [];
94
+ let isRecovering = false;
95
+ let isGivenUp = false;
96
+ let isDisposed = false;
97
+
98
+ function giveUp(reason: string) {
99
+ isGivenUp = true;
100
+ onGaveUp?.({ reason });
101
+ }
102
+
103
+ function watch(next: WebView2Like) {
104
+ current = next;
105
+ unsubscribe = next.onCoreProcessFailed((_sender, args) => {
106
+ void recover(KINDS.get(args.processFailedKind) ?? ProcessFailureKind.OTHER);
107
+ });
108
+ }
109
+
110
+ async function run(kind: ProcessFailureKind) {
111
+ const isRebuild = kind === ProcessFailureKind.BROWSER_EXITED;
112
+ if (!isRebuild) {
113
+ (await waitForCoreWebView2(current)).reload();
114
+ return;
115
+ }
116
+
117
+ quietly(() => unsubscribe?.());
118
+ watch(await rebuild());
119
+ await setup(await waitForCoreWebView2(current));
120
+ }
121
+
122
+ async function recover(kind: ProcessFailureKind) {
123
+ const isIgnored = isDisposed || isGivenUp || isRecovering;
124
+ if (isIgnored) {
125
+ return;
126
+ }
127
+
128
+ const now = Date.now();
129
+ failures = [...failures.filter(failedAt => now - failedAt < windowMilliseconds), now];
130
+ const isStreak = failures.length > maxCrashes;
131
+ if (isStreak) {
132
+ giveUp(`${failures.length} failures within ${windowMilliseconds} ms`);
133
+ return;
134
+ }
135
+
136
+ isRecovering = true;
137
+ onRecovering?.({ kind });
138
+ try {
139
+ await run(kind);
140
+ } catch (error) {
141
+ giveUp(messageOf(error));
142
+ } finally {
143
+ isRecovering = false;
144
+ }
145
+ }
146
+
147
+ async function start() {
148
+ isRecovering = true;
149
+ watch(control);
150
+ try {
151
+ await setup(await waitForCoreWebView2(control));
152
+ } catch (error) {
153
+ giveUp(messageOf(error));
154
+ } finally {
155
+ isRecovering = false;
156
+ }
157
+ }
158
+
159
+ void start();
160
+ const guard: WebView2Guard = {
161
+ async retry() {
162
+ const isBusy = isDisposed || isRecovering;
163
+ if (isBusy) {
164
+ return;
165
+ }
166
+
167
+ isGivenUp = false;
168
+ failures = [];
169
+ await recover(ProcessFailureKind.BROWSER_EXITED);
170
+ },
171
+ dispose() {
172
+ isDisposed = true;
173
+ quietly(() => unsubscribe?.());
174
+ }
175
+ };
176
+ return guard;
177
+ }