Skip to content

Commit

Permalink
feat: add network online checking
Browse files Browse the repository at this point in the history
  • Loading branch information
flingyp committed Sep 13, 2023
1 parent dd74d6b commit 549cb3d
Show file tree
Hide file tree
Showing 8 changed files with 2,122 additions and 2,097 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "@flypeng"
"extends": "@flypeng",
"ignorePatterns": ["dev-dist/*"]
}
2 changes: 2 additions & 0 deletions auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ declare global {
const useMousePressed: typeof import('@vueuse/core')['useMousePressed']
const useMutationObserver: typeof import('@vueuse/core')['useMutationObserver']
const useNaiveMessage: typeof import('./src/composables/common/useNaiveMessage/index')['useNaiveMessage']
const useNaiveNotification: typeof import('./src/composables/common/useNaiveNotification/index')['useNaiveNotification']
const useNavigatorLanguage: typeof import('@vueuse/core')['useNavigatorLanguage']
const useNetwork: typeof import('@vueuse/core')['useNetwork']
const useNow: typeof import('@vueuse/core')['useNow']
Expand Down Expand Up @@ -540,6 +541,7 @@ declare module 'vue' {
readonly useMousePressed: UnwrapRef<typeof import('@vueuse/core')['useMousePressed']>
readonly useMutationObserver: UnwrapRef<typeof import('@vueuse/core')['useMutationObserver']>
readonly useNaiveMessage: UnwrapRef<typeof import('./src/composables/common/useNaiveMessage/index')['useNaiveMessage']>
readonly useNaiveNotification: UnwrapRef<typeof import('./src/composables/common/useNaiveNotification/index')['useNaiveNotification']>
readonly useNavigatorLanguage: UnwrapRef<typeof import('@vueuse/core')['useNavigatorLanguage']>
readonly useNetwork: UnwrapRef<typeof import('@vueuse/core')['useNetwork']>
readonly useNow: UnwrapRef<typeof import('@vueuse/core')['useNow']>
Expand Down
2 changes: 1 addition & 1 deletion dev-dist/registerSW.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
if('serviceWorker' in navigator) navigator.serviceWorker.register('/dev-sw.js?dev-sw', { scope: '/', type: 'classic' })
if ('serviceWorker' in navigator) navigator.serviceWorker.register('/dev-sw.js?dev-sw', { scope: '/', type: 'classic' })
100 changes: 49 additions & 51 deletions dev-dist/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,80 +13,78 @@

// If the loader is already loaded, just stop.
if (!self.define) {
let registry = {};
const registry = {}

// Used for `eval` and `importScripts` where we can't get script URL by other means.
// In both cases, it's safe to use a global var because those functions are synchronous.
let nextDefineUri;
let nextDefineUri

const singleRequire = (uri, parentUri) => {
uri = new URL(uri + ".js", parentUri).href;
uri = new URL(`${uri}.js`, parentUri).href
return registry[uri] || (

new Promise(resolve => {
if ("document" in self) {
const script = document.createElement("script");
script.src = uri;
script.onload = resolve;
document.head.appendChild(script);
} else {
nextDefineUri = uri;
importScripts(uri);
resolve();
}
})

.then(() => {
let promise = registry[uri];
if (!promise) {
throw new Error(`Module ${uri} didn’t register its module`);

new Promise((resolve) => {
if ('document' in self) {
const script = document.createElement('script')
script.src = uri
script.onload = resolve
document.head.appendChild(script)
} else {
nextDefineUri = uri
importScripts(uri)
resolve()
}
return promise;
})
);
};

.then(() => {
const promise = registry[uri]
if (!promise) {
throw new Error(`Module ${uri} didn’t register its module`)
}
return promise
})
)
}

self.define = (depsNames, factory) => {
const uri = nextDefineUri || ("document" in self ? document.currentScript.src : "") || location.href;
const uri = nextDefineUri || ('document' in self ? document.currentScript.src : '') || location.href
if (registry[uri]) {
// Module is already loading or loaded.
return;
return
}
let exports = {};
const require = depUri => singleRequire(depUri, uri);
const exports = {}
const require = (depUri) => singleRequire(depUri, uri)
const specialDeps = {
module: { uri },
exports,
require
};
require,
}
registry[uri] = Promise.all(depsNames.map(
depName => specialDeps[depName] || require(depName)
)).then(deps => {
factory(...deps);
return exports;
});
};
(depName) => specialDeps[depName] || require(depName),
)).then((deps) => {
factory(...deps)
return exports
})
}
}
define(['./workbox-ab7aa862'], (function (workbox) { 'use strict';

self.skipWaiting();
workbox.clientsClaim();
define(['./workbox-ab7aa862'], ((workbox) => {
self.skipWaiting()
workbox.clientsClaim()

/**
* The precacheAndRoute() method efficiently caches and responds to
* requests for URLs in the manifest.
* See https://goo.gl/S9QRab
*/
workbox.precacheAndRoute([{
"url": "registerSW.js",
"revision": "3ca0b8505b4bec776b69afdba2768812"
url: 'registerSW.js',
revision: '3ca0b8505b4bec776b69afdba2768812',
}, {
"url": "index.html",
"revision": "0.kmkb1uarnq"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
allowlist: [/^\/$/]
}));

}));
url: 'index.html',
revision: '0.ifpga1ik8r8',
}], {})
workbox.cleanupOutdatedCaches()
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL('index.html'), {
allowlist: [/^\/$/],
}))
}))

0 comments on commit 549cb3d

Please sign in to comment.