Skip to content

Commit

Permalink
Mobile improvements.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 56c3e13aca3a7e2752c61b1fac7f2cb723cb6781
  • Loading branch information
cpojer committed Nov 29, 2024
1 parent 3984a96 commit ddaf187
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 62 deletions.
44 changes: 1 addition & 43 deletions offline/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -213,48 +213,6 @@
</p>
<a>Try again</a>
</div>
<script type="text/javascript">
let timer;
const reload = () => {
if (window.$__AC__) {
window.$__AC__.reload();
return;
}

if ($SERVER_URL) {
location.href = $SERVER_URL;
}
};
const setTimer = () => {
timer = setTimeout(() => {
if (navigator.onLine) {
reload();
timer = null;
} else {
setTimer();
}
}, 1000);
};

document.getElementById('box').addEventListener('click', reload);
document
.getElementById('keyart')
.addEventListener('dragstart', (event) => event.preventDefault());

window.addEventListener('offline', () => {
clearTimeout(timer);
timer = null;
});

window.addEventListener('online', () => {
if (navigator.onLine && !timer) {
setTimer();
}
});

if (navigator.onLine) {
setTimer();
}
</script>
<script src="/index.js" type="module"></script>
</body>
</html>
50 changes: 50 additions & 0 deletions offline/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Capacitor, registerPlugin } from '@capacitor/core';

const ReloadWebViewPlugin = registerPlugin('ReloadWebViewPlugin');

let timer;
const reload = () => {
if (window.$__AC__) {
window.$__AC__.reload();
return;
}

if (Capacitor.getPlatform() === 'android' && ReloadWebViewPlugin) {
ReloadWebViewPlugin.reload();
return;
}

if (process.env.CLIENT_URL) {
location.href = process.env.CLIENT_URL;
}
};
const setTimer = () => {
timer = setTimeout(() => {
if (navigator.onLine) {
reload();
timer = null;
} else {
setTimer();
}
}, 1000);
};

document.getElementById('box').addEventListener('click', reload);
document
.getElementById('keyart')
.addEventListener('dragstart', (event) => event.preventDefault());

window.addEventListener('offline', () => {
clearTimeout(timer);
timer = null;
});

window.addEventListener('online', () => {
if (navigator.onLine && !timer) {
setTimer();
}
});

if (navigator.onLine) {
setTimer();
}
1 change: 1 addition & 0 deletions offline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author": "Christoph Nakazawa <[email protected]>",
"type": "module",
"devDependencies": {
"@capacitor/core": "^6.2.0",
"vite-plugin-minify": "^2.0.1",
"vite-plugin-singlefile": "^2.0.3"
}
Expand Down
30 changes: 11 additions & 19 deletions offline/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@ import { ViteMinifyPlugin as minifyHTMLPlugin } from 'vite-plugin-minify';
import { viteSingleFile } from 'vite-plugin-singlefile';

export default defineConfig({
plugins: [
{
name: 'html-transform',
transformIndexHtml(html: string) {
return html.replaceAll(
'$SERVER_URL',
process.env.NODE_ENV === 'production'
? '"https://app.athenacrisis.com/"'
: `"http://${
execSync(`ifconfig | grep "inet " | grep -v 127.0.0.1`)
.toString()
.match(/inet\s+(\d.+)\s+netmask/i)?.[1] || 'localhost'
}:3000"`,
);
},
},
viteSingleFile(),
minifyHTMLPlugin(),
],
define: {
'process.env.CLIENT_URL':
process.env.NODE_ENV === 'production'
? '"https://app.athenacrisis.com/"'
: `"http://${
execSync(`ifconfig | grep "inet " | grep -v 127.0.0.1`)
.toString()
.match(/inet\s+(\d.+)\s+netmask/i)?.[1] || 'localhost'
}:3000"`,
},
plugins: [viteSingleFile(), minifyHTMLPlugin()],
});
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ddaf187

Please sign in to comment.