From a429bcf6c974794e75785a8db4ff53e93667c8be Mon Sep 17 00:00:00 2001 From: Artemy Date: Tue, 20 Jun 2023 17:19:55 +0300 Subject: [PATCH] fix: get appdata --- src/preload/index.js | 4 +--- src/renderer/src/components/utils.js | 6 ++++-- src/renderer/src/pages/Main.jsx | 13 ++++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/preload/index.js b/src/preload/index.js index a0636a8..3fd54b1 100644 --- a/src/preload/index.js +++ b/src/preload/index.js @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import { contextBridge, nativeImage } from 'electron' +import { contextBridge } from 'electron' import { electronAPI } from '@electron-toolkit/preload' // Custom APIs for renderer @@ -24,7 +24,6 @@ const api = {} // just add to the DOM global. if (process.contextIsolated) { try { - contextBridge.exposeInMainWorld('nativeImage', nativeImage) contextBridge.exposeInMainWorld('electron', electronAPI) contextBridge.exposeInMainWorld('api', api) } catch (error) { @@ -33,5 +32,4 @@ if (process.contextIsolated) { } else { window.electron = electronAPI window.api = api - window.nativeImage = nativeImage } diff --git a/src/renderer/src/components/utils.js b/src/renderer/src/components/utils.js index 027503d..95e2253 100644 --- a/src/renderer/src/components/utils.js +++ b/src/renderer/src/components/utils.js @@ -1,8 +1,9 @@ import { Client, Authenticator } from 'pimi-launcher-core' import path from 'path' import process from 'process' + async function launch(version, setProgress, setDownload, setGameStarted, setStarted) { - const appdata = process.platform === 'win32' ? process.env.APPDATA : process.env.HOME + const appdata = process.platform === 'win32' ? process.env['APPDATA'] : process.env['HOME'] const launcher = new Client() let opts = { @@ -21,6 +22,8 @@ async function launch(version, setProgress, setDownload, setGameStarted, setStar } } + launcher.launch(opts) + launcher.on('progress', (e) => setProgress(e)) launcher.on('download', (e) => setDownload(e)) launcher.on('debug', (e) => console.log(e)) @@ -31,7 +34,6 @@ async function launch(version, setProgress, setDownload, setGameStarted, setStar setGameStarted(false) setStarted(false) }) - await launcher.launch(opts) } export { launch } diff --git a/src/renderer/src/pages/Main.jsx b/src/renderer/src/pages/Main.jsx index 6164416..6b3da17 100644 --- a/src/renderer/src/pages/Main.jsx +++ b/src/renderer/src/pages/Main.jsx @@ -55,7 +55,7 @@ function Main() { > {versions.map((version, index) => { return ( - ) @@ -71,21 +71,24 @@ function Main() { launch(version, setProgress, setDownload, setGameStarted, setStarted) setStarted(true) }} + disabled={started} /> {started && gameStarted && ( <> -
Minecraft launches...
+
Minecraft launches...
)} {started && !gameStarted && ( <> -
Downloading{'.'.repeat(progress.task % 3)}
-
+
Downloading{'.'.repeat(progress.task % 3)}
+
{download || 'please wait'} {`(${progress.type})` || ''}
-
{((progress.task / progress.total) * 100 || 0).toFixed(2)}%
+
+ {((progress.task / progress.total) * 100 || 0).toFixed(2)}% +
)}