window.cjs 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171
  1. 'use strict';
  2. var tauri = require('./helpers/tauri.cjs');
  3. var event = require('./helpers/event.cjs');
  4. var event$1 = require('./event.cjs');
  5. // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
  6. // SPDX-License-Identifier: Apache-2.0
  7. // SPDX-License-Identifier: MIT
  8. /**
  9. * Provides APIs to create windows, communicate with other windows and manipulate the current window.
  10. *
  11. * This package is also accessible with `window.__TAURI__.window` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
  12. *
  13. * The APIs must be added to [`tauri.allowlist.window`](https://tauri.app/v1/api/config/#allowlistconfig.window) in `tauri.conf.json`:
  14. * ```json
  15. * {
  16. * "tauri": {
  17. * "allowlist": {
  18. * "window": {
  19. * "all": true, // enable all window APIs
  20. * "create": true, // enable window creation
  21. * "center": true,
  22. * "requestUserAttention": true,
  23. * "setResizable": true,
  24. * "setMaximizable": true,
  25. * "setMinimizable": true,
  26. * "setClosable": true,
  27. * "setTitle": true,
  28. * "maximize": true,
  29. * "unmaximize": true,
  30. * "minimize": true,
  31. * "unminimize": true,
  32. * "show": true,
  33. * "hide": true,
  34. * "close": true,
  35. * "setDecorations": true,
  36. * "setAlwaysOnTop": true,
  37. * "setContentProtected": true,
  38. * "setSize": true,
  39. * "setMinSize": true,
  40. * "setMaxSize": true,
  41. * "setPosition": true,
  42. * "setFullscreen": true,
  43. * "setFocus": true,
  44. * "setIcon": true,
  45. * "setSkipTaskbar": true,
  46. * "setCursorGrab": true,
  47. * "setCursorVisible": true,
  48. * "setCursorIcon": true,
  49. * "setCursorPosition": true,
  50. * "setIgnoreCursorEvents": true,
  51. * "startDragging": true,
  52. * "print": true
  53. * }
  54. * }
  55. * }
  56. * }
  57. * ```
  58. * It is recommended to allowlist only the APIs you use for optimal bundle size and security.
  59. *
  60. * ## Window events
  61. *
  62. * Events can be listened to using `appWindow.listen`:
  63. * ```typescript
  64. * import { appWindow } from "@tauri-apps/api/window";
  65. * appWindow.listen("my-window-event", ({ event, payload }) => { });
  66. * ```
  67. *
  68. * @module
  69. */
  70. /**
  71. * A size represented in logical pixels.
  72. *
  73. * @since 1.0.0
  74. */
  75. class LogicalSize {
  76. constructor(width, height) {
  77. this.type = 'Logical';
  78. this.width = width;
  79. this.height = height;
  80. }
  81. }
  82. /**
  83. * A size represented in physical pixels.
  84. *
  85. * @since 1.0.0
  86. */
  87. class PhysicalSize {
  88. constructor(width, height) {
  89. this.type = 'Physical';
  90. this.width = width;
  91. this.height = height;
  92. }
  93. /**
  94. * Converts the physical size to a logical one.
  95. * @example
  96. * ```typescript
  97. * import { appWindow } from '@tauri-apps/api/window';
  98. * const factor = await appWindow.scaleFactor();
  99. * const size = await appWindow.innerSize();
  100. * const logical = size.toLogical(factor);
  101. * ```
  102. * */
  103. toLogical(scaleFactor) {
  104. return new LogicalSize(this.width / scaleFactor, this.height / scaleFactor);
  105. }
  106. }
  107. /**
  108. * A position represented in logical pixels.
  109. *
  110. * @since 1.0.0
  111. */
  112. class LogicalPosition {
  113. constructor(x, y) {
  114. this.type = 'Logical';
  115. this.x = x;
  116. this.y = y;
  117. }
  118. }
  119. /**
  120. * A position represented in physical pixels.
  121. *
  122. * @since 1.0.0
  123. */
  124. class PhysicalPosition {
  125. constructor(x, y) {
  126. this.type = 'Physical';
  127. this.x = x;
  128. this.y = y;
  129. }
  130. /**
  131. * Converts the physical position to a logical one.
  132. * @example
  133. * ```typescript
  134. * import { appWindow } from '@tauri-apps/api/window';
  135. * const factor = await appWindow.scaleFactor();
  136. * const position = await appWindow.innerPosition();
  137. * const logical = position.toLogical(factor);
  138. * ```
  139. * */
  140. toLogical(scaleFactor) {
  141. return new LogicalPosition(this.x / scaleFactor, this.y / scaleFactor);
  142. }
  143. }
  144. /**
  145. * Attention type to request on a window.
  146. *
  147. * @since 1.0.0
  148. */
  149. exports.UserAttentionType = void 0;
  150. (function (UserAttentionType) {
  151. /**
  152. * #### Platform-specific
  153. * - **macOS:** Bounces the dock icon until the application is in focus.
  154. * - **Windows:** Flashes both the window and the taskbar button until the application is in focus.
  155. */
  156. UserAttentionType[UserAttentionType["Critical"] = 1] = "Critical";
  157. /**
  158. * #### Platform-specific
  159. * - **macOS:** Bounces the dock icon once.
  160. * - **Windows:** Flashes the taskbar button until the application is in focus.
  161. */
  162. UserAttentionType[UserAttentionType["Informational"] = 2] = "Informational";
  163. })(exports.UserAttentionType || (exports.UserAttentionType = {}));
  164. /**
  165. * Get an instance of `WebviewWindow` for the current webview window.
  166. *
  167. * @since 1.0.0
  168. */
  169. function getCurrent() {
  170. return new WebviewWindow(window.__TAURI_METADATA__.__currentWindow.label, {
  171. // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
  172. skip: true
  173. });
  174. }
  175. /**
  176. * Gets a list of instances of `WebviewWindow` for all available webview windows.
  177. *
  178. * @since 1.0.0
  179. */
  180. function getAll() {
  181. return window.__TAURI_METADATA__.__windows.map((w) => new WebviewWindow(w.label, {
  182. // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
  183. skip: true
  184. }));
  185. }
  186. /** @ignore */
  187. // events that are emitted right here instead of by the created webview
  188. const localTauriEvents = ['tauri://created', 'tauri://error'];
  189. /**
  190. * A webview window handle allows emitting and listening to events from the backend that are tied to the window.
  191. *
  192. * @ignore
  193. * @since 1.0.0
  194. */
  195. class WebviewWindowHandle {
  196. constructor(label) {
  197. this.label = label;
  198. // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
  199. this.listeners = Object.create(null);
  200. }
  201. /**
  202. * Listen to an event emitted by the backend or webview.
  203. * The event must either be a global event or an event targetting this window.
  204. *
  205. * See {@link WebviewWindow.emit | `emit`} for more information.
  206. *
  207. * @example
  208. * ```typescript
  209. * import { appWindow } from '@tauri-apps/api/window';
  210. * const unlisten = await appWindow.listen<string>('state-changed', (event) => {
  211. * console.log(`Got error: ${payload}`);
  212. * });
  213. *
  214. * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
  215. * unlisten();
  216. * ```
  217. *
  218. * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
  219. *
  220. * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
  221. * @param handler Event handler.
  222. * @returns A promise resolving to a function to unlisten to the event.
  223. */
  224. async listen(event$1, handler) {
  225. if (this._handleTauriEvent(event$1, handler)) {
  226. return Promise.resolve(() => {
  227. // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, security/detect-object-injection
  228. const listeners = this.listeners[event$1];
  229. listeners.splice(listeners.indexOf(handler), 1);
  230. });
  231. }
  232. return event.listen(event$1, this.label, handler);
  233. }
  234. /**
  235. * Listen to an one-off event.
  236. * See {@link WebviewWindow.listen | `listen`} for more information.
  237. *
  238. * @example
  239. * ```typescript
  240. * import { appWindow } from '@tauri-apps/api/window';
  241. * const unlisten = await appWindow.once<null>('initialized', (event) => {
  242. * console.log(`Window initialized!`);
  243. * });
  244. *
  245. * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
  246. * unlisten();
  247. * ```
  248. *
  249. * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
  250. *
  251. * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
  252. * @param handler Event handler.
  253. * @returns A promise resolving to a function to unlisten to the event.
  254. */
  255. async once(event$1, handler) {
  256. if (this._handleTauriEvent(event$1, handler)) {
  257. return Promise.resolve(() => {
  258. // eslint-disable-next-line security/detect-object-injection
  259. const listeners = this.listeners[event$1];
  260. listeners.splice(listeners.indexOf(handler), 1);
  261. });
  262. }
  263. return event.once(event$1, this.label, handler);
  264. }
  265. /**
  266. * Emits an event to the backend and all Tauri windows.
  267. * The event will have this window's {@link WebviewWindow.label | label} as {@link Event.windowLabel | source window label}.
  268. *
  269. * @example
  270. * ```typescript
  271. * import { appWindow } from '@tauri-apps/api/window';
  272. * await appWindow.emit('window-loaded', { loggedIn: true, token: 'authToken' });
  273. * ```
  274. *
  275. * This function can also be used to communicate between windows:
  276. * ```typescript
  277. * import { appWindow } from '@tauri-apps/api/window';
  278. * await appWindow.listen('sync-data', (event) => { });
  279. *
  280. * // on another window...
  281. * import { WebviewWindow } from '@tauri-apps/api/window';
  282. * const otherWindow = WebviewWindow.getByLabel('other')
  283. * await otherWindow.emit('sync-data');
  284. * ```
  285. *
  286. * Global listeners are also triggered:
  287. * ```typescript
  288. * import { appWindow } from '@tauri-apps/api/window';
  289. * import { listen } from '@tauri-apps/api/event';
  290. * await listen('ping', (event) => { });
  291. *
  292. * await appWindow.emit('ping');
  293. * ```
  294. *
  295. * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
  296. * @param payload Event payload.
  297. */
  298. async emit(event$1, payload) {
  299. if (localTauriEvents.includes(event$1)) {
  300. // eslint-disable-next-line
  301. for (const handler of this.listeners[event$1] || []) {
  302. handler({ event: event$1, id: -1, windowLabel: this.label, payload });
  303. }
  304. return Promise.resolve();
  305. }
  306. return event.emit(event$1, this.label, payload);
  307. }
  308. /** @ignore */
  309. _handleTauriEvent(event, handler) {
  310. if (localTauriEvents.includes(event)) {
  311. if (!(event in this.listeners)) {
  312. // eslint-disable-next-line
  313. this.listeners[event] = [handler];
  314. }
  315. else {
  316. // eslint-disable-next-line
  317. this.listeners[event].push(handler);
  318. }
  319. return true;
  320. }
  321. return false;
  322. }
  323. }
  324. /**
  325. * Manage the current window object.
  326. *
  327. * @ignore
  328. * @since 1.0.0
  329. */
  330. class WindowManager extends WebviewWindowHandle {
  331. // Getters
  332. /**
  333. * The scale factor that can be used to map physical pixels to logical pixels.
  334. * @example
  335. * ```typescript
  336. * import { appWindow } from '@tauri-apps/api/window';
  337. * const factor = await appWindow.scaleFactor();
  338. * ```
  339. *
  340. * @returns The window's monitor scale factor.
  341. * */
  342. async scaleFactor() {
  343. return tauri.invokeTauriCommand({
  344. __tauriModule: 'Window',
  345. message: {
  346. cmd: 'manage',
  347. data: {
  348. label: this.label,
  349. cmd: {
  350. type: 'scaleFactor'
  351. }
  352. }
  353. }
  354. });
  355. }
  356. /**
  357. * The position of the top-left hand corner of the window's client area relative to the top-left hand corner of the desktop.
  358. * @example
  359. * ```typescript
  360. * import { appWindow } from '@tauri-apps/api/window';
  361. * const position = await appWindow.innerPosition();
  362. * ```
  363. *
  364. * @returns The window's inner position.
  365. * */
  366. async innerPosition() {
  367. return tauri.invokeTauriCommand({
  368. __tauriModule: 'Window',
  369. message: {
  370. cmd: 'manage',
  371. data: {
  372. label: this.label,
  373. cmd: {
  374. type: 'innerPosition'
  375. }
  376. }
  377. }
  378. }).then(({ x, y }) => new PhysicalPosition(x, y));
  379. }
  380. /**
  381. * The position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.
  382. * @example
  383. * ```typescript
  384. * import { appWindow } from '@tauri-apps/api/window';
  385. * const position = await appWindow.outerPosition();
  386. * ```
  387. *
  388. * @returns The window's outer position.
  389. * */
  390. async outerPosition() {
  391. return tauri.invokeTauriCommand({
  392. __tauriModule: 'Window',
  393. message: {
  394. cmd: 'manage',
  395. data: {
  396. label: this.label,
  397. cmd: {
  398. type: 'outerPosition'
  399. }
  400. }
  401. }
  402. }).then(({ x, y }) => new PhysicalPosition(x, y));
  403. }
  404. /**
  405. * The physical size of the window's client area.
  406. * The client area is the content of the window, excluding the title bar and borders.
  407. * @example
  408. * ```typescript
  409. * import { appWindow } from '@tauri-apps/api/window';
  410. * const size = await appWindow.innerSize();
  411. * ```
  412. *
  413. * @returns The window's inner size.
  414. */
  415. async innerSize() {
  416. return tauri.invokeTauriCommand({
  417. __tauriModule: 'Window',
  418. message: {
  419. cmd: 'manage',
  420. data: {
  421. label: this.label,
  422. cmd: {
  423. type: 'innerSize'
  424. }
  425. }
  426. }
  427. }).then(({ width, height }) => new PhysicalSize(width, height));
  428. }
  429. /**
  430. * The physical size of the entire window.
  431. * These dimensions include the title bar and borders. If you don't want that (and you usually don't), use inner_size instead.
  432. * @example
  433. * ```typescript
  434. * import { appWindow } from '@tauri-apps/api/window';
  435. * const size = await appWindow.outerSize();
  436. * ```
  437. *
  438. * @returns The window's outer size.
  439. */
  440. async outerSize() {
  441. return tauri.invokeTauriCommand({
  442. __tauriModule: 'Window',
  443. message: {
  444. cmd: 'manage',
  445. data: {
  446. label: this.label,
  447. cmd: {
  448. type: 'outerSize'
  449. }
  450. }
  451. }
  452. }).then(({ width, height }) => new PhysicalSize(width, height));
  453. }
  454. /**
  455. * Gets the window's current fullscreen state.
  456. * @example
  457. * ```typescript
  458. * import { appWindow } from '@tauri-apps/api/window';
  459. * const fullscreen = await appWindow.isFullscreen();
  460. * ```
  461. *
  462. * @returns Whether the window is in fullscreen mode or not.
  463. * */
  464. async isFullscreen() {
  465. return tauri.invokeTauriCommand({
  466. __tauriModule: 'Window',
  467. message: {
  468. cmd: 'manage',
  469. data: {
  470. label: this.label,
  471. cmd: {
  472. type: 'isFullscreen'
  473. }
  474. }
  475. }
  476. });
  477. }
  478. /**
  479. * Gets the window's current minimized state.
  480. * @example
  481. * ```typescript
  482. * import { appWindow } from '@tauri-apps/api/window';
  483. * const minimized = await appWindow.isMinimized();
  484. * ```
  485. *
  486. * @since 1.3.0
  487. * */
  488. async isMinimized() {
  489. return tauri.invokeTauriCommand({
  490. __tauriModule: 'Window',
  491. message: {
  492. cmd: 'manage',
  493. data: {
  494. label: this.label,
  495. cmd: {
  496. type: 'isMinimized'
  497. }
  498. }
  499. }
  500. });
  501. }
  502. /**
  503. * Gets the window's current maximized state.
  504. * @example
  505. * ```typescript
  506. * import { appWindow } from '@tauri-apps/api/window';
  507. * const maximized = await appWindow.isMaximized();
  508. * ```
  509. *
  510. * @returns Whether the window is maximized or not.
  511. * */
  512. async isMaximized() {
  513. return tauri.invokeTauriCommand({
  514. __tauriModule: 'Window',
  515. message: {
  516. cmd: 'manage',
  517. data: {
  518. label: this.label,
  519. cmd: {
  520. type: 'isMaximized'
  521. }
  522. }
  523. }
  524. });
  525. }
  526. /**
  527. * Gets the window's current focus state.
  528. * @example
  529. * ```typescript
  530. * import { appWindow } from '@tauri-apps/api/window';
  531. * const focused = await appWindow.isFocused();
  532. * ```
  533. *
  534. * @returns Whether the window is focused or not.
  535. *
  536. * @since 1.4
  537. * */
  538. async isFocused() {
  539. return tauri.invokeTauriCommand({
  540. __tauriModule: 'Window',
  541. message: {
  542. cmd: 'manage',
  543. data: {
  544. label: this.label,
  545. cmd: {
  546. type: 'isFocused'
  547. }
  548. }
  549. }
  550. });
  551. }
  552. /**
  553. * Gets the window's current decorated state.
  554. * @example
  555. * ```typescript
  556. * import { appWindow } from '@tauri-apps/api/window';
  557. * const decorated = await appWindow.isDecorated();
  558. * ```
  559. *
  560. * @returns Whether the window is decorated or not.
  561. * */
  562. async isDecorated() {
  563. return tauri.invokeTauriCommand({
  564. __tauriModule: 'Window',
  565. message: {
  566. cmd: 'manage',
  567. data: {
  568. label: this.label,
  569. cmd: {
  570. type: 'isDecorated'
  571. }
  572. }
  573. }
  574. });
  575. }
  576. /**
  577. * Gets the window's current resizable state.
  578. * @example
  579. * ```typescript
  580. * import { appWindow } from '@tauri-apps/api/window';
  581. * const resizable = await appWindow.isResizable();
  582. * ```
  583. *
  584. * @returns Whether the window is resizable or not.
  585. * */
  586. async isResizable() {
  587. return tauri.invokeTauriCommand({
  588. __tauriModule: 'Window',
  589. message: {
  590. cmd: 'manage',
  591. data: {
  592. label: this.label,
  593. cmd: {
  594. type: 'isResizable'
  595. }
  596. }
  597. }
  598. });
  599. }
  600. /**
  601. * Gets the window’s native maximize button state.
  602. *
  603. * #### Platform-specific
  604. *
  605. * - **Linux / iOS / Android:** Unsupported.
  606. *
  607. * @example
  608. * ```typescript
  609. * import { appWindow } from '@tauri-apps/api/window';
  610. * const maximizable = await appWindow.isMaximizable();
  611. * ```
  612. *
  613. * @returns Whether the window's native maximize button is enabled or not.
  614. * */
  615. async isMaximizable() {
  616. return tauri.invokeTauriCommand({
  617. __tauriModule: 'Window',
  618. message: {
  619. cmd: 'manage',
  620. data: {
  621. label: this.label,
  622. cmd: {
  623. type: 'isMaximizable'
  624. }
  625. }
  626. }
  627. });
  628. }
  629. /**
  630. * Gets the window’s native minimize button state.
  631. *
  632. * #### Platform-specific
  633. *
  634. * - **Linux / iOS / Android:** Unsupported.
  635. *
  636. * @example
  637. * ```typescript
  638. * import { appWindow } from '@tauri-apps/api/window';
  639. * const minimizable = await appWindow.isMinimizable();
  640. * ```
  641. *
  642. * @returns Whether the window's native minimize button is enabled or not.
  643. * */
  644. async isMinimizable() {
  645. return tauri.invokeTauriCommand({
  646. __tauriModule: 'Window',
  647. message: {
  648. cmd: 'manage',
  649. data: {
  650. label: this.label,
  651. cmd: {
  652. type: 'isMinimizable'
  653. }
  654. }
  655. }
  656. });
  657. }
  658. /**
  659. * Gets the window’s native close button state.
  660. *
  661. * #### Platform-specific
  662. *
  663. * - **Linux / iOS / Android:** Unsupported.
  664. *
  665. * @example
  666. * ```typescript
  667. * import { appWindow } from '@tauri-apps/api/window';
  668. * const closable = await appWindow.isClosable();
  669. * ```
  670. *
  671. * @returns Whether the window's native close button is enabled or not.
  672. * */
  673. async isClosable() {
  674. return tauri.invokeTauriCommand({
  675. __tauriModule: 'Window',
  676. message: {
  677. cmd: 'manage',
  678. data: {
  679. label: this.label,
  680. cmd: {
  681. type: 'isClosable'
  682. }
  683. }
  684. }
  685. });
  686. }
  687. /**
  688. * Gets the window's current visible state.
  689. * @example
  690. * ```typescript
  691. * import { appWindow } from '@tauri-apps/api/window';
  692. * const visible = await appWindow.isVisible();
  693. * ```
  694. *
  695. * @returns Whether the window is visible or not.
  696. * */
  697. async isVisible() {
  698. return tauri.invokeTauriCommand({
  699. __tauriModule: 'Window',
  700. message: {
  701. cmd: 'manage',
  702. data: {
  703. label: this.label,
  704. cmd: {
  705. type: 'isVisible'
  706. }
  707. }
  708. }
  709. });
  710. }
  711. /**
  712. * Gets the window's current title.
  713. * @example
  714. * ```typescript
  715. * import { appWindow } from '@tauri-apps/api/window';
  716. * const title = await appWindow.title();
  717. * ```
  718. *
  719. * @since 1.3.0
  720. * */
  721. async title() {
  722. return tauri.invokeTauriCommand({
  723. __tauriModule: 'Window',
  724. message: {
  725. cmd: 'manage',
  726. data: {
  727. label: this.label,
  728. cmd: {
  729. type: 'title'
  730. }
  731. }
  732. }
  733. });
  734. }
  735. /**
  736. * Gets the window's current theme.
  737. *
  738. * #### Platform-specific
  739. *
  740. * - **macOS:** Theme was introduced on macOS 10.14. Returns `light` on macOS 10.13 and below.
  741. *
  742. * @example
  743. * ```typescript
  744. * import { appWindow } from '@tauri-apps/api/window';
  745. * const theme = await appWindow.theme();
  746. * ```
  747. *
  748. * @returns The window theme.
  749. * */
  750. async theme() {
  751. return tauri.invokeTauriCommand({
  752. __tauriModule: 'Window',
  753. message: {
  754. cmd: 'manage',
  755. data: {
  756. label: this.label,
  757. cmd: {
  758. type: 'theme'
  759. }
  760. }
  761. }
  762. });
  763. }
  764. // Setters
  765. /**
  766. * Centers the window.
  767. * @example
  768. * ```typescript
  769. * import { appWindow } from '@tauri-apps/api/window';
  770. * await appWindow.center();
  771. * ```
  772. *
  773. * @returns A promise indicating the success or failure of the operation.
  774. */
  775. async center() {
  776. return tauri.invokeTauriCommand({
  777. __tauriModule: 'Window',
  778. message: {
  779. cmd: 'manage',
  780. data: {
  781. label: this.label,
  782. cmd: {
  783. type: 'center'
  784. }
  785. }
  786. }
  787. });
  788. }
  789. /**
  790. * Requests user attention to the window, this has no effect if the application
  791. * is already focused. How requesting for user attention manifests is platform dependent,
  792. * see `UserAttentionType` for details.
  793. *
  794. * Providing `null` will unset the request for user attention. Unsetting the request for
  795. * user attention might not be done automatically by the WM when the window receives input.
  796. *
  797. * #### Platform-specific
  798. *
  799. * - **macOS:** `null` has no effect.
  800. * - **Linux:** Urgency levels have the same effect.
  801. * @example
  802. * ```typescript
  803. * import { appWindow } from '@tauri-apps/api/window';
  804. * await appWindow.requestUserAttention();
  805. * ```
  806. *
  807. * @param requestType
  808. * @returns A promise indicating the success or failure of the operation.
  809. */
  810. async requestUserAttention(requestType) {
  811. let requestType_ = null;
  812. if (requestType) {
  813. if (requestType === exports.UserAttentionType.Critical) {
  814. requestType_ = { type: 'Critical' };
  815. }
  816. else {
  817. requestType_ = { type: 'Informational' };
  818. }
  819. }
  820. return tauri.invokeTauriCommand({
  821. __tauriModule: 'Window',
  822. message: {
  823. cmd: 'manage',
  824. data: {
  825. label: this.label,
  826. cmd: {
  827. type: 'requestUserAttention',
  828. payload: requestType_
  829. }
  830. }
  831. }
  832. });
  833. }
  834. /**
  835. * Updates the window resizable flag.
  836. * @example
  837. * ```typescript
  838. * import { appWindow } from '@tauri-apps/api/window';
  839. * await appWindow.setResizable(false);
  840. * ```
  841. *
  842. * @param resizable
  843. * @returns A promise indicating the success or failure of the operation.
  844. */
  845. async setResizable(resizable) {
  846. return tauri.invokeTauriCommand({
  847. __tauriModule: 'Window',
  848. message: {
  849. cmd: 'manage',
  850. data: {
  851. label: this.label,
  852. cmd: {
  853. type: 'setResizable',
  854. payload: resizable
  855. }
  856. }
  857. }
  858. });
  859. }
  860. /**
  861. * Sets whether the window's native maximize button is enabled or not.
  862. * If resizable is set to false, this setting is ignored.
  863. *
  864. * #### Platform-specific
  865. *
  866. * - **macOS:** Disables the "zoom" button in the window titlebar, which is also used to enter fullscreen mode.
  867. * - **Linux / iOS / Android:** Unsupported.
  868. *
  869. * @example
  870. * ```typescript
  871. * import { appWindow } from '@tauri-apps/api/window';
  872. * await appWindow.setMaximizable(false);
  873. * ```
  874. *
  875. * @param maximizable
  876. * @returns A promise indicating the success or failure of the operation.
  877. */
  878. async setMaximizable(maximizable) {
  879. return tauri.invokeTauriCommand({
  880. __tauriModule: 'Window',
  881. message: {
  882. cmd: 'manage',
  883. data: {
  884. label: this.label,
  885. cmd: {
  886. type: 'setMaximizable',
  887. payload: maximizable
  888. }
  889. }
  890. }
  891. });
  892. }
  893. /**
  894. * Sets whether the window's native minimize button is enabled or not.
  895. *
  896. * #### Platform-specific
  897. *
  898. * - **Linux / iOS / Android:** Unsupported.
  899. *
  900. * @example
  901. * ```typescript
  902. * import { appWindow } from '@tauri-apps/api/window';
  903. * await appWindow.setMinimizable(false);
  904. * ```
  905. *
  906. * @param minimizable
  907. * @returns A promise indicating the success or failure of the operation.
  908. */
  909. async setMinimizable(minimizable) {
  910. return tauri.invokeTauriCommand({
  911. __tauriModule: 'Window',
  912. message: {
  913. cmd: 'manage',
  914. data: {
  915. label: this.label,
  916. cmd: {
  917. type: 'setMinimizable',
  918. payload: minimizable
  919. }
  920. }
  921. }
  922. });
  923. }
  924. /**
  925. * Sets whether the window's native close button is enabled or not.
  926. *
  927. * #### Platform-specific
  928. *
  929. * - **Linux:** GTK+ will do its best to convince the window manager not to show a close button. Depending on the system, this function may not have any effect when called on a window that is already visible
  930. * - **iOS / Android:** Unsupported.
  931. *
  932. * @example
  933. * ```typescript
  934. * import { appWindow } from '@tauri-apps/api/window';
  935. * await appWindow.setClosable(false);
  936. * ```
  937. *
  938. * @param closable
  939. * @returns A promise indicating the success or failure of the operation.
  940. */
  941. async setClosable(closable) {
  942. return tauri.invokeTauriCommand({
  943. __tauriModule: 'Window',
  944. message: {
  945. cmd: 'manage',
  946. data: {
  947. label: this.label,
  948. cmd: {
  949. type: 'setClosable',
  950. payload: closable
  951. }
  952. }
  953. }
  954. });
  955. }
  956. /**
  957. * Sets the window title.
  958. * @example
  959. * ```typescript
  960. * import { appWindow } from '@tauri-apps/api/window';
  961. * await appWindow.setTitle('Tauri');
  962. * ```
  963. *
  964. * @param title The new title
  965. * @returns A promise indicating the success or failure of the operation.
  966. */
  967. async setTitle(title) {
  968. return tauri.invokeTauriCommand({
  969. __tauriModule: 'Window',
  970. message: {
  971. cmd: 'manage',
  972. data: {
  973. label: this.label,
  974. cmd: {
  975. type: 'setTitle',
  976. payload: title
  977. }
  978. }
  979. }
  980. });
  981. }
  982. /**
  983. * Maximizes the window.
  984. * @example
  985. * ```typescript
  986. * import { appWindow } from '@tauri-apps/api/window';
  987. * await appWindow.maximize();
  988. * ```
  989. *
  990. * @returns A promise indicating the success or failure of the operation.
  991. */
  992. async maximize() {
  993. return tauri.invokeTauriCommand({
  994. __tauriModule: 'Window',
  995. message: {
  996. cmd: 'manage',
  997. data: {
  998. label: this.label,
  999. cmd: {
  1000. type: 'maximize'
  1001. }
  1002. }
  1003. }
  1004. });
  1005. }
  1006. /**
  1007. * Unmaximizes the window.
  1008. * @example
  1009. * ```typescript
  1010. * import { appWindow } from '@tauri-apps/api/window';
  1011. * await appWindow.unmaximize();
  1012. * ```
  1013. *
  1014. * @returns A promise indicating the success or failure of the operation.
  1015. */
  1016. async unmaximize() {
  1017. return tauri.invokeTauriCommand({
  1018. __tauriModule: 'Window',
  1019. message: {
  1020. cmd: 'manage',
  1021. data: {
  1022. label: this.label,
  1023. cmd: {
  1024. type: 'unmaximize'
  1025. }
  1026. }
  1027. }
  1028. });
  1029. }
  1030. /**
  1031. * Toggles the window maximized state.
  1032. * @example
  1033. * ```typescript
  1034. * import { appWindow } from '@tauri-apps/api/window';
  1035. * await appWindow.toggleMaximize();
  1036. * ```
  1037. *
  1038. * @returns A promise indicating the success or failure of the operation.
  1039. */
  1040. async toggleMaximize() {
  1041. return tauri.invokeTauriCommand({
  1042. __tauriModule: 'Window',
  1043. message: {
  1044. cmd: 'manage',
  1045. data: {
  1046. label: this.label,
  1047. cmd: {
  1048. type: 'toggleMaximize'
  1049. }
  1050. }
  1051. }
  1052. });
  1053. }
  1054. /**
  1055. * Minimizes the window.
  1056. * @example
  1057. * ```typescript
  1058. * import { appWindow } from '@tauri-apps/api/window';
  1059. * await appWindow.minimize();
  1060. * ```
  1061. *
  1062. * @returns A promise indicating the success or failure of the operation.
  1063. */
  1064. async minimize() {
  1065. return tauri.invokeTauriCommand({
  1066. __tauriModule: 'Window',
  1067. message: {
  1068. cmd: 'manage',
  1069. data: {
  1070. label: this.label,
  1071. cmd: {
  1072. type: 'minimize'
  1073. }
  1074. }
  1075. }
  1076. });
  1077. }
  1078. /**
  1079. * Unminimizes the window.
  1080. * @example
  1081. * ```typescript
  1082. * import { appWindow } from '@tauri-apps/api/window';
  1083. * await appWindow.unminimize();
  1084. * ```
  1085. *
  1086. * @returns A promise indicating the success or failure of the operation.
  1087. */
  1088. async unminimize() {
  1089. return tauri.invokeTauriCommand({
  1090. __tauriModule: 'Window',
  1091. message: {
  1092. cmd: 'manage',
  1093. data: {
  1094. label: this.label,
  1095. cmd: {
  1096. type: 'unminimize'
  1097. }
  1098. }
  1099. }
  1100. });
  1101. }
  1102. /**
  1103. * Sets the window visibility to true.
  1104. * @example
  1105. * ```typescript
  1106. * import { appWindow } from '@tauri-apps/api/window';
  1107. * await appWindow.show();
  1108. * ```
  1109. *
  1110. * @returns A promise indicating the success or failure of the operation.
  1111. */
  1112. async show() {
  1113. return tauri.invokeTauriCommand({
  1114. __tauriModule: 'Window',
  1115. message: {
  1116. cmd: 'manage',
  1117. data: {
  1118. label: this.label,
  1119. cmd: {
  1120. type: 'show'
  1121. }
  1122. }
  1123. }
  1124. });
  1125. }
  1126. /**
  1127. * Sets the window visibility to false.
  1128. * @example
  1129. * ```typescript
  1130. * import { appWindow } from '@tauri-apps/api/window';
  1131. * await appWindow.hide();
  1132. * ```
  1133. *
  1134. * @returns A promise indicating the success or failure of the operation.
  1135. */
  1136. async hide() {
  1137. return tauri.invokeTauriCommand({
  1138. __tauriModule: 'Window',
  1139. message: {
  1140. cmd: 'manage',
  1141. data: {
  1142. label: this.label,
  1143. cmd: {
  1144. type: 'hide'
  1145. }
  1146. }
  1147. }
  1148. });
  1149. }
  1150. /**
  1151. * Closes the window.
  1152. * @example
  1153. * ```typescript
  1154. * import { appWindow } from '@tauri-apps/api/window';
  1155. * await appWindow.close();
  1156. * ```
  1157. *
  1158. * @returns A promise indicating the success or failure of the operation.
  1159. */
  1160. async close() {
  1161. return tauri.invokeTauriCommand({
  1162. __tauriModule: 'Window',
  1163. message: {
  1164. cmd: 'manage',
  1165. data: {
  1166. label: this.label,
  1167. cmd: {
  1168. type: 'close'
  1169. }
  1170. }
  1171. }
  1172. });
  1173. }
  1174. /**
  1175. * Whether the window should have borders and bars.
  1176. * @example
  1177. * ```typescript
  1178. * import { appWindow } from '@tauri-apps/api/window';
  1179. * await appWindow.setDecorations(false);
  1180. * ```
  1181. *
  1182. * @param decorations Whether the window should have borders and bars.
  1183. * @returns A promise indicating the success or failure of the operation.
  1184. */
  1185. async setDecorations(decorations) {
  1186. return tauri.invokeTauriCommand({
  1187. __tauriModule: 'Window',
  1188. message: {
  1189. cmd: 'manage',
  1190. data: {
  1191. label: this.label,
  1192. cmd: {
  1193. type: 'setDecorations',
  1194. payload: decorations
  1195. }
  1196. }
  1197. }
  1198. });
  1199. }
  1200. /**
  1201. * Whether the window should always be on top of other windows.
  1202. * @example
  1203. * ```typescript
  1204. * import { appWindow } from '@tauri-apps/api/window';
  1205. * await appWindow.setAlwaysOnTop(true);
  1206. * ```
  1207. *
  1208. * @param alwaysOnTop Whether the window should always be on top of other windows or not.
  1209. * @returns A promise indicating the success or failure of the operation.
  1210. */
  1211. async setAlwaysOnTop(alwaysOnTop) {
  1212. return tauri.invokeTauriCommand({
  1213. __tauriModule: 'Window',
  1214. message: {
  1215. cmd: 'manage',
  1216. data: {
  1217. label: this.label,
  1218. cmd: {
  1219. type: 'setAlwaysOnTop',
  1220. payload: alwaysOnTop
  1221. }
  1222. }
  1223. }
  1224. });
  1225. }
  1226. /**
  1227. * Prevents the window contents from being captured by other apps.
  1228. * @example
  1229. * ```typescript
  1230. * import { appWindow } from '@tauri-apps/api/window';
  1231. * await appWindow.setContentProtected(true);
  1232. * ```
  1233. *
  1234. * @returns A promise indicating the success or failure of the operation.
  1235. *
  1236. * @since 1.2.0
  1237. */
  1238. async setContentProtected(protected_) {
  1239. return tauri.invokeTauriCommand({
  1240. __tauriModule: 'Window',
  1241. message: {
  1242. cmd: 'manage',
  1243. data: {
  1244. label: this.label,
  1245. cmd: {
  1246. type: 'setContentProtected',
  1247. payload: protected_
  1248. }
  1249. }
  1250. }
  1251. });
  1252. }
  1253. /**
  1254. * Resizes the window with a new inner size.
  1255. * @example
  1256. * ```typescript
  1257. * import { appWindow, LogicalSize } from '@tauri-apps/api/window';
  1258. * await appWindow.setSize(new LogicalSize(600, 500));
  1259. * ```
  1260. *
  1261. * @param size The logical or physical inner size.
  1262. * @returns A promise indicating the success or failure of the operation.
  1263. */
  1264. async setSize(size) {
  1265. if (!size || (size.type !== 'Logical' && size.type !== 'Physical')) {
  1266. throw new Error('the `size` argument must be either a LogicalSize or a PhysicalSize instance');
  1267. }
  1268. return tauri.invokeTauriCommand({
  1269. __tauriModule: 'Window',
  1270. message: {
  1271. cmd: 'manage',
  1272. data: {
  1273. label: this.label,
  1274. cmd: {
  1275. type: 'setSize',
  1276. payload: {
  1277. type: size.type,
  1278. data: {
  1279. width: size.width,
  1280. height: size.height
  1281. }
  1282. }
  1283. }
  1284. }
  1285. }
  1286. });
  1287. }
  1288. /**
  1289. * Sets the window minimum inner size. If the `size` argument is not provided, the constraint is unset.
  1290. * @example
  1291. * ```typescript
  1292. * import { appWindow, PhysicalSize } from '@tauri-apps/api/window';
  1293. * await appWindow.setMinSize(new PhysicalSize(600, 500));
  1294. * ```
  1295. *
  1296. * @param size The logical or physical inner size, or `null` to unset the constraint.
  1297. * @returns A promise indicating the success or failure of the operation.
  1298. */
  1299. async setMinSize(size) {
  1300. if (size && size.type !== 'Logical' && size.type !== 'Physical') {
  1301. throw new Error('the `size` argument must be either a LogicalSize or a PhysicalSize instance');
  1302. }
  1303. return tauri.invokeTauriCommand({
  1304. __tauriModule: 'Window',
  1305. message: {
  1306. cmd: 'manage',
  1307. data: {
  1308. label: this.label,
  1309. cmd: {
  1310. type: 'setMinSize',
  1311. payload: size
  1312. ? {
  1313. type: size.type,
  1314. data: {
  1315. width: size.width,
  1316. height: size.height
  1317. }
  1318. }
  1319. : null
  1320. }
  1321. }
  1322. }
  1323. });
  1324. }
  1325. /**
  1326. * Sets the window maximum inner size. If the `size` argument is undefined, the constraint is unset.
  1327. * @example
  1328. * ```typescript
  1329. * import { appWindow, LogicalSize } from '@tauri-apps/api/window';
  1330. * await appWindow.setMaxSize(new LogicalSize(600, 500));
  1331. * ```
  1332. *
  1333. * @param size The logical or physical inner size, or `null` to unset the constraint.
  1334. * @returns A promise indicating the success or failure of the operation.
  1335. */
  1336. async setMaxSize(size) {
  1337. if (size && size.type !== 'Logical' && size.type !== 'Physical') {
  1338. throw new Error('the `size` argument must be either a LogicalSize or a PhysicalSize instance');
  1339. }
  1340. return tauri.invokeTauriCommand({
  1341. __tauriModule: 'Window',
  1342. message: {
  1343. cmd: 'manage',
  1344. data: {
  1345. label: this.label,
  1346. cmd: {
  1347. type: 'setMaxSize',
  1348. payload: size
  1349. ? {
  1350. type: size.type,
  1351. data: {
  1352. width: size.width,
  1353. height: size.height
  1354. }
  1355. }
  1356. : null
  1357. }
  1358. }
  1359. }
  1360. });
  1361. }
  1362. /**
  1363. * Sets the window outer position.
  1364. * @example
  1365. * ```typescript
  1366. * import { appWindow, LogicalPosition } from '@tauri-apps/api/window';
  1367. * await appWindow.setPosition(new LogicalPosition(600, 500));
  1368. * ```
  1369. *
  1370. * @param position The new position, in logical or physical pixels.
  1371. * @returns A promise indicating the success or failure of the operation.
  1372. */
  1373. async setPosition(position) {
  1374. if (!position ||
  1375. (position.type !== 'Logical' && position.type !== 'Physical')) {
  1376. throw new Error('the `position` argument must be either a LogicalPosition or a PhysicalPosition instance');
  1377. }
  1378. return tauri.invokeTauriCommand({
  1379. __tauriModule: 'Window',
  1380. message: {
  1381. cmd: 'manage',
  1382. data: {
  1383. label: this.label,
  1384. cmd: {
  1385. type: 'setPosition',
  1386. payload: {
  1387. type: position.type,
  1388. data: {
  1389. x: position.x,
  1390. y: position.y
  1391. }
  1392. }
  1393. }
  1394. }
  1395. }
  1396. });
  1397. }
  1398. /**
  1399. * Sets the window fullscreen state.
  1400. * @example
  1401. * ```typescript
  1402. * import { appWindow } from '@tauri-apps/api/window';
  1403. * await appWindow.setFullscreen(true);
  1404. * ```
  1405. *
  1406. * @param fullscreen Whether the window should go to fullscreen or not.
  1407. * @returns A promise indicating the success or failure of the operation.
  1408. */
  1409. async setFullscreen(fullscreen) {
  1410. return tauri.invokeTauriCommand({
  1411. __tauriModule: 'Window',
  1412. message: {
  1413. cmd: 'manage',
  1414. data: {
  1415. label: this.label,
  1416. cmd: {
  1417. type: 'setFullscreen',
  1418. payload: fullscreen
  1419. }
  1420. }
  1421. }
  1422. });
  1423. }
  1424. /**
  1425. * Bring the window to front and focus.
  1426. * @example
  1427. * ```typescript
  1428. * import { appWindow } from '@tauri-apps/api/window';
  1429. * await appWindow.setFocus();
  1430. * ```
  1431. *
  1432. * @returns A promise indicating the success or failure of the operation.
  1433. */
  1434. async setFocus() {
  1435. return tauri.invokeTauriCommand({
  1436. __tauriModule: 'Window',
  1437. message: {
  1438. cmd: 'manage',
  1439. data: {
  1440. label: this.label,
  1441. cmd: {
  1442. type: 'setFocus'
  1443. }
  1444. }
  1445. }
  1446. });
  1447. }
  1448. /**
  1449. * Sets the window icon.
  1450. * @example
  1451. * ```typescript
  1452. * import { appWindow } from '@tauri-apps/api/window';
  1453. * await appWindow.setIcon('/tauri/awesome.png');
  1454. * ```
  1455. *
  1456. * Note that you need the `icon-ico` or `icon-png` Cargo features to use this API.
  1457. * To enable it, change your Cargo.toml file:
  1458. * ```toml
  1459. * [dependencies]
  1460. * tauri = { version = "...", features = ["...", "icon-png"] }
  1461. * ```
  1462. *
  1463. * @param icon Icon bytes or path to the icon file.
  1464. * @returns A promise indicating the success or failure of the operation.
  1465. */
  1466. async setIcon(icon) {
  1467. return tauri.invokeTauriCommand({
  1468. __tauriModule: 'Window',
  1469. message: {
  1470. cmd: 'manage',
  1471. data: {
  1472. label: this.label,
  1473. cmd: {
  1474. type: 'setIcon',
  1475. payload: {
  1476. // correctly serialize Uint8Arrays
  1477. icon: typeof icon === 'string' ? icon : Array.from(icon)
  1478. }
  1479. }
  1480. }
  1481. }
  1482. });
  1483. }
  1484. /**
  1485. * Whether the window icon should be hidden from the taskbar or not.
  1486. *
  1487. * #### Platform-specific
  1488. *
  1489. * - **macOS:** Unsupported.
  1490. * @example
  1491. * ```typescript
  1492. * import { appWindow } from '@tauri-apps/api/window';
  1493. * await appWindow.setSkipTaskbar(true);
  1494. * ```
  1495. *
  1496. * @param skip true to hide window icon, false to show it.
  1497. * @returns A promise indicating the success or failure of the operation.
  1498. */
  1499. async setSkipTaskbar(skip) {
  1500. return tauri.invokeTauriCommand({
  1501. __tauriModule: 'Window',
  1502. message: {
  1503. cmd: 'manage',
  1504. data: {
  1505. label: this.label,
  1506. cmd: {
  1507. type: 'setSkipTaskbar',
  1508. payload: skip
  1509. }
  1510. }
  1511. }
  1512. });
  1513. }
  1514. /**
  1515. * Grabs the cursor, preventing it from leaving the window.
  1516. *
  1517. * There's no guarantee that the cursor will be hidden. You should
  1518. * hide it by yourself if you want so.
  1519. *
  1520. * #### Platform-specific
  1521. *
  1522. * - **Linux:** Unsupported.
  1523. * - **macOS:** This locks the cursor in a fixed location, which looks visually awkward.
  1524. * @example
  1525. * ```typescript
  1526. * import { appWindow } from '@tauri-apps/api/window';
  1527. * await appWindow.setCursorGrab(true);
  1528. * ```
  1529. *
  1530. * @param grab `true` to grab the cursor icon, `false` to release it.
  1531. * @returns A promise indicating the success or failure of the operation.
  1532. */
  1533. async setCursorGrab(grab) {
  1534. return tauri.invokeTauriCommand({
  1535. __tauriModule: 'Window',
  1536. message: {
  1537. cmd: 'manage',
  1538. data: {
  1539. label: this.label,
  1540. cmd: {
  1541. type: 'setCursorGrab',
  1542. payload: grab
  1543. }
  1544. }
  1545. }
  1546. });
  1547. }
  1548. /**
  1549. * Modifies the cursor's visibility.
  1550. *
  1551. * #### Platform-specific
  1552. *
  1553. * - **Windows:** The cursor is only hidden within the confines of the window.
  1554. * - **macOS:** The cursor is hidden as long as the window has input focus, even if the cursor is
  1555. * outside of the window.
  1556. * @example
  1557. * ```typescript
  1558. * import { appWindow } from '@tauri-apps/api/window';
  1559. * await appWindow.setCursorVisible(false);
  1560. * ```
  1561. *
  1562. * @param visible If `false`, this will hide the cursor. If `true`, this will show the cursor.
  1563. * @returns A promise indicating the success or failure of the operation.
  1564. */
  1565. async setCursorVisible(visible) {
  1566. return tauri.invokeTauriCommand({
  1567. __tauriModule: 'Window',
  1568. message: {
  1569. cmd: 'manage',
  1570. data: {
  1571. label: this.label,
  1572. cmd: {
  1573. type: 'setCursorVisible',
  1574. payload: visible
  1575. }
  1576. }
  1577. }
  1578. });
  1579. }
  1580. /**
  1581. * Modifies the cursor icon of the window.
  1582. * @example
  1583. * ```typescript
  1584. * import { appWindow } from '@tauri-apps/api/window';
  1585. * await appWindow.setCursorIcon('help');
  1586. * ```
  1587. *
  1588. * @param icon The new cursor icon.
  1589. * @returns A promise indicating the success or failure of the operation.
  1590. */
  1591. async setCursorIcon(icon) {
  1592. return tauri.invokeTauriCommand({
  1593. __tauriModule: 'Window',
  1594. message: {
  1595. cmd: 'manage',
  1596. data: {
  1597. label: this.label,
  1598. cmd: {
  1599. type: 'setCursorIcon',
  1600. payload: icon
  1601. }
  1602. }
  1603. }
  1604. });
  1605. }
  1606. /**
  1607. * Changes the position of the cursor in window coordinates.
  1608. * @example
  1609. * ```typescript
  1610. * import { appWindow, LogicalPosition } from '@tauri-apps/api/window';
  1611. * await appWindow.setCursorPosition(new LogicalPosition(600, 300));
  1612. * ```
  1613. *
  1614. * @param position The new cursor position.
  1615. * @returns A promise indicating the success or failure of the operation.
  1616. */
  1617. async setCursorPosition(position) {
  1618. if (!position ||
  1619. (position.type !== 'Logical' && position.type !== 'Physical')) {
  1620. throw new Error('the `position` argument must be either a LogicalPosition or a PhysicalPosition instance');
  1621. }
  1622. return tauri.invokeTauriCommand({
  1623. __tauriModule: 'Window',
  1624. message: {
  1625. cmd: 'manage',
  1626. data: {
  1627. label: this.label,
  1628. cmd: {
  1629. type: 'setCursorPosition',
  1630. payload: {
  1631. type: position.type,
  1632. data: {
  1633. x: position.x,
  1634. y: position.y
  1635. }
  1636. }
  1637. }
  1638. }
  1639. }
  1640. });
  1641. }
  1642. /**
  1643. * Changes the cursor events behavior.
  1644. *
  1645. * @example
  1646. * ```typescript
  1647. * import { appWindow } from '@tauri-apps/api/window';
  1648. * await appWindow.setIgnoreCursorEvents(true);
  1649. * ```
  1650. *
  1651. * @param ignore `true` to ignore the cursor events; `false` to process them as usual.
  1652. * @returns A promise indicating the success or failure of the operation.
  1653. */
  1654. async setIgnoreCursorEvents(ignore) {
  1655. return tauri.invokeTauriCommand({
  1656. __tauriModule: 'Window',
  1657. message: {
  1658. cmd: 'manage',
  1659. data: {
  1660. label: this.label,
  1661. cmd: {
  1662. type: 'setIgnoreCursorEvents',
  1663. payload: ignore
  1664. }
  1665. }
  1666. }
  1667. });
  1668. }
  1669. /**
  1670. * Starts dragging the window.
  1671. * @example
  1672. * ```typescript
  1673. * import { appWindow } from '@tauri-apps/api/window';
  1674. * await appWindow.startDragging();
  1675. * ```
  1676. *
  1677. * @return A promise indicating the success or failure of the operation.
  1678. */
  1679. async startDragging() {
  1680. return tauri.invokeTauriCommand({
  1681. __tauriModule: 'Window',
  1682. message: {
  1683. cmd: 'manage',
  1684. data: {
  1685. label: this.label,
  1686. cmd: {
  1687. type: 'startDragging'
  1688. }
  1689. }
  1690. }
  1691. });
  1692. }
  1693. // Listeners
  1694. /**
  1695. * Listen to window resize.
  1696. *
  1697. * @example
  1698. * ```typescript
  1699. * import { appWindow } from "@tauri-apps/api/window";
  1700. * const unlisten = await appWindow.onResized(({ payload: size }) => {
  1701. * console.log('Window resized', size);
  1702. * });
  1703. *
  1704. * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
  1705. * unlisten();
  1706. * ```
  1707. *
  1708. * @returns A promise resolving to a function to unlisten to the event.
  1709. * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
  1710. *
  1711. * @since 1.0.2
  1712. */
  1713. async onResized(handler) {
  1714. return this.listen(event$1.TauriEvent.WINDOW_RESIZED, (e) => {
  1715. e.payload = mapPhysicalSize(e.payload);
  1716. handler(e);
  1717. });
  1718. }
  1719. /**
  1720. * Listen to window move.
  1721. *
  1722. * @example
  1723. * ```typescript
  1724. * import { appWindow } from "@tauri-apps/api/window";
  1725. * const unlisten = await appWindow.onMoved(({ payload: position }) => {
  1726. * console.log('Window moved', position);
  1727. * });
  1728. *
  1729. * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
  1730. * unlisten();
  1731. * ```
  1732. *
  1733. * @returns A promise resolving to a function to unlisten to the event.
  1734. * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
  1735. *
  1736. * @since 1.0.2
  1737. */
  1738. async onMoved(handler) {
  1739. return this.listen(event$1.TauriEvent.WINDOW_MOVED, (e) => {
  1740. e.payload = mapPhysicalPosition(e.payload);
  1741. handler(e);
  1742. });
  1743. }
  1744. /**
  1745. * Listen to window close requested. Emitted when the user requests to closes the window.
  1746. *
  1747. * @example
  1748. * ```typescript
  1749. * import { appWindow } from "@tauri-apps/api/window";
  1750. * import { confirm } from '@tauri-apps/api/dialog';
  1751. * const unlisten = await appWindow.onCloseRequested(async (event) => {
  1752. * const confirmed = await confirm('Are you sure?');
  1753. * if (!confirmed) {
  1754. * // user did not confirm closing the window; let's prevent it
  1755. * event.preventDefault();
  1756. * }
  1757. * });
  1758. *
  1759. * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
  1760. * unlisten();
  1761. * ```
  1762. *
  1763. * @returns A promise resolving to a function to unlisten to the event.
  1764. * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
  1765. *
  1766. * @since 1.0.2
  1767. */
  1768. /* eslint-disable @typescript-eslint/promise-function-async */
  1769. async onCloseRequested(handler) {
  1770. return this.listen(event$1.TauriEvent.WINDOW_CLOSE_REQUESTED, (event) => {
  1771. const evt = new CloseRequestedEvent(event);
  1772. void Promise.resolve(handler(evt)).then(() => {
  1773. if (!evt.isPreventDefault()) {
  1774. return this.close();
  1775. }
  1776. });
  1777. });
  1778. }
  1779. /* eslint-enable */
  1780. /**
  1781. * Listen to window focus change.
  1782. *
  1783. * @example
  1784. * ```typescript
  1785. * import { appWindow } from "@tauri-apps/api/window";
  1786. * const unlisten = await appWindow.onFocusChanged(({ payload: focused }) => {
  1787. * console.log('Focus changed, window is focused? ' + focused);
  1788. * });
  1789. *
  1790. * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
  1791. * unlisten();
  1792. * ```
  1793. *
  1794. * @returns A promise resolving to a function to unlisten to the event.
  1795. * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
  1796. *
  1797. * @since 1.0.2
  1798. */
  1799. async onFocusChanged(handler) {
  1800. const unlistenFocus = await this.listen(event$1.TauriEvent.WINDOW_FOCUS, (event) => {
  1801. handler({ ...event, payload: true });
  1802. });
  1803. const unlistenBlur = await this.listen(event$1.TauriEvent.WINDOW_BLUR, (event) => {
  1804. handler({ ...event, payload: false });
  1805. });
  1806. return () => {
  1807. unlistenFocus();
  1808. unlistenBlur();
  1809. };
  1810. }
  1811. /**
  1812. * Listen to window scale change. Emitted when the window's scale factor has changed.
  1813. * The following user actions can cause DPI changes:
  1814. * - Changing the display's resolution.
  1815. * - Changing the display's scale factor (e.g. in Control Panel on Windows).
  1816. * - Moving the window to a display with a different scale factor.
  1817. *
  1818. * @example
  1819. * ```typescript
  1820. * import { appWindow } from "@tauri-apps/api/window";
  1821. * const unlisten = await appWindow.onScaleChanged(({ payload }) => {
  1822. * console.log('Scale changed', payload.scaleFactor, payload.size);
  1823. * });
  1824. *
  1825. * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
  1826. * unlisten();
  1827. * ```
  1828. *
  1829. * @returns A promise resolving to a function to unlisten to the event.
  1830. * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
  1831. *
  1832. * @since 1.0.2
  1833. */
  1834. async onScaleChanged(handler) {
  1835. return this.listen(event$1.TauriEvent.WINDOW_SCALE_FACTOR_CHANGED, handler);
  1836. }
  1837. /**
  1838. * Listen to the window menu item click. The payload is the item id.
  1839. *
  1840. * @example
  1841. * ```typescript
  1842. * import { appWindow } from "@tauri-apps/api/window";
  1843. * const unlisten = await appWindow.onMenuClicked(({ payload: menuId }) => {
  1844. * console.log('Menu clicked: ' + menuId);
  1845. * });
  1846. *
  1847. * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
  1848. * unlisten();
  1849. * ```
  1850. *
  1851. * @returns A promise resolving to a function to unlisten to the event.
  1852. * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
  1853. *
  1854. * @since 1.0.2
  1855. */
  1856. async onMenuClicked(handler) {
  1857. return this.listen(event$1.TauriEvent.MENU, handler);
  1858. }
  1859. /**
  1860. * Listen to a file drop event.
  1861. * The listener is triggered when the user hovers the selected files on the window,
  1862. * drops the files or cancels the operation.
  1863. *
  1864. * @example
  1865. * ```typescript
  1866. * import { appWindow } from "@tauri-apps/api/window";
  1867. * const unlisten = await appWindow.onFileDropEvent((event) => {
  1868. * if (event.payload.type === 'hover') {
  1869. * console.log('User hovering', event.payload.paths);
  1870. * } else if (event.payload.type === 'drop') {
  1871. * console.log('User dropped', event.payload.paths);
  1872. * } else {
  1873. * console.log('File drop cancelled');
  1874. * }
  1875. * });
  1876. *
  1877. * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
  1878. * unlisten();
  1879. * ```
  1880. *
  1881. * @returns A promise resolving to a function to unlisten to the event.
  1882. * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
  1883. *
  1884. * @since 1.0.2
  1885. */
  1886. async onFileDropEvent(handler) {
  1887. const unlistenFileDrop = await this.listen(event$1.TauriEvent.WINDOW_FILE_DROP, (event) => {
  1888. handler({ ...event, payload: { type: 'drop', paths: event.payload } });
  1889. });
  1890. const unlistenFileHover = await this.listen(event$1.TauriEvent.WINDOW_FILE_DROP_HOVER, (event) => {
  1891. handler({ ...event, payload: { type: 'hover', paths: event.payload } });
  1892. });
  1893. const unlistenCancel = await this.listen(event$1.TauriEvent.WINDOW_FILE_DROP_CANCELLED, (event) => {
  1894. handler({ ...event, payload: { type: 'cancel' } });
  1895. });
  1896. return () => {
  1897. unlistenFileDrop();
  1898. unlistenFileHover();
  1899. unlistenCancel();
  1900. };
  1901. }
  1902. /**
  1903. * Listen to the system theme change.
  1904. *
  1905. * @example
  1906. * ```typescript
  1907. * import { appWindow } from "@tauri-apps/api/window";
  1908. * const unlisten = await appWindow.onThemeChanged(({ payload: theme }) => {
  1909. * console.log('New theme: ' + theme);
  1910. * });
  1911. *
  1912. * // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
  1913. * unlisten();
  1914. * ```
  1915. *
  1916. * @returns A promise resolving to a function to unlisten to the event.
  1917. * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
  1918. *
  1919. * @since 1.0.2
  1920. */
  1921. async onThemeChanged(handler) {
  1922. return this.listen(event$1.TauriEvent.WINDOW_THEME_CHANGED, handler);
  1923. }
  1924. }
  1925. /**
  1926. * @since 1.0.2
  1927. */
  1928. class CloseRequestedEvent {
  1929. constructor(event) {
  1930. this._preventDefault = false;
  1931. this.event = event.event;
  1932. this.windowLabel = event.windowLabel;
  1933. this.id = event.id;
  1934. }
  1935. preventDefault() {
  1936. this._preventDefault = true;
  1937. }
  1938. isPreventDefault() {
  1939. return this._preventDefault;
  1940. }
  1941. }
  1942. /**
  1943. * Create new webview windows and get a handle to existing ones.
  1944. *
  1945. * Windows are identified by a *label* a unique identifier that can be used to reference it later.
  1946. * It may only contain alphanumeric characters `a-zA-Z` plus the following special characters `-`, `/`, `:` and `_`.
  1947. *
  1948. * @example
  1949. * ```typescript
  1950. * // loading embedded asset:
  1951. * const webview = new WebviewWindow('theUniqueLabel', {
  1952. * url: 'path/to/page.html'
  1953. * });
  1954. * // alternatively, load a remote URL:
  1955. * const webview = new WebviewWindow('theUniqueLabel', {
  1956. * url: 'https://github.com/tauri-apps/tauri'
  1957. * });
  1958. *
  1959. * webview.once('tauri://created', function () {
  1960. * // webview window successfully created
  1961. * });
  1962. * webview.once('tauri://error', function (e) {
  1963. * // an error happened creating the webview window
  1964. * });
  1965. *
  1966. * // emit an event to the backend
  1967. * await webview.emit("some event", "data");
  1968. * // listen to an event from the backend
  1969. * const unlisten = await webview.listen("event name", e => {});
  1970. * unlisten();
  1971. * ```
  1972. *
  1973. * @since 1.0.2
  1974. */
  1975. class WebviewWindow extends WindowManager {
  1976. /**
  1977. * Creates a new WebviewWindow.
  1978. * @example
  1979. * ```typescript
  1980. * import { WebviewWindow } from '@tauri-apps/api/window';
  1981. * const webview = new WebviewWindow('my-label', {
  1982. * url: 'https://github.com/tauri-apps/tauri'
  1983. * });
  1984. * webview.once('tauri://created', function () {
  1985. * // webview window successfully created
  1986. * });
  1987. * webview.once('tauri://error', function (e) {
  1988. * // an error happened creating the webview window
  1989. * });
  1990. * ```
  1991. *
  1992. * * @param label The unique webview window label. Must be alphanumeric: `a-zA-Z-/:_`.
  1993. * @returns The WebviewWindow instance to communicate with the webview.
  1994. */
  1995. constructor(label, options = {}) {
  1996. super(label);
  1997. // @ts-expect-error `skip` is not a public API so it is not defined in WindowOptions
  1998. if (!(options === null || options === void 0 ? void 0 : options.skip)) {
  1999. tauri.invokeTauriCommand({
  2000. __tauriModule: 'Window',
  2001. message: {
  2002. cmd: 'createWebview',
  2003. data: {
  2004. options: {
  2005. label,
  2006. ...options
  2007. }
  2008. }
  2009. }
  2010. })
  2011. .then(async () => this.emit('tauri://created'))
  2012. .catch(async (e) => this.emit('tauri://error', e));
  2013. }
  2014. }
  2015. /**
  2016. * Gets the WebviewWindow for the webview associated with the given label.
  2017. * @example
  2018. * ```typescript
  2019. * import { WebviewWindow } from '@tauri-apps/api/window';
  2020. * const mainWindow = WebviewWindow.getByLabel('main');
  2021. * ```
  2022. *
  2023. * @param label The webview window label.
  2024. * @returns The WebviewWindow instance to communicate with the webview or null if the webview doesn't exist.
  2025. */
  2026. static getByLabel(label) {
  2027. if (getAll().some((w) => w.label === label)) {
  2028. // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
  2029. return new WebviewWindow(label, { skip: true });
  2030. }
  2031. return null;
  2032. }
  2033. /**
  2034. * Gets the focused window.
  2035. * @example
  2036. * ```typescript
  2037. * import { WebviewWindow } from '@tauri-apps/api/window';
  2038. * const focusedWindow = WebviewWindow.getFocusedWindow();
  2039. * ```
  2040. *
  2041. * @returns The WebviewWindow instance to communicate with the webview or `undefined` if there is not any focused window.
  2042. *
  2043. * @since 1.4
  2044. */
  2045. static async getFocusedWindow() {
  2046. for (const w of getAll()) {
  2047. if (await w.isFocused()) {
  2048. return w;
  2049. }
  2050. }
  2051. return null;
  2052. }
  2053. }
  2054. /** The WebviewWindow for the current window. */
  2055. exports.appWindow = void 0;
  2056. if ('__TAURI_METADATA__' in window) {
  2057. exports.appWindow = new WebviewWindow(window.__TAURI_METADATA__.__currentWindow.label, {
  2058. // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
  2059. skip: true
  2060. });
  2061. }
  2062. else {
  2063. console.warn(`Could not find "window.__TAURI_METADATA__". The "appWindow" value will reference the "main" window label.\nNote that this is not an issue if running this frontend on a browser instead of a Tauri window.`);
  2064. exports.appWindow = new WebviewWindow('main', {
  2065. // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
  2066. skip: true
  2067. });
  2068. }
  2069. function mapMonitor(m) {
  2070. return m === null
  2071. ? null
  2072. : {
  2073. name: m.name,
  2074. scaleFactor: m.scaleFactor,
  2075. position: mapPhysicalPosition(m.position),
  2076. size: mapPhysicalSize(m.size)
  2077. };
  2078. }
  2079. function mapPhysicalPosition(m) {
  2080. return new PhysicalPosition(m.x, m.y);
  2081. }
  2082. function mapPhysicalSize(m) {
  2083. return new PhysicalSize(m.width, m.height);
  2084. }
  2085. /**
  2086. * Returns the monitor on which the window currently resides.
  2087. * Returns `null` if current monitor can't be detected.
  2088. * @example
  2089. * ```typescript
  2090. * import { currentMonitor } from '@tauri-apps/api/window';
  2091. * const monitor = currentMonitor();
  2092. * ```
  2093. *
  2094. * @since 1.0.0
  2095. */
  2096. async function currentMonitor() {
  2097. return tauri.invokeTauriCommand({
  2098. __tauriModule: 'Window',
  2099. message: {
  2100. cmd: 'manage',
  2101. data: {
  2102. cmd: {
  2103. type: 'currentMonitor'
  2104. }
  2105. }
  2106. }
  2107. }).then(mapMonitor);
  2108. }
  2109. /**
  2110. * Returns the primary monitor of the system.
  2111. * Returns `null` if it can't identify any monitor as a primary one.
  2112. * @example
  2113. * ```typescript
  2114. * import { primaryMonitor } from '@tauri-apps/api/window';
  2115. * const monitor = primaryMonitor();
  2116. * ```
  2117. *
  2118. * @since 1.0.0
  2119. */
  2120. async function primaryMonitor() {
  2121. return tauri.invokeTauriCommand({
  2122. __tauriModule: 'Window',
  2123. message: {
  2124. cmd: 'manage',
  2125. data: {
  2126. cmd: {
  2127. type: 'primaryMonitor'
  2128. }
  2129. }
  2130. }
  2131. }).then(mapMonitor);
  2132. }
  2133. /**
  2134. * Returns the list of all the monitors available on the system.
  2135. * @example
  2136. * ```typescript
  2137. * import { availableMonitors } from '@tauri-apps/api/window';
  2138. * const monitors = availableMonitors();
  2139. * ```
  2140. *
  2141. * @since 1.0.0
  2142. */
  2143. async function availableMonitors() {
  2144. return tauri.invokeTauriCommand({
  2145. __tauriModule: 'Window',
  2146. message: {
  2147. cmd: 'manage',
  2148. data: {
  2149. cmd: {
  2150. type: 'availableMonitors'
  2151. }
  2152. }
  2153. }
  2154. }).then((ms) => ms.map(mapMonitor));
  2155. }
  2156. exports.CloseRequestedEvent = CloseRequestedEvent;
  2157. exports.LogicalPosition = LogicalPosition;
  2158. exports.LogicalSize = LogicalSize;
  2159. exports.PhysicalPosition = PhysicalPosition;
  2160. exports.PhysicalSize = PhysicalSize;
  2161. exports.WebviewWindow = WebviewWindow;
  2162. exports.WebviewWindowHandle = WebviewWindowHandle;
  2163. exports.WindowManager = WindowManager;
  2164. exports.availableMonitors = availableMonitors;
  2165. exports.currentMonitor = currentMonitor;
  2166. exports.getAll = getAll;
  2167. exports.getCurrent = getCurrent;
  2168. exports.primaryMonitor = primaryMonitor;