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
//!
//! Creation and management of application windows. Provides control such as maximizing,
//! minimizing and restoring application windows, changing the title, size and position,
//! window transparency, control over kiosk and full-screen modes, window image capture,
//! iframe control and print options control including print header, footer and other options.
//!
//! # Synopsis
//!
//! ```rust
//! use workflow_wasm::prelude::*;
//!
//! // Get the current window
//! let win = nw_sys::window::get();
//!
//! // Listen to the minimize event
//! let minimize_callback = callback!(|| {
//! log_info!("Window is minimized");
//! });
//!
//! win.on("minimize", minimize_callback.as_ref());
//!
//! // Minimize the window
//! win.minimize();
//!
//! // Unlisten the minimize event
//! win.remove_all_listeners_with_name("minimize");
//!
//! // Create a new window and get it
//! let options = nw_sys::window::Options::new()
//! .title("Test window");
//!
//! let open_callback = callback!(|new_win:nw_sys::Window| {
//! // And listen to new window's focus event
//! let focus_callabck = callback!(||{
//! log_info!("New window is focused");
//! });
//! new_win.on("focus", focus_callabck.as_ref());
//! });
//!
//! nw_sys::window::open_with_options_and_callback(
//! "https://github.com",
//! &options,
//! open_callback.as_ref()
//! );
//!
//! // save these `open_callback`, `focus_callabck`
//! // and `minimize_callback` somewhere
//! app.push_callback(open_callback);
//! app.push_callback(minimize_callback);
//!
//! ```
use crate::menu::Menu;
use crate::options::OptionsTrait;
use js_sys::{ArrayBuffer, Function, Object, Promise};
use wasm_bindgen::prelude::*;
use web_sys::HtmlIFrameElement;
#[wasm_bindgen]
extern "C" {
// TODO: win.cookies.*
///
/// Interface for managing application windows. For usage example please refer to [nw_sys::window](self)
///
#[wasm_bindgen(js_namespace=nw, js_name = Window)]
#[derive(Debug, Clone)]
pub type Window;
#[wasm_bindgen(method, getter, js_name = window)]
/// Get the corresponding DOM window object of the native window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winwindow)
///
pub fn window(this: &Window) -> web_sys::Window;
#[wasm_bindgen(method, getter, js_name = x)]
/// Get left offset from window frame to screen.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winx)
///
pub fn x(this: &Window) -> i32;
#[wasm_bindgen(method, setter, js_name = x)]
/// Set left offset from window frame to screen.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winx)
///
pub fn set_x(this: &Window, x: i32);
#[wasm_bindgen(method, getter, js_name = y)]
/// Get top offset from window frame to screen.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winy)
///
pub fn y(this: &Window) -> i32;
#[wasm_bindgen(method, setter, js_name = y)]
/// Set top offset from window frame to screen.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winy)
///
pub fn set_y(this: &Window, y: i32);
#[wasm_bindgen(method, getter, js_name = width)]
/// Get window’s size, including the window’s frame.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winwidth)
///
pub fn width(this: &Window) -> u32;
#[wasm_bindgen(method, setter, js_name = width)]
/// Set window’s size, including the window’s frame.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winwidth)
///
pub fn set_width(this: &Window, width: u32);
#[wasm_bindgen(method, getter, js_name = height)]
/// Get window’s size, including the window’s frame.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winheight)
///
pub fn height(this: &Window) -> u32;
#[wasm_bindgen(method, setter, js_name = height)]
/// Set window’s size, including the window’s frame.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winheight)
///
pub fn set_height(this: &Window, height: u32);
#[wasm_bindgen(method, getter, js_name = title)]
/// Get window’s title.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wintitle)
///
pub fn title(this: &Window) -> String;
#[wasm_bindgen(method, setter, js_name = title)]
/// Set window’s title.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wintitle)
///
pub fn set_title(this: &Window, title: &str);
#[wasm_bindgen(method, getter, js_name = menu)]
/// Get window’s menubar.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winmenu)
///
pub fn menu(this: &Window) -> Menu;
#[wasm_bindgen(method, setter, js_name = menu)]
/// Set window’s menubar.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winmenu)
///
pub fn set_menu(this: &Window, menu: &Menu);
#[wasm_bindgen(method, setter, js_name = menu)]
/// Set window’s menubar = null.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winmenu)
///
pub fn remove_menu_impl(this: &Window, menu: JsValue);
#[wasm_bindgen(method, getter, js_name = isAlwaysOnTop)]
/// Get whether the window is always on top of other windows.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winisalwaysontop)
///
pub fn is_always_on_top(this: &Window) -> bool;
#[wasm_bindgen(method, getter, js_name = isFullscreen)]
/// Get whether we’re in fullscreen mode.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winisfullscreen)
///
pub fn is_fullscreen(this: &Window) -> bool;
#[wasm_bindgen(method, getter, js_name = isTransparent)]
/// Get whether transparency is turned on
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winistransparent)
///
pub fn is_transparent(this: &Window) -> bool;
#[wasm_bindgen(method, getter, js_name = isKioskMode)]
/// Get whether we’re in kiosk mode.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winiskioskmode)
///
pub fn is_kiosk_mode(this: &Window) -> bool;
#[wasm_bindgen(method, getter, js_name = zoomLevel)]
/// Get the page zoom. 0 for normal size; positive value for zooming in; negative value for zooming out.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winzoomlevel)
///
pub fn zoom_level(this: &Window) -> i16;
#[wasm_bindgen(method, setter, js_name = zoomLevel)]
/// Set the page zoom. 0 for normal size; positive value for zooming in; negative value for zooming out.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winzoomlevel)
///
pub fn set_zoom_level(this: &Window, zoom: i16);
//TODO: Cookies
#[wasm_bindgen(method, js_name = moveTo)]
/// Moves a window’s left and top edge to the specified coordinates.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winmovetox-y)
///
pub fn move_to(this: &Window, x: u32, y: u32);
#[wasm_bindgen(method, js_name = moveBy)]
/// Moves a window a specified number of pixels relative to its current coordinates.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winmovebyx-y)
///
pub fn move_by(this: &Window, x: u32, y: u32);
#[wasm_bindgen(method, js_name = resizeTo)]
/// Resizes a window to the specified width and height.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winresizetowidth-height)
///
pub fn resize_to(this: &Window, width: u32, height: u32);
#[wasm_bindgen(method, js_name = setInnerWidth)]
/// Set the inner width of the window
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetinnerwidthwidth)
///
pub fn set_inner_width(this: &Window, width: u32);
#[wasm_bindgen(method, js_name = setInnerHeight)]
/// Set the inner height of the window
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetinnerheightheight)
///
pub fn set_inner_height(this: &Window, height: u32);
#[wasm_bindgen(method, js_name = resizeBy)]
/// Resizes a window by the specified amount.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winresizebywidth-height)
///
pub fn resize_by(this: &Window, width: u32, height: u32);
#[wasm_bindgen(method, js_name = focus)]
/// Focus on the window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winfocus)
///
pub fn focus(this: &Window);
#[wasm_bindgen(method, js_name = blur)]
/// Move focus away. Usually it will move focus to other windows of your app,
/// since on some platforms there is no concept of blur.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winblur)
///
pub fn blur(this: &Window);
#[wasm_bindgen(method, js_name = show)]
/// Show the window if it’s not shown.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winshowis_show)
///
pub fn show(this: &Window);
#[wasm_bindgen(method, js_name = show)]
/// Show/Hide the window
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winshowis_show)
///
pub fn set_show(this: &Window, is_show: bool);
#[wasm_bindgen(method, js_name = hide)]
/// Hide the window. User will not be able to find the window once it’s hidden.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winhide)
///
pub fn hide(this: &Window);
#[wasm_bindgen(method, js_name = close)]
/// Closes the current window.
/// You can prevent the closing by listening to the close event.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincloseforce)
///
pub fn close(this: &Window);
#[wasm_bindgen(method, js_name = close)]
/// Closes the current window.
/// You can prevent the closing by listening to the close event.
/// if force is equals true, then the close event will be ignored.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincloseforce)
///
pub fn close_impl(this: &Window, force: bool);
#[wasm_bindgen(method)]
/// Reloads the current window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winreload)
///
pub fn reload(this: &Window);
#[wasm_bindgen(method, js_name=reloadDev)]
/// Reloads the current page by starting a new renderer process from scratch.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winreloaddev)
///
pub fn reload_dev(this: &Window);
#[wasm_bindgen(method, js_name=reloadIgnoringCache)]
/// Like reload(), but don’t use caches (aka “shift-reload”).
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winreloadignoringcache)
///
pub fn reload_ignoring_cache(this: &Window);
#[wasm_bindgen(method)]
/// Maximize the window on GTK and Windows, and zoom the window on Mac OS X.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winmaximize)
///
pub fn maximize(this: &Window);
#[wasm_bindgen(method)]
/// Unmaximize the window, i.e. the reverse of maximize().
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winunmaximize)
///
pub fn unmaximize(this: &Window);
#[wasm_bindgen(method)]
/// Minimize the window to task bar on Windows, iconify the window on GTK,
/// and miniaturize the window on Mac OS X.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winminimize)
///
pub fn minimize(this: &Window);
#[wasm_bindgen(method)]
/// Restore window to previous state after the window is minimized,
/// i.e. the reverse of minimize().
/// It’s not named unminimize since restore is used commonly.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winrestore)
///
pub fn restore(this: &Window);
#[wasm_bindgen(method, js_name=enterFullscreen)]
/// Make the window fullscreen.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winenterfullscreen)
///
pub fn enter_fullscreen(this: &Window);
#[wasm_bindgen(method, js_name=leaveFullscreen)]
/// Leave the fullscreen mode.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winleavefullscreen)
///
pub fn leave_fullscreen(this: &Window);
#[wasm_bindgen(method, js_name=toggleFullscreen)]
/// Toggle the fullscreen mode.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wintogglefullscreen)
///
pub fn toggle_fullscreen(this: &Window);
#[wasm_bindgen(method, js_name=enterKioskMode)]
/// Enter the Kiosk mode.
/// In Kiosk mode, the app will be fullscreen and try to prevent users from
/// leaving the app, so you should remember to provide a way in app to
/// leave Kiosk mode. This mode is mainly used for presentation on public
/// displays.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winenterkioskmode)
///
pub fn enter_kiosk_mode(this: &Window);
#[wasm_bindgen(method, js_name=leaveKioskMode)]
/// Leave the Kiosk mode.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winleavekioskmode)
///
pub fn leave_kiosk_mode(this: &Window);
#[wasm_bindgen(method, js_name=toggleKioskMode)]
/// Toggle the kiosk mode.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wintogglekioskmode)
///
pub fn toggle_kiosk_mode(this: &Window);
#[wasm_bindgen(method, js_name=setTransparent)]
/// Turn on/off the transparency support.
///
/// See more info on [Transparent Window](https://docs.nwjs.io/en/latest/For%20Users/Advanced/Transparent%20Window/).
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wintogglekioskmode)
///
pub fn set_transparent(this: &Window, transparent: bool);
#[wasm_bindgen(method, js_name=setShadow)]
/// (Mac) Turn the window’s native shadow on/off.
/// Useful for frameless, transparent windows.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetshadowshadow-mac)
///
pub fn set_shadow(this: &Window, shadow: bool);
#[wasm_bindgen(method, js_name=showDevTools)]
/// Open the devtools to inspect the window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winshowdevtoolsiframe-callback)
///
pub fn show_dev_tools(this: &Window);
#[wasm_bindgen(method, js_name=showDevTools)]
/// Open the devtools to inspect the window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winshowdevtoolsiframe-callback)
///
pub fn show_dev_tools_with_id(this: &Window, iframe_id: &str);
#[wasm_bindgen(method, js_name=showDevTools)]
/// Open the devtools to inspect the window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winshowdevtoolsiframe-callback)
///
pub fn show_dev_tools_with_id_and_callback(this: &Window, iframe_id: &str, callback: &Function);
#[wasm_bindgen(method, js_name=showDevTools)]
/// Open the devtools to inspect the window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winshowdevtoolsiframe-callback)
///
pub fn show_dev_tools_with_iframe(this: &Window, iframe_element: &HtmlIFrameElement);
#[wasm_bindgen(method, js_name=showDevTools)]
/// Open the devtools to inspect the window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winshowdevtoolsiframe-callback)
///
pub fn show_dev_tools_with_iframe_and_callback(
this: &Window,
iframe_element: &HtmlIFrameElement,
callback: &Function,
);
#[wasm_bindgen(method, js_name=closeDevTools)]
/// Close the devtools window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winclosedevtools)
///
pub fn close_dev_tools(this: &Window);
#[wasm_bindgen(method, js_name=getPrinters)]
/// Enumerate the printers in the system.
/// The callback function will receive an array of JSON objects for
/// the printer information. The device name of the JSON object can
/// be used as parameter in `win.print()`
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wingetprinterscallback)
///
pub fn get_printers(this: &Window, callback: &Function);
#[wasm_bindgen(method, js_name=isDevToolsOpen)]
/// Query the status of devtools window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winisdevtoolsopen)
///
pub fn is_dev_tools_open(this: &Window) -> bool;
#[wasm_bindgen(method, js_name=print)]
/// Print the web contents in the window with or without the need for
/// user’s interaction.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn print(this: &Window, options: &PrintOptions);
#[wasm_bindgen(method, js_name=setMaximumSize)]
/// Set window’s maximum size.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetmaximumsizewidth-height)
///
pub fn set_maximum_size(this: &Window, width: u32, height: u32);
#[wasm_bindgen(method, js_name=setMinimumSize)]
/// Set window’s minimum size.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetminimumsizewidth-height)
///
pub fn set_minimum_size(this: &Window, width: u32, height: u32);
#[wasm_bindgen(method, js_name=setResizable)]
/// Set whether window is resizable.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetresizableresizable)
///
pub fn set_resizable(this: &Window, resizable: bool);
#[wasm_bindgen(method, js_name=setAlwaysOnTop)]
/// Sets the widget to be on top of all other windows in the window system.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetalwaysontoptop)
///
pub fn set_always_on_top(this: &Window, top: bool);
#[wasm_bindgen(method, js_name=setVisibleOnAllWorkspaces)]
/// (Mac and Linux)
/// Sets the widget to be on top of all other windows in the window system.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetvisibleonallworkspacesvisible-mac-and-linux)
///
pub fn set_visible_on_all_workspaces(this: &Window, top: bool);
#[wasm_bindgen(method, js_name=canSetVisibleOnAllWorkspaces)]
/// (Mac and Linux)
/// Returns a boolean indicating if the platform (currently Mac OS X and Linux)
/// support Window API method `win.set_visible_on_all_workspaces(true/false)`.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincansetvisibleonallworkspaces-mac-and-linux)
///
pub fn can_set_visible_on_all_workspaces(this: &Window) -> bool;
#[wasm_bindgen(method, js_name=setPosition)]
/// Move window to specified position.
/// Currently only center is supported on all platforms,
/// which will put window in the middle of the screen.
///
/// There are three valid positions: null or center or mouse
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetpositionposition)
///
pub fn set_position_impl(this: &Window, position: JsValue);
#[wasm_bindgen(method, js_name=setShowInTaskbar)]
/// Control whether to show window in taskbar or dock.
///
/// See also `show_in_taskbar` in [Manifest-format](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#show_in_taskbar).
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetshowintaskbarshow)
///
pub fn set_show_in_taskbar(this: &Window, show: bool);
#[wasm_bindgen(method, js_name=requestAttention)]
/// Request the user’s attension by making the window flashes in the task bar.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winrequestattentionattension)
///
pub fn request_attention(this: &Window, attension: bool);
#[wasm_bindgen(method, js_name=requestAttention)]
/// Request the user’s attension by making the window flashes in the task bar.
///
/// On Mac, value < 0 will trigger NSInformationalRequest, while value > 0 will trigger NSCriticalRequest.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winrequestattentionattension)
///
pub fn request_attention_with_number(this: &Window, attension: i16);
#[wasm_bindgen(method, js_name=capturePage)]
/// Captures the visible area of the window.
///
/// To capture the full page,
/// see [win.captureScreenshot](https://docs.nwjs.io/en/latest/References/Window/#wincapturescreenshotoptions-callback).
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincapturepagecallback-config)
///
pub fn capture_page(this: &Window, callback: &Function);
#[wasm_bindgen(method, js_name=capturePage)]
/// Captures the visible area of the window.
///
/// To capture the full page,
/// see [win.captureScreenshot](https://docs.nwjs.io/en/latest/References/Window/#wincapturescreenshotoptions-callback).
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincapturepagecallback-config)
///
pub fn capture_page_with_config(this: &Window, callback: &Function, config: &CaptureConfig);
#[wasm_bindgen(method, js_name=captureScreenshot)]
/// Captures the the window.
/// It can be used to capture the full page beyond the visible area.
///
/// Note: This API is experimental and subject to change in the future.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincapturepagecallback-config)
///
pub fn capture_screenshot(this: &Window, config: &ScreenshotConfig) -> Promise;
#[wasm_bindgen(method, js_name=captureScreenshot)]
/// Captures the the window.
/// It can be used to capture the full page beyond the visible area.
///
/// Note: This API is experimental and subject to change in the future.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincapturepagecallback-config)
///
pub fn capture_screenshot_with_callback(
this: &Window,
config: &ScreenshotConfig,
callback: &Function,
);
#[wasm_bindgen(method, js_name=setProgressBar)]
/// Set progress bar
///
/// Note: Only Ubuntu is supported,
/// and you’ll need to specify the application `.desktop` file through
/// `NW_DESKTOP` env.
///
/// If `NW_DESKTOP` env variable is not found, it uses `nw.desktop` by default.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetprogressbarprogress)
///
pub fn set_progress_bar(this: &Window, progress: f32);
#[wasm_bindgen(method, js_name=setBadgeLabel)]
/// Set the badge label on the window icon in taskbar or dock.
///
/// Note: This API is only supported on Ubuntu and the label is restricted
/// to a string number only. You’ll also need to specify the `.desktop`
/// file for your application (see the note on `set_progress_bar`)
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetbadgelabellabel)
///
pub fn set_badge_label(this: &Window, label: &str);
#[wasm_bindgen(method, js_name=eval)]
/// Execute a piece of JavaScript in the frame.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winevalframe-script)
///
pub fn eval_impl(this: &Window, iframe: JsValue, script: &str);
#[wasm_bindgen(method, js_name=eval)]
/// Execute a piece of JavaScript in the frame.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winevalframe-script)
///
pub fn eval_with_iframe(this: &Window, iframe: &HtmlIFrameElement, script: &str);
#[wasm_bindgen(method, js_name=evalNWBin)]
/// Load and execute the compiled binary in the frame.
///
/// See [Protect JavaScript Source Code](https://docs.nwjs.io/en/latest/For%20Users/Advanced/Protect%20JavaScript%20Source%20Code/).
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winevalnwbinframe-path)
///
pub fn eval_nw_bin_impl(this: &Window, iframe: JsValue, script: JsValue);
#[wasm_bindgen(method, js_name=evalNWBin)]
/// Load and execute the compiled binary in the frame.
///
/// See [Protect JavaScript Source Code](https://docs.nwjs.io/en/latest/For%20Users/Advanced/Protect%20JavaScript%20Source%20Code/).
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winevalnwbinframe-path)
///
pub fn eval_nw_bin_with_iframe_impl(this: &Window, iframe: &HtmlIFrameElement, script: JsValue);
#[wasm_bindgen(method, js_name=evalNWBinModule)]
/// Load and execute the compiled binary for Modules in the frame.
///
/// The binary should be compiled with nwjc --nw-module.
/// The following code will load `lib.bin` as module and other modules
/// can refer to it with something like `import * from "./lib.js"`
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winevalnwbinmoduleframe-path-module_path)
///
pub fn eval_nw_bin_module_impl(
this: &Window,
iframe: JsValue,
script: JsValue,
module_path: &str,
);
#[wasm_bindgen(method, js_name=evalNWBinModule)]
/// Load and execute the compiled binary for Modules in the frame.
///
/// The binary should be compiled with nwjc --nw-module.
/// The following code will load `lib.bin` as module and other modules
/// can refer to it with something like `import * from "./lib.js"`
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winevalnwbinmoduleframe-path-module_path)
///
pub fn eval_nw_bin_module_with_iframe(
this: &Window,
iframe: &HtmlIFrameElement,
script: JsValue,
module_path: &str,
);
#[wasm_bindgen(method, js_name=removeAllListeners)]
/// Removes all listeners
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winremovealllistenerseventname)
///
pub fn remove_all_listeners(this: &Window);
#[wasm_bindgen(method, js_name=removeAllListeners)]
/// Removes all listeners of the specified `event_name`
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winremovealllistenerseventname)
///
pub fn remove_all_listeners_with_name(this: &Window, event_name: &str);
#[wasm_bindgen(method)]
/// Add event listener to the specified `event_name`
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#event-close)
///
pub fn on(this: &Window, event_name: &str, callback: &Function);
}
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace=["nw", "Window"], js_name = get)]
/// Get current window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#windowgetwindow_object)
///
pub fn get() -> Window;
#[wasm_bindgen(js_namespace=["nw", "Window"], js_name = getAll)]
/// Get all windows with a callback function whose parameter is an array of nw::Window object.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#windowgetallcallback)
///
pub fn get_all(callback: &Function);
#[wasm_bindgen(js_namespace=["nw", "Window"], js_name = open)]
/// Open new window
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#windowopenurl-options-callback)
///
pub fn open(url: &str);
/// Window open options
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#windowopenurl-options-callback)
#[wasm_bindgen(extends = Object)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub type Options;
#[wasm_bindgen(js_namespace=["nw", "Window"], js_name = open)]
/// Open window with options
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#windowopenurl-options-callback)
pub fn open_with_options(url: &str, option: &Options);
#[wasm_bindgen(js_namespace=["nw", "Window"], js_name = open)]
/// Open window with options and callback.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#windowopenurl-options-callback)
pub fn open_with_options_and_callback(url: &str, option: &Options, callback: &Function);
/// Window Print options
///
#[wasm_bindgen(extends = Object)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub type PrintOptions;
/// Window Capture Config
///
#[wasm_bindgen(extends = Object)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub type CaptureConfig;
/// Screenshot Config
///
#[wasm_bindgen(extends = Object)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub type ScreenshotConfig;
}
/// Window position
///
pub enum WindowPosition {
Null,
Center,
Mouse,
}
/// NW Binary data
///
pub enum NWBinary {
Path(String),
ArrayBuffer(ArrayBuffer),
//Buffer(Buffer)
}
impl Window {
/// Set window’s menubar = null.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winmenu)
///
pub fn remove_menu(&self) {
self.remove_menu_impl(JsValue::null());
}
/// Closes the current window without triggering `close` event.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincloseforce)
///
pub fn close_with_force(&self) {
self.close_impl(true);
}
/// Move window to specified position.
/// Currently only center is supported on all platforms,
/// which will put window in the middle of the screen.
///
/// There are three valid positions: null or center or mouse
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetpositionposition)
///
pub fn set_position(&self, position: WindowPosition) {
let position = match position {
WindowPosition::Null => JsValue::null(),
WindowPosition::Center => JsValue::from("center"),
WindowPosition::Mouse => JsValue::from("mouse"),
};
self.set_position_impl(position);
}
/// Execute a piece of JavaScript in the frame.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winevalframe-script)
///
pub fn eval(&self, iframe: Option<HtmlIFrameElement>, script: &str) {
if let Some(iframe) = iframe {
self.eval_with_iframe(&iframe, script);
} else {
self.eval_impl(JsValue::null(), script);
}
}
/// Load and execute the compiled binary in the frame.
///
/// See [Protect JavaScript Source Code](https://docs.nwjs.io/en/latest/For%20Users/Advanced/Protect%20JavaScript%20Source%20Code/).
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winevalnwbinframe-path)
///
pub fn eval_nw_bin(&self, iframe: Option<HtmlIFrameElement>, script: NWBinary) {
let script = match script {
NWBinary::Path(path) => JsValue::from(path),
NWBinary::ArrayBuffer(buffer) => JsValue::from(buffer),
};
if let Some(iframe) = iframe {
self.eval_nw_bin_with_iframe_impl(&iframe, script);
} else {
self.eval_nw_bin_impl(JsValue::null(), script);
}
}
/// Load and execute the compiled binary for Modules in the frame.
///
/// The binary should be compiled with nwjc --nw-module.
/// The following code will load `lib.bin` as module and other modules
/// can refer to it with something like `import * from "./lib.js"`
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winevalnwbinmoduleframe-path-module_path)
///
pub fn eval_nw_bin_module(
&self,
iframe: Option<HtmlIFrameElement>,
script: NWBinary,
module_path: &str,
) {
let script = match script {
NWBinary::Path(path) => JsValue::from(path),
NWBinary::ArrayBuffer(buffer) => JsValue::from(buffer),
};
if let Some(iframe) = iframe {
self.eval_nw_bin_module_with_iframe(&iframe, script, module_path);
} else {
self.eval_nw_bin_module_impl(JsValue::null(), script, module_path);
}
}
}
impl OptionsTrait for Options {}
impl Options {
/// the id used to identify the window.
/// This will be used to remember the size and position of the window
/// and restore that geometry when a window with the same id is later opened.
/// [See also the Chrome App documentation](https://developer.chrome.com/docs/extensions/reference/app_window/#property-CreateWindowOptions-id)
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#windowopenurl-options-callback)
pub fn id(self, id: &str) -> Self {
self.set("id", JsValue::from(id))
}
/// The default title of window created by NW.js, .
/// it's very useful if you want to show your own title when the app is starting
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#webkit-subfields)
pub fn title(self, title: &str) -> Self {
self.set("title", JsValue::from(title))
}
/// the initial inner width of the window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#webkit-subfields)
pub fn width(self, width: u32) -> Self {
self.set("width", JsValue::from(width))
}
/// the initial inner height of the window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#webkit-subfields)
pub fn height(self, height: u32) -> Self {
self.set("height", JsValue::from(height))
}
/// path to window’s icon.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#icon)
pub fn icon(self, icon: &String) -> Self {
self.set("icon", JsValue::from(icon))
}
/// Move window to specified position.
/// Currently only center is supported on all platforms,
/// which will put window in the middle of the screen.
///
/// There are three valid positions: null or center or mouse
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winsetpositionposition)
///
pub fn position(self, position: WindowPosition) -> Self {
let position = match position {
WindowPosition::Null => JsValue::null(),
WindowPosition::Center => JsValue::from("center"),
WindowPosition::Mouse => JsValue::from("mouse"),
};
self.set("position", position)
}
/// minimum inner width of window
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#min_width)
pub fn min_width(self, min_width: u32) -> Self {
self.set("min_width", JsValue::from(min_width))
}
/// minimum inner height of window
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#min_height)
pub fn min_height(self, min_height: u32) -> Self {
self.set("min_height", JsValue::from(min_height))
}
/// maximum inner width of window
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#max_width)
pub fn max_width(self, max_width: u32) -> Self {
self.set("max_width", JsValue::from(max_width))
}
/// maximum inner height of window
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#max_height)
pub fn max_height(self, max_height: u32) -> Self {
self.set("max_height", JsValue::from(max_height))
}
/// (Linux) show as desktop background window under X11 environment
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#as_desktop-linux)
pub fn as_desktop(self, as_desktop: bool) -> Self {
self.set("as_desktop", JsValue::from(as_desktop))
}
/// whether window is resizable
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#resizable)
pub fn resizable(self, resizable: bool) -> Self {
self.set("resizable", JsValue::from(resizable))
}
/// whether the window should always stay on top of other windows.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#always_on_top)
pub fn always_on_top(self, always_on_top: bool) -> Self {
self.set("always_on_top", JsValue::from(always_on_top))
}
/// whether the window should be visible on all workspaces
/// simultaneously (on platforms that support multiple workspaces,
/// currently Mac OS X and Linux).
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#visible_on_all_workspaces-mac-linux)
pub fn visible_on_all_workspaces(self, visible_on_all_workspaces: bool) -> Self {
self.set(
"visible_on_all_workspaces",
JsValue::from(visible_on_all_workspaces),
)
}
/// whether window is fullscreen
///
/// Beware, if frame is also set to false in fullscreen it will prevent
/// the mouse from being captured on the very edges of the screen.
/// You should avoid activate it if fullscreen is also set to true.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#fullscreen)
pub fn fullscreen(self, fullscreen: bool) -> Self {
self.set("fullscreen", JsValue::from(fullscreen))
}
/// whether the window is shown in taskbar or dock. The default is `true`.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#show_in_taskbar)
pub fn show_in_taskbar(self, show_in_taskbar: bool) -> Self {
self.set("show_in_taskbar", JsValue::from(show_in_taskbar))
}
/// specify it to `false` to make the window frameless
///
/// Beware, if frame is set to false in fullscreen it will prevent the
/// mouse from being captured on the very edges of the screen.
/// You should avoid activating it if fullscreen is also set to true.
///
/// Frameless apps do not have a title bar for the user to click and
/// drag the window. You can use CSS to designate DOM elements as
/// draggable regions.
///
/// ```css
/// .drag-enable {
/// -webkit-app-region: drag;
/// }
/// .drag-disable {
/// -webkit-app-region: no-drag;
/// }
/// ```
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#frame)
pub fn frame(self, frame: bool) -> Self {
self.set("frame", JsValue::from(frame))
}
/// specify it to `false` if you want your app to be hidden on startup
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#show)
pub fn show(self, show: bool) -> Self {
self.set("show", JsValue::from(show))
}
/// whether to use `Kiosk` mode. In `Kiosk` mode, the app will be fullscreen
/// and try to prevent users from leaving the app, so you should
/// remember to provide a way in app to leave Kiosk mode.
/// This mode is mainly used for presentation on public displays
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#kiosk)
pub fn kiosk(self, kiosk: bool) -> Self {
self.set("kiosk", JsValue::from(kiosk))
}
/// whether to turn on transparent window mode.
/// The default is `false`.
/// Control the transparency with rgba background value in CSS.
/// Use command line option `--disable-transparency` to disable this
/// feature completely.
///
/// There is experimental support for "click-through" on the
/// transparent region: add `--disable-gpu` option to the command line.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#transparent)
pub fn transparent(self, transparent: bool) -> Self {
self.set("transparent", JsValue::from(transparent))
}
/// the initial left of the window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#webkit-subfields)
pub fn left(self, left: u32) -> Self {
self.set("x", JsValue::from(left))
}
/// the initial top of the window.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Manifest%20Format/#webkit-subfields)
pub fn top(self, top: u32) -> Self {
self.set("y", JsValue::from(top))
}
/// whether to open a new window in a separate render process.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#windowopenurl-options-callback)
pub fn new_instance(self, value: bool) -> Self {
self.set("new_instance", JsValue::from(value))
}
/// If true, the Node context and DOM context are merged in the new window’s process.
/// Use only when new_instance is true.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#windowopenurl-options-callback)
pub fn mixed_context(self, value: bool) -> Self {
self.set("mixed_context", JsValue::from(value))
}
/// the script to be injected before any DOM is constructed and any script is run.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#windowopenurl-options-callback)
pub fn inject_js_start(self, js: &str) -> Self {
self.set("inject_js_start", JsValue::from(js))
}
/// the script to be injected after the document object is loaded, before onload event is fired.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#windowopenurl-options-callback)
pub fn inject_js_end(self, js: &str) -> Self {
self.set("inject_js_end", JsValue::from(js))
}
}
impl std::fmt::Display for Options {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)?;
Ok(())
}
}
impl OptionsTrait for CaptureConfig {
fn initialize(self) -> Self {
self.datatype("datauri")
}
}
impl CaptureConfig {
/// The image format used to generate the image.
/// It supports two formats: "png" and "jpeg".
///
/// If ignored, it’s "jpeg" by default.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincapturepagecallback-config)
pub fn format(self, format: &str) -> Self {
self.set("format", JsValue::from(format))
}
/// It supports three types: "raw", "buffer" and "datauri".
///
/// If ignored, it’s "datauri" by default.
///
/// The `raw` only contains the Base64 encoded image.
/// But `datauri` contains the mime type headers as well,
/// and it can be directly assigned to src of Image to load the image.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincapturepagecallback-config)
///
pub fn datatype(self, datatype: &str) -> Self {
self.set("datatype", JsValue::from(datatype))
}
}
impl std::fmt::Display for CaptureConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)?;
Ok(())
}
}
impl OptionsTrait for ScreenshotConfig {}
impl ScreenshotConfig {
/// Capture the whole page beyond the visible area.
/// Currently the height of captured image is capped at 16384 pixels by Chromium.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincapturescreenshotoptions-callback)
///
pub fn fullsize(self, fullsize: bool) -> Self {
self.set("fullsize", JsValue::from(fullsize))
}
/// The image format used to generate the image.
///
/// It supports two formats: "png" and "jpeg".
///
/// "png" is the default.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincapturescreenshotoptions-callback)
///
pub fn format(self, format: &str) -> Self {
self.set("format", JsValue::from(format))
}
/// Compression quality from range [0..100] (jpeg only).
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincapturescreenshotoptions-callback)
///
pub fn quality(self, quality: u8) -> Self {
self.set("quality", JsValue::from(quality))
}
/// Capture the screenshot of a given region only.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#wincapturescreenshotoptions-callback)
///
pub fn clip(self, x: i32, y: i32, width: u32, height: u32, scale: u32) -> Self {
let clip_region = Object::new();
let items = vec![
("x", JsValue::from(x)),
("y", JsValue::from(y)),
("width", JsValue::from(width)),
("height", JsValue::from(height)),
("scale", JsValue::from(scale)),
];
for (key, value) in items {
let _ = js_sys::Reflect::set(&clip_region, &JsValue::from(key), &value);
}
self.set("clip", JsValue::from(clip_region))
}
}
impl std::fmt::Display for ScreenshotConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)?;
Ok(())
}
}
/// Window print margin
pub enum PrintMargin {
Default,
NoMargins,
Minimum,
///Custom margin: left, top, right, bottom
Custom(Option<u16>, Option<u16>, Option<u16>, Option<u16>),
}
impl OptionsTrait for PrintOptions {}
impl PrintOptions {
/// Whether to print without the need for user’s interaction; optional,
/// true by default
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn autoprint(self, autoprint: bool) -> Self {
self.set("autoprint", JsValue::from(autoprint))
}
/// Hide the flashing print preview dialog; optional, false by default
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn silent(self, silent: bool) -> Self {
self.set("silent", JsValue::from(silent))
}
/// The device name of the printer returned by `nw::Window::get_printers();`
///
/// No need to set this when printing to PDF
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn printer(self, printer: &str) -> Self {
self.set("printer", JsValue::from(printer))
}
/// The path of the output PDF when printing to PDF
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn pdf_path(self, pdf_path: &str) -> Self {
self.set("pdf_path", JsValue::from(pdf_path))
}
/// Whether to enable header and footer
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn header_footer_enabled(self, header_footer_enabled: bool) -> Self {
self.set("headerFooterEnabled", JsValue::from(header_footer_enabled))
}
/// Whether to use landscape or portrait
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn landscape(self, landscape: bool) -> Self {
self.set("landscape", JsValue::from(landscape))
}
/// The paper size spec
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn media_size(self, media_size: Object) -> Self {
self.set("mediaSize", JsValue::from(media_size))
}
/// Whether to print CSS backgrounds
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn should_print_backgrounds(self, should_print_backgrounds: bool) -> Self {
self.set(
"shouldPrintBackgrounds",
JsValue::from(should_print_backgrounds),
)
}
/// MarginsType
///
/// see margins_custom.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn margin(mut self, margin: PrintMargin) -> Self {
let margin_type = match margin {
PrintMargin::Default => 0,
PrintMargin::NoMargins => 1,
PrintMargin::Minimum => 2,
PrintMargin::Custom(l, t, r, b) => {
let margins_custom = Object::new();
let items = vec![
("marginLeft", l),
("marginTop", t),
("marginRight", r),
("marginBottom", b),
];
for (key, value) in items {
let v = value.unwrap_or(0);
let _ = js_sys::Reflect::set(
&margins_custom,
&JsValue::from(key),
&JsValue::from(v),
);
}
self = self.set("marginsCustom", JsValue::from(margins_custom));
3
}
};
self.set("marginsType", JsValue::from(margin_type))
}
/// The number of copies to print.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn copies(self, copies: u8) -> Self {
self.set("copies", JsValue::from(copies))
}
/// The scale factor; 100 is the default.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn scale_factor(self, scale_factor: u8) -> Self {
self.set("scaleFactor", JsValue::from(scale_factor))
}
/// String to replace the URL in the header.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn header_string(self, header_string: &str) -> Self {
self.set("headerString", JsValue::from(header_string))
}
/// String to replace the URL in the footer.
///
/// ⧉ [NWJS Documentation](https://docs.nwjs.io/en/latest/References/Window/#winprintoptions)
///
pub fn footer_string(self, footer_string: &str) -> Self {
self.set("footerString", JsValue::from(footer_string))
}
}
impl std::fmt::Display for PrintOptions {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)?;
Ok(())
}
}