index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. function loadMainDartJs() {
  2. if (scriptLoaded) {
  3. return;
  4. }
  5. //hideSplash();
  6. scriptLoaded = true;
  7. // document.getElementsByTagName('base')[0].setAttribute("href", window.STATIC_ROOT);
  8. var scriptTag = document.createElement("script");
  9. scriptTag.src = window.STATIC_ROOT + "main.dart.js?v=" + serviceWorkerVersion;
  10. scriptTag.type = "application/javascript";
  11. document.body.append(scriptTag);
  12. }
  13. function loadVersion(callback) {
  14. fetch("version.json?d=" + serviceWorkerVersion)
  15. .then(function (res) { return res.json() })
  16. .then(function (data) {
  17. window.FLYINSONO_VERSION = data;
  18. callback && callback();
  19. });
  20. }
  21. ///外部通知
  22. function externalNotification(a, b) {
  23. window.invokeJs(a, b);
  24. }
  25. function closeSlaveWindow() {
  26. var shell = window["FisShellApi"];
  27. if (shell) {
  28. shell.closeSlaveWindow();
  29. }
  30. }
  31. function beginWindowDrag(name) {
  32. var shell = window["FisShellApi"];
  33. if (shell) {
  34. shell.beginWindowDrag(name);
  35. }
  36. }
  37. function endWindowDrag(name) {
  38. var shell = window["FisShellApi"];
  39. if (shell) {
  40. shell.endWindowDrag(name);
  41. }
  42. }
  43. function closeWindow(name) {
  44. var shell = window["FisShellApi"];
  45. if (shell) {
  46. shell.closeWindow(name);
  47. }
  48. }
  49. function maximizeWindow(name) {
  50. var shell = window["FisShellApi"];
  51. if (shell) {
  52. shell.maximizeWindow(name);
  53. }
  54. }
  55. function minimizeWindow(name) {
  56. var shell = window["FisShellApi"];
  57. if (shell) {
  58. shell.minimizeWindow(name);
  59. }
  60. }
  61. ///打印pdf
  62. function printPdfByBase64(base64) {
  63. printJS({
  64. printable: base64,
  65. type: "pdf",
  66. base64: true,
  67. });
  68. }
  69. function closeWindow(windowType) {
  70. var shell = window["FisShellApi"];
  71. if (shell) {
  72. shell.closeWindow(windowType);
  73. }
  74. }
  75. function getLanguageCode(callback) {
  76. var shell = window["FisShellApi"];
  77. if (shell) {
  78. var request = shell.getLanguageCode();
  79. request.then((v) => callback(v));
  80. }
  81. }
  82. function closeSlaveWindow() {
  83. var shell = window["FisShellApi"];
  84. if (shell) {
  85. shell.closeSlaveWindow();
  86. }
  87. }
  88. function beginWindowDrag(name) {
  89. var shell = window["FisShellApi"];
  90. if (shell) {
  91. shell.beginWindowDrag(name);
  92. }
  93. }
  94. function endWindowDrag(name) {
  95. var shell = window["FisShellApi"];
  96. if (shell) {
  97. shell.endWindowDrag(name);
  98. }
  99. }
  100. function closeWindow(name) {
  101. var shell = window["FisShellApi"];
  102. if (shell) {
  103. shell.closeWindow(name);
  104. }
  105. }
  106. function maximizeWindow(name) {
  107. var shell = window["FisShellApi"];
  108. if (shell) {
  109. shell.maximizeWindow(name);
  110. }
  111. }
  112. function minimizeWindow(name) {
  113. var shell = window["FisShellApi"];
  114. if (shell) {
  115. shell.minimizeWindow(name);
  116. }
  117. }
  118. window.addEventListener("flutter-first-frame", function () {
  119. console.log("flutter-first-frame");
  120. });
  121. function loadService() {
  122. if ("serviceWorker" in navigator) {
  123. // Service workers are supported. Use them.
  124. window.addEventListener("load", function () {
  125. // Wait for registration to finish before dropping the <script> tag.
  126. // Otherwise, the browser will load the script multiple times,
  127. // potentially different versions.
  128. var serviceWorkerUrl =
  129. "./flutter_service_worker.js?v=" + serviceWorkerVersion;
  130. navigator.serviceWorker.register(serviceWorkerUrl).then((reg) => {
  131. function waitForActivation(serviceWorker) {
  132. serviceWorker.addEventListener("statechange", () => {
  133. if (serviceWorker.state == "activated") {
  134. console.log("Installed new service worker.");
  135. loadMainDartJs();
  136. }
  137. });
  138. }
  139. if (!reg.active && (reg.installing || reg.waiting)) {
  140. // No active web worker and we have installed or are installing
  141. // one for the first time. Simply wait for it to activate.
  142. waitForActivation(reg.installing || reg.waiting);
  143. } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
  144. // When the app updates the serviceWorkerVersion changes, so we
  145. // need to ask the service worker to update.
  146. console.log("New service worker available.");
  147. reg.update().then((data) => {
  148. var worker = data.installing || data.waiting || data.active;
  149. waitForActivation(worker);
  150. });
  151. // waitForActivation(reg.installing);
  152. } else {
  153. // Existing service worker is still good.
  154. console.log("Loading app from service worker.");
  155. loadMainDartJs();
  156. }
  157. });
  158. // If service worker doesn't succeed in a reasonable amount of time,
  159. // fallback to plaint <script> tag.
  160. setTimeout(() => {
  161. if (!scriptLoaded) {
  162. console.warn(
  163. "Failed to load app from service worker. Falling back to plain <script> tag."
  164. );
  165. loadMainDartJs();
  166. }
  167. }, 4000);
  168. });
  169. } else {
  170. // Service workers not supported. Just drop the <script> tag.
  171. loadMainDartJs();
  172. }
  173. }
  174. function kIsWechat() {
  175. return window.__wxjs_environment === "miniprogram";
  176. }