Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bee 1.8 support and installer removal #264

Merged
merged 4 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ It also stores configuration files, Bee assets and other things in application's

As there are several independent components it bit depends on what you want to develop.

**Be aware!** The UIs (Installer and Dashboard) won't automatically open during development in order not to confuse on which
**Be aware!** The UI won't automatically open during development in order not to confuse on which
environment they are running. You have to open them manually.

#### Electron Desktop
Expand All @@ -86,21 +86,12 @@ To work on the Electron Desktop back-end you just need to do your work and then
Electron app and shows the Tray icon. No UI will be opened automatically. If you need to make more adjustment you have to exit
the process with `SIGINT (CTRL+C)` and relaunch.

#### Installer

To work on the Installer, run first `npm start` that will spin up the Electron Desktop back-end and also launches the `/installer` development
server. In order for the UI to be able to access the Desktop API it needs to have injected API token, which you can do by running `npm run open:installer`
that will open the Installer UI served by the development server with API key be passed in the URL. Changes to the Installer UI are automatically
hot-reloaded.

The UI served by the Desktop itself is updated only when you restart the `npm start`.

#### Dashboard
#### UI (Dashboard)

To work on the Dashboard, run first `npm start` that will spin up the Electron Desktop back-end. Then go to your locally cloned `bee-dashboard` repo and
in it start the development server with `npm start`. Similarly to Installer, the Dashboard also needs to have API key injected in order to use the
Desktop's API. You can inject it similarly by running `npm run desktop` in the Dashboard repo that will open the Dashboard UI with API key in the URL.
Changes to the Installer UI are automatically hot-reloaded.
in it start the development server with `npm start`. Dashboard also needs to have API key injected in order to use the
Desktop's API. You can inject it by running `npm run desktop` in the Dashboard repo that will open the Dashboard UI with API key in the URL.
Changes are automatically hot-reloaded.

The UI served by the Desktop itself is updated only when you update the `@ethersphere/bee-dashboard` NPM package in the Desktop repo.

Expand All @@ -109,7 +100,7 @@ The UI served by the Desktop itself is updated only when you update the `@ethers
There are several handy scripts:

- `npm run purge:data` that purge's the Desktop's data folder
- `npm run purge:logs` that purge's the Dekstop's logs folder
- `npm run purge:logs` that purge's the Desktop's logs folder

## Maintainers

Expand Down
20 changes: 17 additions & 3 deletions assets/splash.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
src: url("iAWriterQuattroS-Regular.woff");
}

* {
-webkit-touch-callout:none;
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
}

body {
margin: 0;
overflow: hidden;
Expand Down Expand Up @@ -40,9 +48,9 @@
}

.Initializing {
width: 112px;
width: 220px;
height: 23px;
margin: 124px 94px 0;
margin: 124px 0 0 90px;
font-family: iA-Writer, serif;
font-size: 18px;
font-weight: normal;
Expand All @@ -67,10 +75,16 @@
<div class='Rectangle'>
<div class='Hello'>Hello</div>
<img src='splash-logo.svg' class='logo'>
<div class='Initializing'>Initializing<span id='dots'>...</span></div>
<div class='Initializing'><span id='message'>Starting</span><span id='dots'>...</span></div>
</div>
</body>
<script>
const urlParams = new URLSearchParams(window.location.search)

if (urlParams.has('msg')) {
document.getElementById('message').innerText = decodeURI(urlParams.get('msg'))
}

const dotsElem = document.getElementById('dots')
setInterval(() => {
if (dotsElem.innerText.length >= 3) {
Expand Down
4 changes: 0 additions & 4 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ import { shell } from 'electron'
import { getApiKey } from './api-key'
import { port } from './port'

export function openInstallerInBrowser() {
shell.openExternal(`http://localhost:${port.value}/installer/?v=${getApiKey()}`)
}

export function openDashboardInBrowser() {
shell.openExternal(`http://localhost:${port.value}/dashboard/?v=${getApiKey()}`)
}
37 changes: 0 additions & 37 deletions src/config-yaml.ts

This file was deleted.

57 changes: 53 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,62 @@
export type EnvironmentVariables = Partial<{
// Logging
LOG_LEVEL: string
}>
import { existsSync, readFileSync, writeFileSync } from 'fs'
import { getPath } from './path'
import { dump, FAILSAFE_SCHEMA, load } from 'js-yaml'
import PACKAGE_JSON from '../package.json'

export const SUPPORTED_LEVELS = ['critical', 'error', 'warn', 'info', 'verbose', 'debug'] as const
export type SupportedLevels = typeof SUPPORTED_LEVELS[number]
export const DEFAULT_LOG_LEVEL = 'info'
const DESKTOP_VERSION_FILE = 'desktop.version'

export const logLevel =
process.env.LOG_LEVEL && SUPPORTED_LEVELS.includes(process.env.LOG_LEVEL as SupportedLevels)
? process.env.LOG_LEVEL
: DEFAULT_LOG_LEVEL

export function configYamlExists(): boolean {
return existsSync(getPath('config.yaml'))
}

export function readConfigYaml(): Record<string, unknown> {
const raw = readFileSync(getPath('config.yaml'), 'utf-8')
const data = load(raw, {
schema: FAILSAFE_SCHEMA,
})

return data as Record<string, unknown>
}

export function writeConfigYaml(newValues: Record<string, unknown>) {
const data = readConfigYaml()
for (const [key, value] of Object.entries(newValues)) {
data[key] = value
}
writeFileSync(getPath('config.yaml'), dump(data))
}

export function getDesktopVersionFromFile(): string | undefined {
try {
const desktopFile = readFileSync(getPath(DESKTOP_VERSION_FILE))

return desktopFile.toString('utf-8')
} catch (e) {
return
}
}

