mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-03 00:33:49 +03:00
create electron event
This commit is contained in:
parent
484e79dba3
commit
3b17953a82
42
src/main/events/autoupdater/check-for-updates.ts
Normal file
42
src/main/events/autoupdater/check-for-updates.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { AppUpdaterEvents } from "@types";
|
||||
import { registerEvent } from "../register-event";
|
||||
import updater, {
|
||||
ProgressInfo,
|
||||
UpdateDownloadedEvent,
|
||||
UpdateInfo,
|
||||
} from "electron-updater";
|
||||
|
||||
const { autoUpdater } = updater;
|
||||
|
||||
const checkForUpdates = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
cb: (value: AppUpdaterEvents) => void
|
||||
) => {
|
||||
console.log("check for updates event");
|
||||
autoUpdater
|
||||
.addListener("error", (error: Error, message?: string) => {
|
||||
cb({ error, message });
|
||||
})
|
||||
.addListener("checking-for-update", () => {
|
||||
cb("checking-for-updates");
|
||||
})
|
||||
.addListener("update-not-available", (info: UpdateInfo) => {
|
||||
cb(info);
|
||||
})
|
||||
.addListener("update-available", (info: UpdateInfo) => {
|
||||
cb(info);
|
||||
})
|
||||
.addListener("update-downloaded", (event: UpdateDownloadedEvent) => {
|
||||
cb(event);
|
||||
})
|
||||
.addListener("download-progress", (info: ProgressInfo) => {
|
||||
cb(info);
|
||||
})
|
||||
.addListener("update-cancelled", (info: UpdateInfo) => {
|
||||
cb(info);
|
||||
});
|
||||
|
||||
autoUpdater.checkForUpdates();
|
||||
};
|
||||
|
||||
registerEvent("checkForUpdates", checkForUpdates);
|
@ -27,6 +27,7 @@ import "./torrenting/start-game-download";
|
||||
import "./user-preferences/get-user-preferences";
|
||||
import "./user-preferences/update-user-preferences";
|
||||
import "./user-preferences/auto-launch";
|
||||
import "./autoupdater/check-for-updates";
|
||||
|
||||
ipcMain.handle("ping", () => "pong");
|
||||
ipcMain.handle("getVersion", () => app.getVersion());
|
||||
|
@ -41,11 +41,14 @@ export class WindowManager {
|
||||
// Load the remote URL for development or the local html file for production.
|
||||
if (is.dev && process.env["ELECTRON_RENDERER_URL"]) {
|
||||
this.splashWindow?.loadURL(
|
||||
`${process.env["ELECTRON_RENDERER_URL"]}/splash.html`
|
||||
`${process.env["ELECTRON_RENDERER_URL"]}#/splash`
|
||||
);
|
||||
} else {
|
||||
this.splashWindow?.loadFile(
|
||||
path.join(__dirname, "../renderer/splash.html")
|
||||
path.join(__dirname, "../renderer/index.html"),
|
||||
{
|
||||
hash: "splash",
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -56,6 +59,10 @@ export class WindowManager {
|
||||
height: 400,
|
||||
frame: true,
|
||||
alwaysOnTop: false,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, "../preload/index.mjs"),
|
||||
sandbox: false,
|
||||
},
|
||||
});
|
||||
|
||||
this.loadSplashURL();
|
||||
|
@ -7,6 +7,7 @@ import type {
|
||||
GameShop,
|
||||
TorrentProgress,
|
||||
UserPreferences,
|
||||
AppUpdaterEvents,
|
||||
} from "@types";
|
||||
|
||||
contextBridge.exposeInMainWorld("electron", {
|
||||
@ -112,4 +113,8 @@ contextBridge.exposeInMainWorld("electron", {
|
||||
showOpenDialog: (options: Electron.OpenDialogOptions) =>
|
||||
ipcRenderer.invoke("showOpenDialog", options),
|
||||
platform: process.platform,
|
||||
|
||||
/* Splash */
|
||||
checkForUpdates: (cb: (value: AppUpdaterEvents) => void) =>
|
||||
ipcRenderer.invoke("checkForUpdates", cb),
|
||||
});
|
||||
|
@ -1,16 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Hydra</title>
|
||||
<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://steamcdn-a.akamaihd.net https://cdn.cloudflare.steamstatic.com https://cdn2.steamgriddb.com https://cdn.akamai.steamstatic.com; media-src 'self' data: https://steamcdn-a.akamaihd.net https://cdn.cloudflare.steamstatic.com https://cdn2.steamgriddb.com https://cdn.akamai.steamstatic.com;"
|
||||
/>
|
||||
</head>
|
||||
<body style="background-color: #1c1c1c">
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/splash.tsx"></script>
|
||||
</body>
|
||||
</html>
|
@ -12,7 +12,7 @@ import {
|
||||
import * as styles from "./app.css";
|
||||
import { themeClass } from "./theme.css";
|
||||
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import { Outlet, useLocation, useNavigate } from "react-router-dom";
|
||||
import {
|
||||
setSearch,
|
||||
clearSearch,
|
||||
@ -27,7 +27,7 @@ export interface AppProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
export function App({ children }: AppProps) {
|
||||
export function App() {
|
||||
const contentRef = useRef<HTMLDivElement>(null);
|
||||
const { updateLibrary } = useLibrary();
|
||||
|
||||
@ -128,7 +128,7 @@ export function App({ children }: AppProps) {
|
||||
/>
|
||||
|
||||
<section ref={contentRef} className={styles.content}>
|
||||
{children}
|
||||
<Outlet />
|
||||
</section>
|
||||
</article>
|
||||
</main>
|
||||
|
3
src/renderer/src/declaration.d.ts
vendored
3
src/renderer/src/declaration.d.ts
vendored
@ -90,6 +90,9 @@ declare global {
|
||||
options: Electron.OpenDialogOptions
|
||||
) => Promise<Electron.OpenDialogReturnValue>;
|
||||
platform: NodeJS.Platform;
|
||||
|
||||
/* Splash */
|
||||
checkForUpdates: (cb: (value: AppUpdaterEvents) => void) => Promise<void>;
|
||||
}
|
||||
|
||||
interface Window {
|
||||
|
@ -27,6 +27,7 @@ import {
|
||||
import { store } from "./store";
|
||||
|
||||
import * as resources from "@locales";
|
||||
import Splash from "./pages/splash/splash";
|
||||
|
||||
i18n
|
||||
.use(LanguageDetector)
|
||||
@ -46,16 +47,17 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
|
||||
<React.StrictMode>
|
||||
<Provider store={store}>
|
||||
<HashRouter>
|
||||
<App>
|
||||
<Routes>
|
||||
<Route path="/" Component={Home} />
|
||||
<Routes>
|
||||
<Route path="/" Component={Splash} />
|
||||
<Route element={<App />}>
|
||||
<Route path="/teste" Component={Home} />
|
||||
<Route path="/catalogue" Component={Catalogue} />
|
||||
<Route path="/downloads" Component={Downloads} />
|
||||
<Route path="/game/:shop/:objectID" Component={GameDetails} />
|
||||
<Route path="/search" Component={SearchResults} />
|
||||
<Route path="/settings" Component={Settings} />
|
||||
</Routes>
|
||||
</App>
|
||||
</Route>
|
||||
</Routes>
|
||||
</HashRouter>
|
||||
</Provider>
|
||||
</React.StrictMode>
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { style } from "@vanilla-extract/css";
|
||||
import { SPACING_UNIT, vars } from "../../theme.css";
|
||||
import { SPACING_UNIT } from "../../theme.css";
|
||||
|
||||
export const main = style({
|
||||
width: "100%",
|
||||
|
@ -3,10 +3,18 @@ import * as styles from "./splash.css";
|
||||
import { themeClass } from "../../theme.css";
|
||||
|
||||
import "../../app.css";
|
||||
import { useEffect } from "react";
|
||||
|
||||
document.body.classList.add(themeClass);
|
||||
|
||||
export default function Splash() {
|
||||
useEffect(() => {
|
||||
window.electron.checkForUpdates((event) => {
|
||||
console.log("-----------");
|
||||
console.log(event);
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<main className={styles.main}>
|
||||
<img src={icon} className={styles.splashIcon} alt="" />
|
||||
|
@ -1,4 +1,9 @@
|
||||
import type { Downloader, GameStatus } from "@shared";
|
||||
import {
|
||||
ProgressInfo,
|
||||
UpdateDownloadedEvent,
|
||||
UpdateInfo,
|
||||
} from "electron-updater";
|
||||
|
||||
export type GameShop = "steam" | "epic";
|
||||
export type CatalogueCategory = "recently_added" | "trending";
|
||||
@ -143,3 +148,32 @@ export interface SteamGame {
|
||||
name: string;
|
||||
clientIcon: string | null;
|
||||
}
|
||||
|
||||
interface ErrorEvent {
|
||||
error: Error;
|
||||
message?: string;
|
||||
}
|
||||
|
||||
interface UpdateNotAvailable {
|
||||
info: UpdateInfo;
|
||||
}
|
||||
interface UpdateAvailable {
|
||||
info: UpdateInfo;
|
||||
}
|
||||
interface UpdateDownloaded {
|
||||
event: UpdateDownloadedEvent;
|
||||
}
|
||||
interface DownloadProgress {
|
||||
info: ProgressInfo;
|
||||
}
|
||||
interface UpdateCancelled {
|
||||
info: UpdateInfo;
|
||||
}
|
||||
|
||||
export type AppUpdaterEvents =
|
||||
| ErrorEvent
|
||||
| UpdateNotAvailable
|
||||
| UpdateAvailable
|
||||
| UpdateDownloaded
|
||||
| DownloadProgress
|
||||
| UpdateCancelled;
|
||||
|
Loading…
Reference in New Issue
Block a user