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/get-user-preferences";
|
||||||
import "./user-preferences/update-user-preferences";
|
import "./user-preferences/update-user-preferences";
|
||||||
import "./user-preferences/auto-launch";
|
import "./user-preferences/auto-launch";
|
||||||
|
import "./autoupdater/check-for-updates";
|
||||||
|
|
||||||
ipcMain.handle("ping", () => "pong");
|
ipcMain.handle("ping", () => "pong");
|
||||||
ipcMain.handle("getVersion", () => app.getVersion());
|
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.
|
// Load the remote URL for development or the local html file for production.
|
||||||
if (is.dev && process.env["ELECTRON_RENDERER_URL"]) {
|
if (is.dev && process.env["ELECTRON_RENDERER_URL"]) {
|
||||||
this.splashWindow?.loadURL(
|
this.splashWindow?.loadURL(
|
||||||
`${process.env["ELECTRON_RENDERER_URL"]}/splash.html`
|
`${process.env["ELECTRON_RENDERER_URL"]}#/splash`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.splashWindow?.loadFile(
|
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,
|
height: 400,
|
||||||
frame: true,
|
frame: true,
|
||||||
alwaysOnTop: false,
|
alwaysOnTop: false,
|
||||||
|
webPreferences: {
|
||||||
|
preload: path.join(__dirname, "../preload/index.mjs"),
|
||||||
|
sandbox: false,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
this.loadSplashURL();
|
this.loadSplashURL();
|
||||||
|
@ -7,6 +7,7 @@ import type {
|
|||||||
GameShop,
|
GameShop,
|
||||||
TorrentProgress,
|
TorrentProgress,
|
||||||
UserPreferences,
|
UserPreferences,
|
||||||
|
AppUpdaterEvents,
|
||||||
} from "@types";
|
} from "@types";
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld("electron", {
|
contextBridge.exposeInMainWorld("electron", {
|
||||||
@ -112,4 +113,8 @@ contextBridge.exposeInMainWorld("electron", {
|
|||||||
showOpenDialog: (options: Electron.OpenDialogOptions) =>
|
showOpenDialog: (options: Electron.OpenDialogOptions) =>
|
||||||
ipcRenderer.invoke("showOpenDialog", options),
|
ipcRenderer.invoke("showOpenDialog", options),
|
||||||
platform: process.platform,
|
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 * as styles from "./app.css";
|
||||||
import { themeClass } from "./theme.css";
|
import { themeClass } from "./theme.css";
|
||||||
|
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { Outlet, useLocation, useNavigate } from "react-router-dom";
|
||||||
import {
|
import {
|
||||||
setSearch,
|
setSearch,
|
||||||
clearSearch,
|
clearSearch,
|
||||||
@ -27,7 +27,7 @@ export interface AppProps {
|
|||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function App({ children }: AppProps) {
|
export function App() {
|
||||||
const contentRef = useRef<HTMLDivElement>(null);
|
const contentRef = useRef<HTMLDivElement>(null);
|
||||||
const { updateLibrary } = useLibrary();
|
const { updateLibrary } = useLibrary();
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ export function App({ children }: AppProps) {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<section ref={contentRef} className={styles.content}>
|
<section ref={contentRef} className={styles.content}>
|
||||||
{children}
|
<Outlet />
|
||||||
</section>
|
</section>
|
||||||
</article>
|
</article>
|
||||||
</main>
|
</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
|
options: Electron.OpenDialogOptions
|
||||||
) => Promise<Electron.OpenDialogReturnValue>;
|
) => Promise<Electron.OpenDialogReturnValue>;
|
||||||
platform: NodeJS.Platform;
|
platform: NodeJS.Platform;
|
||||||
|
|
||||||
|
/* Splash */
|
||||||
|
checkForUpdates: (cb: (value: AppUpdaterEvents) => void) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Window {
|
interface Window {
|
||||||
|
@ -27,6 +27,7 @@ import {
|
|||||||
import { store } from "./store";
|
import { store } from "./store";
|
||||||
|
|
||||||
import * as resources from "@locales";
|
import * as resources from "@locales";
|
||||||
|
import Splash from "./pages/splash/splash";
|
||||||
|
|
||||||
i18n
|
i18n
|
||||||
.use(LanguageDetector)
|
.use(LanguageDetector)
|
||||||
@ -46,16 +47,17 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
|
|||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<HashRouter>
|
<HashRouter>
|
||||||
<App>
|
<Routes>
|
||||||
<Routes>
|
<Route path="/" Component={Splash} />
|
||||||
<Route path="/" Component={Home} />
|
<Route element={<App />}>
|
||||||
|
<Route path="/teste" Component={Home} />
|
||||||
<Route path="/catalogue" Component={Catalogue} />
|
<Route path="/catalogue" Component={Catalogue} />
|
||||||
<Route path="/downloads" Component={Downloads} />
|
<Route path="/downloads" Component={Downloads} />
|
||||||
<Route path="/game/:shop/:objectID" Component={GameDetails} />
|
<Route path="/game/:shop/:objectID" Component={GameDetails} />
|
||||||
<Route path="/search" Component={SearchResults} />
|
<Route path="/search" Component={SearchResults} />
|
||||||
<Route path="/settings" Component={Settings} />
|
<Route path="/settings" Component={Settings} />
|
||||||
</Routes>
|
</Route>
|
||||||
</App>
|
</Routes>
|
||||||
</HashRouter>
|
</HashRouter>
|
||||||
</Provider>
|
</Provider>
|
||||||
</React.StrictMode>
|
</React.StrictMode>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { style } from "@vanilla-extract/css";
|
import { style } from "@vanilla-extract/css";
|
||||||
import { SPACING_UNIT, vars } from "../../theme.css";
|
import { SPACING_UNIT } from "../../theme.css";
|
||||||
|
|
||||||
export const main = style({
|
export const main = style({
|
||||||
width: "100%",
|
width: "100%",
|
||||||
|
@ -3,10 +3,18 @@ import * as styles from "./splash.css";
|
|||||||
import { themeClass } from "../../theme.css";
|
import { themeClass } from "../../theme.css";
|
||||||
|
|
||||||
import "../../app.css";
|
import "../../app.css";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
document.body.classList.add(themeClass);
|
document.body.classList.add(themeClass);
|
||||||
|
|
||||||
export default function Splash() {
|
export default function Splash() {
|
||||||
|
useEffect(() => {
|
||||||
|
window.electron.checkForUpdates((event) => {
|
||||||
|
console.log("-----------");
|
||||||
|
console.log(event);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className={styles.main}>
|
<main className={styles.main}>
|
||||||
<img src={icon} className={styles.splashIcon} alt="" />
|
<img src={icon} className={styles.splashIcon} alt="" />
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
import type { Downloader, GameStatus } from "@shared";
|
import type { Downloader, GameStatus } from "@shared";
|
||||||
|
import {
|
||||||
|
ProgressInfo,
|
||||||
|
UpdateDownloadedEvent,
|
||||||
|
UpdateInfo,
|
||||||
|
} from "electron-updater";
|
||||||
|
|
||||||
export type GameShop = "steam" | "epic";
|
export type GameShop = "steam" | "epic";
|
||||||
export type CatalogueCategory = "recently_added" | "trending";
|
export type CatalogueCategory = "recently_added" | "trending";
|
||||||
@ -143,3 +148,32 @@ export interface SteamGame {
|
|||||||
name: string;
|
name: string;
|
||||||
clientIcon: string | null;
|
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