-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: wireup node installation flow [#30]
- Loading branch information
Showing
17 changed files
with
220 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import os from 'os' | ||
import path from 'path' | ||
|
||
export const USER_DIR = path.join(os.homedir(), '.blast') | ||
export const NODE_INSTALL_PATH = path.join(USER_DIR, 'node') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>Blast Node Installer</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useCallback, useState } from "react"; | ||
|
||
export default function App() { | ||
const [error, setError] = useState<string | null>(null); | ||
const [isInstalling, setIsInstalling] = useState(false); | ||
|
||
const onInstall = useCallback(() => { | ||
if (isInstalling) { | ||
return; | ||
} | ||
|
||
setError(null); | ||
setIsInstalling(true); | ||
|
||
window.electron | ||
.startNodeInstallation() | ||
.then((success) => { | ||
if (!success) { | ||
setError("Installation failed"); | ||
} | ||
|
||
window.electron.exitAndStart(); | ||
}) | ||
.catch((error) => { | ||
setError(error.message); | ||
}) | ||
.finally(() => { | ||
setIsInstalling(false); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<div className="flex justify-center items-center text-white h-full flex-col gap-2"> | ||
{!isInstalling && ( | ||
<> | ||
<p>You have to install the nodejs runtime to use this app. Click the button below to proceed.</p> | ||
|
||
<button className="py-2 px-4 font-bold text-white bg-blue-500 rounded hover:bg-blue-700" onClick={onInstall}> | ||
Install NodeJS | ||
</button> | ||
</> | ||
)} | ||
|
||
{isInstalling && <p>Installing...</p>} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ipcMain } from "electron"; | ||
|
||
import { setMenu } from "../menu"; | ||
import { installNode, nrm, hasVersionInstalled } from "../nrm"; | ||
import { startRuntime } from "../runtime"; | ||
import { closeNodeInstallerWindow, createApplicationWindow } from "../window"; | ||
|
||
import { EventTypes } from "./types"; | ||
|
||
export function registerIPCMainEvents() { | ||
ipcMain.handle(EventTypes.INSTALL_NODE, async () => { | ||
if (hasVersionInstalled()) { | ||
return true; | ||
} | ||
|
||
await installNode(); | ||
|
||
try { | ||
nrm.nodePath; | ||
} catch (error) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
|
||
ipcMain.handle(EventTypes.EXIT_AND_START, async () => { | ||
closeNodeInstallerWindow(); | ||
await startRuntime(); | ||
setMenu(); | ||
createApplicationWindow(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
interface Window { | ||
electron: { | ||
startNodeInstallation: () => Promise<boolean>; | ||
exitAndStart: () => Promise<void>; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { contextBridge, ipcRenderer } from 'electron' | ||
|
||
import { EventTypes } from './types' | ||
|
||
contextBridge.exposeInMainWorld('electron', { | ||
startNodeInstallation: () => ipcRenderer.invoke(EventTypes.INSTALL_NODE), | ||
exitAndStart: () => ipcRenderer.invoke(EventTypes.EXIT_AND_START) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react"; | ||
import { createRoot } from "react-dom/client"; | ||
import './styles.scss' | ||
|
||
import App from "./App"; | ||
|
||
function start() { | ||
const container = document.getElementById("app"); | ||
if (!container) { | ||
return; | ||
} | ||
|
||
const root = createRoot(container); | ||
|
||
root.render(React.createElement(App)); | ||
} | ||
|
||
start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@tailwind base; | ||
@tailwind components; | ||
@tailwind utilities; | ||
|
||
html, | ||
body, | ||
#app { | ||
height: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const enum EventTypes { | ||
INSTALL_NODE = 'INSTALL_NODE', | ||
EXIT_AND_START = 'EXIT_AND_START', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { NRM } from '@blastlauncher/utils' | ||
|
||
import { NODE_INSTALL_PATH } from './constants' | ||
|
||
const NODE_VERSION = "v18.17.1" | ||
|
||
export const nrm = new NRM({ | ||
installPath: NODE_INSTALL_PATH, | ||
}) | ||
|
||
export function hasVersionInstalled () { | ||
return nrm.hasVersion(NODE_VERSION) | ||
} | ||
|
||
export function installNode () { | ||
return nrm.download(NODE_VERSION) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.