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

Add installation progress to brave://ipfs page #8219

Merged
merged 1 commit into from
Mar 12, 2021
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
18 changes: 17 additions & 1 deletion browser/ui/webui/ipfs_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
#include "brave/components/ipfs/ipfs_service.h"
#include "brave/components/ipfs/repo_stats.h"
#include "brave/components/ipfs_ui/resources/grit/ipfs_generated_map.h"
#include "chrome/browser/browser_process_impl.h"
#include "components/grit/brave_components_resources.h"
#include "components/grit/brave_components_strings.h"
#include "components/update_client/crx_update_item.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
Expand Down Expand Up @@ -190,7 +192,21 @@ void IPFSDOMHandler::OnIpfsLaunched(bool success, int64_t pid) {
}

void IPFSDOMHandler::OnInstallationEvent(ipfs::ComponentUpdaterEvents event) {
if (event == ipfs::ComponentUpdaterEvents::COMPONENT_UPDATE_ERROR) {
if (event == ipfs::ComponentUpdaterEvents::COMPONENT_UPDATE_DOWNLOADING) {
if (!g_browser_process->component_updater())
return;
auto* updater = g_browser_process->component_updater();
update_client::CrxUpdateItem item;
if (updater->GetComponentDetails(ipfs::kIpfsClientComponentId, &item)) {
if (item.downloaded_bytes > 0 && item.total_bytes > 0) {
base::Value value(base::Value::Type::DICTIONARY);
value.SetDoubleKey("total_bytes", item.total_bytes);
value.SetDoubleKey("downloaded_bytes", item.downloaded_bytes);
web_ui()->CallJavascriptFunctionUnsafe("ipfs.onInstallationProgress",
std::move(value));
}
}
} else if (event == ipfs::ComponentUpdaterEvents::COMPONENT_UPDATE_ERROR) {
base::Value value(base::Value::Type::DICTIONARY);
value.SetBoolKey("installed", false);
value.SetStringKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_
#define BRAVE_CHROMIUM_SRC_COMPONENTS_COMPONENT_UPDATER_COMPONENT_UPDATER_SERVICE_H_

#define BRAVE_COMPONENT_UPDATER_SERVICE_H_ \
private: \
friend void BraveOnDemandUpdate(const std::string&); \
\
class IPFSDOMHandler;

#define BRAVE_COMPONENT_UPDATER_SERVICE_H_ friend class ::IPFSDOMHandler;
#define BRAVE_COMPONENT_UPDATER_SERVICE_H_ON_DEMAND_UPDATER \
private: \
friend void BraveOnDemandUpdate(const std::string&); \
\
public:
#include "../../../../components/component_updater/component_updater_service.h"

Expand Down
6 changes: 6 additions & 0 deletions components/definitions/ipfs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ declare namespace IPFS {
repoStats: RepoStats,
nodeInfo: NodeInfo,
garbageCollectionStatus: GarbageCollectionStatus,
installationProgress: InstallationProgress
}

export interface AddressesConfig {
Expand Down Expand Up @@ -47,4 +48,9 @@ declare namespace IPFS {
version: string
}

export interface InstallationProgress {
total_bytes: number
downloaded_bytes: number
}

}
4 changes: 3 additions & 1 deletion components/ipfs/brave_ipfs_client_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ base::FilePath BraveIpfsClientUpdater::GetExecutablePath() const {
void BraveIpfsClientUpdater::OnEvent(Events event, const std::string& id) {
if (id != kIpfsClientComponentId)
return;

if (event == Events::COMPONENT_UPDATE_ERROR) {
registered_ = false;
}
for (Observer& observer : observers_)
observer.OnInstallationEvent(event);
}
Expand Down
5 changes: 5 additions & 0 deletions components/ipfs_ui/actions/ipfs_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export const onGetDaemonStatus = (daemonStatus: IPFS.DaemonStatus) =>
daemonStatus
})

export const onInstallationProgress = (installationProgress: IPFS.InstallationProgress) =>
action(types.IPFS_ON_INSTALLATION_PROGRESS, {
installationProgress
})

export const getRepoStats = () => action(types.IPFS_GET_REPO_STATS)

export const onGetRepoStats = (repoStats: IPFS.RepoStats) =>
Expand Down
2 changes: 1 addition & 1 deletion components/ipfs_ui/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class IPFSPage extends React.Component<Props, {}> {
return (
<div id='ipfsPage'>
{!this.props.ipfsData.daemonStatus.installed && (
<UninstalledView daemonStatus={this.props.ipfsData.daemonStatus} onInstall={this.installDaemon}/>
<UninstalledView daemonStatus={this.props.ipfsData.daemonStatus} installationProgress={this.props.ipfsData.installationProgress} onInstall={this.installDaemon}/>
)}
{this.props.ipfsData.daemonStatus.installed && (
<DaemonStatus daemonStatus={this.props.ipfsData.daemonStatus} addressesConfig={this.props.ipfsData.addressesConfig} onLaunch={this.launchDaemon} onShutdown={this.shutdownDaemon} onRestart={this.restartDaemon} onOpenNodeWebUI={this.openNodeWebUI} />
Expand Down
21 changes: 20 additions & 1 deletion components/ipfs_ui/components/uninstalledView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,31 @@ import { PaddedButton, Section, Title, Error } from '../style'

interface Props {
daemonStatus: IPFS.DaemonStatus
installationProgress: IPFS.InstallationProgress
onInstall: () => void
}

export class UninstalledView extends React.Component<Props, {}> {
constructor (props: Props) {
super(props)
}

progress () {
if (!this.props.daemonStatus.installing ||
this.props.installationProgress.downloaded_bytes === -1 ||
this.props.installationProgress.total_bytes === -1) {
return ''
}
const bytes = this.props.installationProgress.downloaded_bytes
const total = this.props.installationProgress.total_bytes
if (!total)
return ''
const percentages = 100 * bytes / total
spylogsster marked this conversation as resolved.
Show resolved Hide resolved
return <span>{percentages.toFixed(2)}% </span>
}
disableInstallButton () {
return this.props.daemonStatus.installing &&
!this.props.daemonStatus.error.length
}
render () {
return (
<Section>
Expand All @@ -27,6 +44,7 @@ export class UninstalledView extends React.Component<Props, {}> {
</Title>
<div>
{this.props.daemonStatus.installing ? getLocale('installing') : getLocale('notInstalled')}
{this.progress()}
</div>
{this.props.daemonStatus.error.length > 0 && (
<div
Expand All @@ -38,6 +56,7 @@ export class UninstalledView extends React.Component<Props, {}> {
<PaddedButton
text={getLocale('installAndLaunch')}
size={'small'}
disabled={this.disableInstallButton()}
onClick={this.props.onInstall}
/>
)}
Expand Down
3 changes: 2 additions & 1 deletion components/ipfs_ui/constants/ipfs_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ export const enum types {
IPFS_OPEN_NODE_WEBUI = '@@ipfs/IPFS_OPEN_NODE_WEBUI',
IPFS_OPEN_PEERS_WEBUI = '@@ipfs/IPFS_OPEN_PEERS_WEBUI',
IPFS_GARBAGE_COLLECTION = '@@ipfs/IPFS_GARBAGE_COLLECTION',
IPFS_ON_GARBAGE_COLLECTION = '@@ipfs/IPFS_ON_GARBAGE_COLLECTION'
IPFS_ON_GARBAGE_COLLECTION = '@@ipfs/IPFS_ON_GARBAGE_COLLECTION',
IPFS_ON_INSTALLATION_PROGRESS = '@@ipfs/IPFS_ON_INSTALLATION_PROGRESS'
}
8 changes: 7 additions & 1 deletion components/ipfs_ui/ipfs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ window.cr.define('ipfs', function () {
actions.onGetAddressesConfig(addressesConfig)
}

function onInstallationProgress (installationProgress: IPFS.InstallationProgress) {
const actions = bindActionCreators(ipfsActions, store.dispatch.bind(store))
actions.onInstallationProgress(installationProgress)
}

function onGetDaemonStatus (daemonStatus: IPFS.DaemonStatus) {
const actions = bindActionCreators(ipfsActions, store.dispatch.bind(store))
actions.onGetDaemonStatus(daemonStatus)
Expand Down Expand Up @@ -100,7 +105,8 @@ window.cr.define('ipfs', function () {
onGetDaemonStatus,
onGetRepoStats,
onGetNodeInfo,
onGarbageCollection
onGarbageCollection,
onInstallationProgress
}
})

Expand Down
6 changes: 6 additions & 0 deletions components/ipfs_ui/reducers/ipfs_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ const ipfsReducer: Reducer<IPFS.State | undefined> = (state: IPFS.State | undefi
garbageCollectionStatus: action.payload.garbageCollectionStatus
}
break
case types.IPFS_ON_INSTALLATION_PROGRESS:
state = {
...state,
installationProgress: action.payload.installationProgress
}
break
case types.IPFS_RESTART_DAEMON:
chrome.send('ipfs.restartDaemon')
state = {
Expand Down
4 changes: 4 additions & 0 deletions components/ipfs_ui/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export const defaultState: IPFS.State = {
nodeInfo: {
id: '',
version: ''
},
installationProgress: {
total_bytes: -1,
downloaded_bytes: -1
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
diff --git a/components/component_updater/component_updater_service.h b/components/component_updater/component_updater_service.h
index 9de20a64577ba39d467207ef28058a03bc7fb218..6131fd7f0810c4082b735b04d8add24baf4f4619 100644
index 9de20a64577ba39d467207ef28058a03bc7fb218..53004cd57b593c5dc64081b8b446c397574aa3d7 100644
--- a/components/component_updater/component_updater_service.h
+++ b/components/component_updater/component_updater_service.h
@@ -163,6 +163,7 @@ class OnDemandUpdater {
@@ -150,6 +150,7 @@ class ComponentUpdateService {

friend class speech::SodaInstallerImpl;
friend class ::ComponentsHandler;
+ BRAVE_COMPONENT_UPDATER_SERVICE_H_
Copy link
Contributor Author

@spylogsster spylogsster Mar 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkarolin could you please check my changes to patches, I renamed old macros to meet the class name because I need to create another one

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spylogsster this one is fine, the other one I would probably go with BRAVE_COMPONENT_UPDATER_SERVICE_H_ON_DEMAND_UPDATER, or just BRAVE_ON_DEMAND_UPDATER, otherwise it looks like it's in a wrong file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

FRIEND_TEST_ALL_PREFIXES(ComponentInstallerTest, RegisterComponent);
};

@@ -163,6 +164,7 @@ class OnDemandUpdater {
enum class Priority { BACKGROUND = 0, FOREGROUND = 1 };

virtual ~OnDemandUpdater() = default;
+ BRAVE_COMPONENT_UPDATER_SERVICE_H_
+ BRAVE_COMPONENT_UPDATER_SERVICE_H_ON_DEMAND_UPDATER

private:
friend class OnDemandTester;