Skip to content

Commit

Permalink
Show errors about node status
Browse files Browse the repository at this point in the history
  • Loading branch information
spylogsster committed Mar 10, 2021
1 parent ff71a1e commit d3c1273
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 16 deletions.
30 changes: 24 additions & 6 deletions browser/ui/webui/ipfs_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
#include "brave/components/ipfs/repo_stats.h"
#include "brave/components/ipfs_ui/resources/grit/ipfs_generated_map.h"
#include "components/grit/brave_components_resources.h"
#include "components/grit/brave_components_strings.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "ui/base/l10n/l10n_util.h"

namespace {

void CallOnGetDaemonStatus(content::WebUI* web_ui) {
void CallOnGetDaemonStatus(content::WebUI* web_ui, const std::string& error) {
ipfs::IpfsService* service = ipfs::IpfsServiceFactory::GetForContext(
web_ui->GetWebContents()->GetBrowserContext());
if (!service) {
Expand All @@ -30,6 +32,7 @@ void CallOnGetDaemonStatus(content::WebUI* web_ui) {
base::Value value(base::Value::Type::DICTIONARY);
value.SetBoolKey("installed", service->IsIPFSExecutableAvailable());
value.SetBoolKey("launched", service->IsDaemonLaunched());
value.SetStringKey("error", error);
web_ui->CallJavascriptFunctionUnsafe("ipfs.onGetDaemonStatus",
std::move(value));
}
Expand Down Expand Up @@ -156,7 +159,7 @@ void IPFSDOMHandler::HandleGetDaemonStatus(const base::ListValue* args) {
if (!web_ui()->CanCallJavascript())
return;

CallOnGetDaemonStatus(web_ui());
CallOnGetDaemonStatus(web_ui(), std::string());
}

void IPFSDOMHandler::HandleLaunchDaemon(const base::ListValue* args) {
Expand All @@ -172,18 +175,33 @@ void IPFSDOMHandler::LaunchDaemon() {
if (!service) {
return;
}

service->LaunchDaemon(base::NullCallback());
}

void IPFSDOMHandler::OnIpfsLaunched(bool success, int64_t pid) {
if (!web_ui()->CanCallJavascript() || !success)
if (!web_ui()->CanCallJavascript())
return;
CallOnGetDaemonStatus(web_ui());
std::string error;
if (!success) {
error = l10n_util::GetStringUTF8(IDS_IPFS_NODE_LAUNCH_ERROR);
}

CallOnGetDaemonStatus(web_ui(), error);
}

void IPFSDOMHandler::OnInstallationEvent(ipfs::ComponentUpdaterEvents event) {
if (event == ipfs::ComponentUpdaterEvents::COMPONENT_UPDATE_ERROR) {
base::Value value(base::Value::Type::DICTIONARY);
value.SetBoolKey("installed", false);
value.SetStringKey(
"error", l10n_util::GetStringUTF8(IDS_IPFS_NODE_INSTALLATION_ERROR));
web_ui()->CallJavascriptFunctionUnsafe("ipfs.onGetDaemonStatus",
std::move(value));
}
}

void IPFSDOMHandler::OnIpfsShutdown() {
CallOnGetDaemonStatus(web_ui());
CallOnGetDaemonStatus(web_ui(), std::string());
}

void IPFSDOMHandler::HandleShutdownDaemon(const base::ListValue* args) {
Expand Down
1 change: 1 addition & 0 deletions browser/ui/webui/ipfs_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class IPFSDOMHandler : public content::WebUIMessageHandler,
void OnIpfsShutdown() override;
void OnGetConnectedPeers(bool success,
const std::vector<std::string>& peers) override;
void OnInstallationEvent(ipfs::ComponentUpdaterEvents event) override;

private:
void HandleGetConnectedPeers(const base::ListValue* args);
Expand Down
1 change: 1 addition & 0 deletions components/definitions/ipfs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ declare namespace IPFS {
launched: bool
restarting: bool
installing: bool
error: string
}

export interface GarbageCollectionStatus {
Expand Down
13 changes: 10 additions & 3 deletions components/ipfs_ui/components/daemonStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as React from 'react'

import { getLocale } from '../../common/locale'

import { PaddedButton, Section, SideBySideButtons, Title } from '../style'
import { PaddedButton, Section, SideBySideButtons, Title, Error } from '../style'

interface Props {
daemonStatus: IPFS.DaemonStatus
Expand All @@ -29,9 +29,16 @@ export class DaemonStatus extends React.Component<Props, {}> {
<Title>
{getLocale('daemonStatusTitle')}
</Title>
{!this.props.daemonStatus.error.length && (
<div>
{this.props.daemonStatus.launched ? getLocale('launched') : getLocale('notLaunched')}
</div>
{(this.props.daemonStatus.launched && !this.props.daemonStatus.error) ? getLocale('launched') : getLocale('notLaunched')}
</div>)}
{this.props.daemonStatus.error.length > 0 && (
<div
style={Error}
>
{this.props.daemonStatus.error}
</div>)}
<SideBySideButtons>
{(!this.props.daemonStatus.launched && !this.props.daemonStatus.restarting) && (<PaddedButton
text={getLocale('launch')}
Expand Down
4 changes: 2 additions & 2 deletions components/ipfs_ui/components/repoStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as React from 'react'

import { getLocale } from '../../common/locale'

import { Section, Title, PaddedButton, GarbageError } from '../style'
import { Section, Title, PaddedButton, Error } from '../style'

interface Props {
repoStats: IPFS.RepoStats
Expand Down Expand Up @@ -50,7 +50,7 @@ export class RepoStats extends React.Component<Props, {}> {
/>
{!this.props.garbageCollectionStatus.success && this.props.daemonStatus.launched && (
<div
style={GarbageError}
style={Error}
>
{getLocale('gcError')}: {this.props.garbageCollectionStatus.error}
</div>)}
Expand Down
8 changes: 7 additions & 1 deletion components/ipfs_ui/components/uninstalledView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as React from 'react'

import { getLocale } from '../../common/locale'

import { PaddedButton, Section, Title } from '../style'
import { PaddedButton, Section, Title, Error } from '../style'

interface Props {
daemonStatus: IPFS.DaemonStatus
Expand All @@ -28,6 +28,12 @@ export class UninstalledView extends React.Component<Props, {}> {
<div>
{this.props.daemonStatus.installing ? getLocale('installing') : getLocale('notInstalled')}
</div>
{this.props.daemonStatus.error.length > 0 && (
<div
style={Error}
>
{this.props.daemonStatus.error}
</div>)}
{!this.props.daemonStatus.installed && (
<PaddedButton
text={getLocale('installAndLaunch')}
Expand Down
6 changes: 4 additions & 2 deletions components/ipfs_ui/reducers/ipfs_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ const ipfsReducer: Reducer<IPFS.State | undefined> = (state: IPFS.State | undefi
installed: false,
launched: false,
restarting: false,
installing: true
installing: true,
error: ''
}
}
break
Expand Down Expand Up @@ -133,7 +134,8 @@ const ipfsReducer: Reducer<IPFS.State | undefined> = (state: IPFS.State | undefi
installed: true,
launched: false,
restarting: true,
installing: false
installing: false,
error: ''
}
}
break
Expand Down
3 changes: 2 additions & 1 deletion components/ipfs_ui/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export const defaultState: IPFS.State = {
installed: false,
launched: false,
restarting: false,
installing: false
installing: false,
error: ''
},
garbageCollectionStatus: {
success: true,
Expand Down
2 changes: 1 addition & 1 deletion components/ipfs_ui/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ export const LearnMoreLink = {
cursor: 'pointer'
}

export const GarbageError = {
export const Error = {
color: 'red'
}
2 changes: 2 additions & 0 deletions components/resources/ipfs_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<message name="IDS_IPFS_ADDRESSES_CONFIG_TITLE" desc="Title of addresses config section">Addresses</message>
<message name="IDS_IPFS_REPO_STATS_TITLE" desc="Title of repo stats section">Repo Stats</message>
<message name="IDS_IPFS_NODE_INFO_TITLE" desc="Title of node info section">Node info</message>
<message name="IDS_IPFS_NODE_LAUNCH_ERROR" desc="Text of node launch error">An error occurred, please try to launch again</message>
<message name="IDS_IPFS_NODE_INSTALLATION_ERROR" desc="Text of node installation error">An error occurred, please try to install the node again</message>
<message name="IDS_IPFS_DAEMON_STATUS_TITLE" desc="Title of daemon status section">IPFS node status</message>
<message name="IDS_IPFS_API" desc="Title of the API config">API</message>
<message name="IDS_IPFS_GATEWAY" desc="Title of the gateway config">Gateway</message>
Expand Down

0 comments on commit d3c1273

Please sign in to comment.