export function writeDesktopVersionFile() {
writeFileSync(getPath(DESKTOP_VERSION_FILE), PACKAGE_JSON.version)
}

export function readWalletPasswordOrThrow(): string {
if (!configYamlExists()) {
throw Error('Attempted to read password, but config.yaml is not found')
}
const config = readConfigYaml()

if (!config.password) {
throw Error('Attempted to read password, but config.yaml does not contain it')
}

return config.password as string
}
3 changes: 2 additions & 1 deletion src/downloader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export async function runDownloader(force = false): Promise<void> {
}
await ensureDir(paths.data)
await ensureAsset(
`https://github.com/ethersphere/bee/releases/download/v1.7.0/bee-${platformString}-${archString}${suffixString}`,
// TODO: Add final release before merge
`https://github.com/ethersphere/bee/releases/download/v1.8.0-rc4/bee-${platformString}-${archString}${suffixString}`,
`bee${suffixString}`,
{ chmod: process.platform !== 'win32', force },
)
Expand Down
21 changes: 1 addition & 20 deletions src/electron.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
import { app, Menu, Tray } from 'electron'
import { openDashboardInBrowser, openInstallerInBrowser } from './browser'
import { openDashboardInBrowser } from './browser'
import { runLauncher } from './launcher'
import { BeeManager } from './lifecycle'
import { createNotification } from './notify'
import { getAssetPath } from './path'
import { getStatus } from './status'

let tray: Tray

export function rebuildElectronTray() {
if (!tray) {
return
}

if (!getStatus().hasInitialTransaction) {
const contextMenu = Menu.buildFromTemplate([
{
label: 'Open Installer',
click: openInstallerInBrowser,
},
{
label: 'Quit',
click: async () => {
app.quit()
},
},
])
tray.setContextMenu(contextMenu)

return
}
const contextMenu = Menu.buildFromTemplate([
{
label: 'Open Web UI',
Expand Down
68 changes: 36 additions & 32 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import { readFileSync, writeFileSync } from 'fs-extra'
import * as Sentry from '@sentry/electron'
import { dialog, app } from 'electron'
import updater from 'update-electron-app'

import { openDashboardInBrowser, openInstallerInBrowser } from './browser'
import {
configYamlExists,
getDesktopVersionFromFile,
readConfigYaml,
writeConfigYaml,
writeDesktopVersionFile,
} from './config'
import { openDashboardInBrowser } from './browser'
import { runDownloader } from './downloader'
import { runElectronTray } from './electron'
import { runKeepAliveLoop, runLauncher } from './launcher'
import { initializeBee, runKeepAliveLoop, runLauncher } from './launcher'
import { findFreePort } from './port'
import { runServer } from './server'
import { getStatus } from './status'
import SENTRY from './.sentry.json'
import PACKAGE_JSON from '../package.json'
import { logger } from './logger'
import { getPath } from './path'
import { ensureApiKey } from './api-key'

// TODO: Add types definition
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import squirrelInstallingExecution from 'electron-squirrel-startup'
import { initSplash } from './splash'
import { configYamlExists, readConfigYaml, writeConfigYaml } from './config-yaml'
import { initSplash, Splash } from './splash'

// TODO: remove this after 1.0.0 release
// this is a migration path for pioneers
Expand All @@ -32,22 +36,21 @@ if (squirrelInstallingExecution) {
app.quit()
}

const DESKTOP_VERSION_FILE = 'desktop.version'

function getDesktopVersionFromFile(): string | undefined {
try {
const desktopFile = readFileSync(getPath(DESKTOP_VERSION_FILE))
function errorHandler(e: Error | string) {
if (splash) {
splash.hide()
}

return desktopFile.toString('utf-8')
} catch (e) {
return
if (typeof e !== 'string') {
e = e.message
}
}

function writeDesktopVersionFile() {
writeFileSync(getPath(DESKTOP_VERSION_FILE), PACKAGE_JSON.version)
logger.error(e)
dialog.showErrorBox('There was an error in Swarm Desktop', e)
}

let splash: Splash | undefined

async function main() {
logger.info(`Bee Desktop version: ${PACKAGE_JSON.version} (${process.env.NODE_ENV ?? 'production'})`)
const sentryKey = SENTRY.KEY || process.env.SENTRY_KEY
Expand Down Expand Up @@ -76,9 +79,9 @@ async function main() {
// },
})
}
const hideSplash = await initSplash()
splash = await initSplash()

// Auto updaterg
// Auto updater
// @ts-ignore: https://github.com/electron/update-electron-app/pull/96
updater({ logger: { log: (...args) => logger.info(...args) } })

Expand All @@ -91,28 +94,29 @@ async function main() {
)

if (force) {
await runDownloader(force)
splash.setMessage('Downloading Bee')
await runDownloader(true)
writeDesktopVersionFile()
}

ensureApiKey()
await findFreePort()
runServer()
runElectronTray()

if (getStatus().hasInitialTransaction) {
runLauncher()

if (process.env.NODE_ENV !== 'development') openDashboardInBrowser()
} else {
if (process.env.NODE_ENV !== 'development') openInstallerInBrowser()
if (!getStatus().config) {
logger.info('No Bee config found, initializing Bee')
splash.setMessage('Initializing Bee')
await initializeBee()
}

hideSplash()
runLauncher().catch(errorHandler)
runElectronTray()

if (process.env.NODE_ENV !== 'development') openDashboardInBrowser()
splash.hide()
splash = undefined

runKeepAliveLoop()
}

main().catch(e => {
logger.error(e)
dialog.showErrorBox('There was an error in Swarm Desktop', e.message)
})
main().catch(errorHandler)
Loading