Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove service worker #688

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ We ask that you at least take a moment to rename the website.

Large files such as NW.js, Electron, and WKWebView executables are stored on an external server outside of this repository. While we aren't actively removing old files (the server still serves files unused since November 2020), we can't promise they will exist forever. The packager uses a secure checksum to validate these downloads. Forks are free to use our servers, but it's easy to setup your own if you'd prefer (it's just a static file server; see `src/packager/large-assets.js` for more information).

### Service worker

Set the environment variable `ENABLE_SERVICE_WORKER` to `1` to enable service worker for offline support (experimental, not 100% reliable). This is not recommended in development. Our GitHub Actions deploy script uses this by default.

## Standalone builds

The packager supports generating "standalone builds" that are single HTML files containing the entire packager. Large files such as Electron binaries will still be downloaded from a remote server as needed. You can download prebuilt standalone builds from [our GitHub releases](https://github.com/TurboWarp/packager/releases). These can be useful if our website is blocked or you don't have a reliable internet connection. Note that standalone builds do not contain an update checker, so do check on your own occasionally.
Expand Down
37 changes: 0 additions & 37 deletions src/build/generate-service-worker-plugin.js

This file was deleted.

15 changes: 6 additions & 9 deletions src/p4/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import P4 from './P4.svelte';
import serviceWorker from '!!file-loader?name=sw.js!./sw.js';

const app = new P4({
target: document.getElementById('app')
});

document.body.setAttribute('p4-loaded', '');

if (process.env.ENABLE_SERVICE_WORKER && 'serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register(serviceWorker)
.then(() => {
console.log('SW registered');
}).catch((error) => {
console.log('SW error', error);
});
// Forcibly unregister any old service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.getRegistrations().then((registrations) => {
for (const registration of registrations) {
registration.unregister();
}
});
}
50 changes: 0 additions & 50 deletions src/p4/sw.js

This file was deleted.

3 changes: 0 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const CopyWebpackPlugin = require('copy-webpack-plugin');
const AddBuildIDToOutputPlugin = require('./src/build/add-build-id-to-output-plugin');
const GenerateServiceWorkerPlugin = require('./src/build/generate-service-worker-plugin');
const EagerDynamicImportPlugin = require('./src/build/eager-dynamic-import-plugin');

const isProduction = process.env.NODE_ENV === 'production';
Expand Down Expand Up @@ -180,7 +179,6 @@ const makeWebsite = () => ({
]
}),
new webpack.DefinePlugin({
'process.env.ENABLE_SERVICE_WORKER': JSON.stringify(process.env.ENABLE_SERVICE_WORKER),
'process.env.STANDALONE': JSON.stringify(isStandalone ? true : false),
'process.env.VERSION': JSON.stringify(version),
'process.env.PLAUSIBLE_API': JSON.stringify(process.env.PLAUSIBLE_API),
Expand All @@ -191,7 +189,6 @@ const makeWebsite = () => ({
template: './src/p4/template.ejs',
chunks: ['p4']
}),
new GenerateServiceWorkerPlugin(),
...(isStandalone ? [new EagerDynamicImportPlugin()] : []),
...(process.env.BUNDLE_ANALYZER === 'p4' ? [new BundleAnalyzerPlugin()] : [])
],
Expand Down