Update github actions
This commit is contained in:
24
src/main.ts
24
src/main.ts
@@ -4,6 +4,7 @@ import App from "./App.svelte";
|
||||
import { loadData } from "./ts/storage/globalApi";
|
||||
import { initHotkey } from "./ts/hotkey";
|
||||
import { polyfill } from "./ts/polyfill";
|
||||
import { preLoadCheck } from "./preload";
|
||||
|
||||
const errorHandler = (event: ErrorEvent) => {
|
||||
console.error(event.error)
|
||||
@@ -23,18 +24,21 @@ export const removeDefaultHandler = () => {
|
||||
}
|
||||
|
||||
let app: App;
|
||||
try {
|
||||
polyfill()
|
||||
|
||||
app = new App({
|
||||
target: document.getElementById("app"),
|
||||
});
|
||||
if(preLoadCheck()){
|
||||
try {
|
||||
polyfill()
|
||||
|
||||
loadData()
|
||||
initHotkey()
|
||||
} catch (error) {
|
||||
console.error(error, error.stack)
|
||||
alert(error)
|
||||
app = new App({
|
||||
target: document.getElementById("app"),
|
||||
});
|
||||
|
||||
loadData()
|
||||
initHotkey()
|
||||
} catch (error) {
|
||||
console.error(error, error.stack)
|
||||
alert(error)
|
||||
}
|
||||
}
|
||||
|
||||
export default app;
|
||||
29
src/preload.ts
Normal file
29
src/preload.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
export function preLoadCheck(){
|
||||
const searchParams = new URLSearchParams(location.search);
|
||||
|
||||
//@ts-ignore
|
||||
const isTauri = !!window.__TAURI__
|
||||
//@ts-ignore
|
||||
const isNodeServer = !!globalThis.__NODE__
|
||||
|
||||
const isWeb = !isTauri && !isNodeServer && location.hostname !== 'risuai.xyz';
|
||||
|
||||
|
||||
// Check if the user has visited the main page
|
||||
if(!isWeb) {
|
||||
localStorage.setItem('mainpage', 'visited');
|
||||
}
|
||||
else if(searchParams.has('mainpage')) {
|
||||
localStorage.setItem('mainpage', searchParams.get('main-page'));
|
||||
}
|
||||
|
||||
|
||||
// Redirect to the main page if the user has not visited the main page
|
||||
if(localStorage.getItem('mainpage') !== 'visited') {
|
||||
localStorage.setItem('mainpage', 'visited');
|
||||
location.replace('https://risuai.net');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user