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