123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- function loadMainDartJs() {
- if (scriptLoaded) {
- return;
- }
- //hideSplash();
- scriptLoaded = true;
- // document.getElementsByTagName('base')[0].setAttribute("href", window.STATIC_ROOT);
- var scriptTag = document.createElement("script");
- scriptTag.src = window.STATIC_ROOT + "main.dart.js?v=" + serviceWorkerVersion;
- scriptTag.type = "application/javascript";
- document.body.append(scriptTag);
- }
- function loadVersion(callback) {
- fetch("version.json?d=" + serviceWorkerVersion)
- .then(function (res) { return res.json() })
- .then(function (data) {
- window.FLYINSONO_VERSION = data;
- callback && callback();
- });
- }
- ///外部通知
- function externalNotification(a, b) {
- window.invokeJs(a, b);
- }
- function closeSlaveWindow() {
- var shell = window["FisShellApi"];
- if (shell) {
- shell.closeSlaveWindow();
- }
- }
- function beginWindowDrag(name) {
- var shell = window["FisShellApi"];
- if (shell) {
- shell.beginWindowDrag(name);
- }
- }
- function endWindowDrag(name) {
- var shell = window["FisShellApi"];
- if (shell) {
- shell.endWindowDrag(name);
- }
- }
- function closeWindow(name) {
- var shell = window["FisShellApi"];
- if (shell) {
- shell.closeWindow(name);
- }
- }
- function maximizeWindow(name) {
- var shell = window["FisShellApi"];
- if (shell) {
- shell.maximizeWindow(name);
- }
- }
- function minimizeWindow(name) {
- var shell = window["FisShellApi"];
- if (shell) {
- shell.minimizeWindow(name);
- }
- }
- ///打印pdf
- function printPdfByBase64(base64) {
- printJS({
- printable: base64,
- type: "pdf",
- base64: true,
- });
- }
- function closeWindow(windowType) {
- var shell = window["FisShellApi"];
- if (shell) {
- shell.closeWindow(windowType);
- }
- }
- function getLanguageCode(callback) {
- var shell = window["FisShellApi"];
- if (shell) {
- var request = shell.getLanguageCode();
- request.then((v) => callback(v));
- }
- }
- function closeSlaveWindow() {
- var shell = window["FisShellApi"];
- if (shell) {
- shell.closeSlaveWindow();
- }
- }
- function beginWindowDrag(name) {
- var shell = window["FisShellApi"];
- if (shell) {
- shell.beginWindowDrag(name);
- }
- }
- function endWindowDrag(name) {
- var shell = window["FisShellApi"];
- if (shell) {
- shell.endWindowDrag(name);
- }
- }
- function closeWindow(name) {
- var shell = window["FisShellApi"];
- if (shell) {
- shell.closeWindow(name);
- }
- }
- function maximizeWindow(name) {
- var shell = window["FisShellApi"];
- if (shell) {
- shell.maximizeWindow(name);
- }
- }
- function minimizeWindow(name) {
- var shell = window["FisShellApi"];
- if (shell) {
- shell.minimizeWindow(name);
- }
- }
- window.addEventListener("flutter-first-frame", function () {
- console.log("flutter-first-frame");
- });
- function loadService() {
- if ("serviceWorker" in navigator) {
- // Service workers are supported. Use them.
- window.addEventListener("load", function () {
- // Wait for registration to finish before dropping the <script> tag.
- // Otherwise, the browser will load the script multiple times,
- // potentially different versions.
- var serviceWorkerUrl =
- "./flutter_service_worker.js?v=" + serviceWorkerVersion;
- navigator.serviceWorker.register(serviceWorkerUrl).then((reg) => {
- function waitForActivation(serviceWorker) {
- serviceWorker.addEventListener("statechange", () => {
- if (serviceWorker.state == "activated") {
- console.log("Installed new service worker.");
- loadMainDartJs();
- }
- });
- }
- if (!reg.active && (reg.installing || reg.waiting)) {
- // No active web worker and we have installed or are installing
- // one for the first time. Simply wait for it to activate.
- waitForActivation(reg.installing || reg.waiting);
- } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
- // When the app updates the serviceWorkerVersion changes, so we
- // need to ask the service worker to update.
- console.log("New service worker available.");
- reg.update().then((data) => {
- var worker = data.installing || data.waiting || data.active;
- waitForActivation(worker);
- });
- // waitForActivation(reg.installing);
- } else {
- // Existing service worker is still good.
- console.log("Loading app from service worker.");
- loadMainDartJs();
- }
- });
- // If service worker doesn't succeed in a reasonable amount of time,
- // fallback to plaint <script> tag.
- setTimeout(() => {
- if (!scriptLoaded) {
- console.warn(
- "Failed to load app from service worker. Falling back to plain <script> tag."
- );
- loadMainDartJs();
- }
- }, 4000);
- });
- } else {
- // Service workers not supported. Just drop the <script> tag.
- loadMainDartJs();
- }
- }
- function kIsWechat() {
- return window.__wxjs_environment === "miniprogram";
- }
|