1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Display number of resources being fetched in side bar

This commit is contained in:
Laurent Cozic 2018-11-13 22:25:23 +00:00
parent 06091933e1
commit e17f3051f0
6 changed files with 45 additions and 3 deletions

View File

@ -505,7 +505,13 @@ class SideBarComponent extends React.Component {
decryptionReportText = _('Decrypting items: %d/%d', this.props.decryptionWorker.itemIndex + 1, this.props.decryptionWorker.itemCount);
}
let resourceFetcherText = '';
if (this.props.resourceFetcher && this.props.resourceFetcher.toFetchCount) {
resourceFetcherText = _('Fetching resources: %d', this.props.resourceFetcher.toFetchCount);
}
let lines = Synchronizer.reportToLines(this.props.syncReport);
if (resourceFetcherText) lines.push(resourceFetcherText);
if (decryptionReportText) lines.push(decryptionReportText);
const syncReportText = [];
for (let i = 0; i < lines.length; i++) {
@ -547,6 +553,7 @@ const mapStateToProps = state => {
theme: state.settings.theme,
collapsedFolderIds: state.collapsedFolderIds,
decryptionWorker: state.decryptionWorker,
resourceFetcher: state.resourceFetcher,
};
};

View File

@ -389,6 +389,7 @@ class BaseApplication {
reg.dispatch = this.store().dispatch;
BaseSyncTarget.dispatch = this.store().dispatch;
DecryptionWorker.instance().dispatch = this.store().dispatch;
ResourceFetcher.instance().dispatch = this.store().dispatch;
}
async readFlagsFromFile(flagPath) {

View File

@ -37,6 +37,11 @@ class Resource extends BaseItem {
return this.modelSelectAll(sql, [Resource.FETCH_STATUS_IDLE]);
}
static async needToBeFetchedCount() {
const r = await this.db().selectOne('SELECT count(*) as total FROM resource_local_states WHERE fetch_status = ?', [Resource.FETCH_STATUS_IDLE]);
return r ? r['total'] : 0;
}
static fsDriver() {
if (!Resource.fsDriver_) Resource.fsDriver_ = new FsDriverDummy();
return Resource.fsDriver_;

View File

@ -38,7 +38,10 @@ const defaultState = {
itemIndex: 0,
itemCount: 0,
},
selectedNoteTags: []
selectedNoteTags: [],
resourceFetcher: {
toFetchCount: 0,
},
};
const stateUtils = {};
@ -604,6 +607,14 @@ const reducer = (state = defaultState, action) => {
newState.decryptionWorker = decryptionWorker;
break;
case 'RESOURCE_FETCHER_SET':
newState = Object.assign({}, state);
const rf = Object.assign({}, action);
delete rf.type;
newState.resourceFetcher = rf;
break;
case 'LOAD_CUSTOM_CSS':
newState = Object.assign({}, state);

View File

@ -10,6 +10,8 @@ class ResourceFetcher extends BaseService {
constructor(fileApi = null) {
super();
this.dispatch = (action) => {};
this.setFileApi(fileApi);
this.logger_ = new Logger();
this.queue_ = [];
@ -59,6 +61,19 @@ class ResourceFetcher extends BaseService {
return -1;
}
updateReport() {
if (this.updateReportIID_) return;
this.updateReportIID_ = setTimeout(async () => {
const toFetchCount = await Resource.needToBeFetchedCount();
this.dispatch({
type: 'RESOURCE_FETCHER_SET',
toFetchCount: toFetchCount,
});
this.updateReportIID_ = null;
}, 2000);
}
queueDownload(resourceId, priority = null) {
if (priority === null) priority = 'normal';
@ -73,6 +88,8 @@ class ResourceFetcher extends BaseService {
this.queue_.push(item);
}
this.updateReport();
this.scheduleQueueProcess();
return true;
}
@ -85,6 +102,7 @@ class ResourceFetcher extends BaseService {
delete this.fetchingItems_[resource.id];
this.scheduleQueueProcess();
if (emitDownloadComplete) this.eventEmitter_.emit('downloadComplete', { id: resource.id });
this.updateReport();
}
const resource = await Resource.load(resourceId);

View File

@ -74,7 +74,7 @@ class Synchronizer {
if (report.deleteLocal) lines.push(_("Deleted local items: %d.", report.deleteLocal));
if (report.deleteRemote) lines.push(_("Deleted remote items: %d.", report.deleteRemote));
if (report.fetchingTotal && report.fetchingProcessed) lines.push(_("Fetched items: %d/%d.", report.fetchingProcessed, report.fetchingTotal));
if (!report.completedTime && report.state) lines.push(_('State: %s.', Synchronizer.stateToLabel(report.state)));
// if (!report.completedTime && report.state) lines.push(_('State: %s.', Synchronizer.stateToLabel(report.state)));
if (report.cancelling && !report.completedTime) lines.push(_("Cancelling..."));
if (report.completedTime) lines.push(_("Completed: %s", time.formatMsToLocal(report.completedTime)));
if (report.errors && report.errors.length) lines.push(_("Last error: %s", report.errors[report.errors.length - 1].toString().substr(0, 500)));