2017-01-29 12:54:06 +13:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
import React from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { bindActionCreators } from 'redux';
|
2020-03-05 21:32:54 +13:00
|
|
|
import { get as getStorage } from '../util/storage';
|
2020-03-03 16:39:37 +13:00
|
|
|
import { isTouchDevice } from '../util/helpers';
|
2019-09-05 15:36:11 +12:00
|
|
|
import * as uiActions from '../services/ui/actions';
|
2020-03-13 16:41:44 +13:00
|
|
|
import { indexToArray } from '../util/arrays';
|
2020-09-07 21:04:28 +12:00
|
|
|
import localForage from 'localforage';
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2019-09-10 06:59:44 +12:00
|
|
|
class DebugInfo extends React.Component {
|
2020-09-07 21:04:28 +12:00
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = { localForageLength: 0 }
|
|
|
|
|
}
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
localForage.length().then((localForageLength) => this.setState({ localForageLength }))
|
|
|
|
|
}
|
2019-09-05 15:36:11 +12:00
|
|
|
localStorageSize() {
|
|
|
|
|
let data = '';
|
|
|
|
|
|
|
|
|
|
for (const key in window.localStorage) {
|
|
|
|
|
if (window.localStorage.hasOwnProperty(key)) {
|
|
|
|
|
data += window.localStorage[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let used = 0;
|
|
|
|
|
const total = 5000;
|
|
|
|
|
if (data !== '') {
|
|
|
|
|
used = ((data.length * 16) / (8 * 1024)).toFixed(2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
used,
|
|
|
|
|
percent: (used / total * 100).toFixed(2),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-13 20:59:46 +12:00
|
|
|
renderload_queue() {
|
2020-03-05 21:32:54 +13:00
|
|
|
const { ui: { load_queue } } = this.props;
|
|
|
|
|
if (!load_queue) return <div className="debug-info-item mid_grey-text">Nothing loading</div>;
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-08-11 21:05:36 +12:00
|
|
|
const queue = indexToArray(load_queue, null, true);
|
2019-09-05 15:36:11 +12:00
|
|
|
|
|
|
|
|
if (queue.length > 0) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="debug-info-item">
|
2020-08-11 21:05:36 +12:00
|
|
|
{queue.map((item, index) => (<div key={`${item}_${index}`}>{item}</div>))}
|
2019-09-05 15:36:11 +12:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-09-10 06:59:44 +12:00
|
|
|
return <div className="debug-info-item mid_grey-text">Nothing loading</div>;
|
2019-09-05 15:36:11 +12:00
|
|
|
}
|
|
|
|
|
|
2020-09-07 21:04:28 +12:00
|
|
|
render = () => {
|
2019-09-05 15:36:11 +12:00
|
|
|
const localStorageUsage = this.localStorageSize();
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="debug-info">
|
|
|
|
|
|
|
|
|
|
<div className="debug-info-section">
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Version:
|
|
|
|
|
{' '}
|
2019-09-05 15:36:11 +12:00
|
|
|
{version}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Build:
|
|
|
|
|
{' '}
|
2019-09-05 15:36:11 +12:00
|
|
|
{build}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="debug-info-section">
|
2020-09-07 21:04:28 +12:00
|
|
|
<h5>State</h5>
|
|
|
|
|
<div className="debug-info-item">
|
|
|
|
|
Items:
|
|
|
|
|
{' '}
|
|
|
|
|
{this.props.core.items ? Object.keys(this.props.core.items).length : '0'}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="debug-info-item">
|
|
|
|
|
Coldstore items:
|
|
|
|
|
{' '}
|
|
|
|
|
{this.state.localForageLength}
|
|
|
|
|
</div>
|
2019-09-05 15:36:11 +12:00
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Albums:
|
|
|
|
|
{' '}
|
2019-09-05 15:36:11 +12:00
|
|
|
{this.props.core.albums ? Object.keys(this.props.core.albums).length : '0'}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Artists:
|
|
|
|
|
{' '}
|
2019-09-05 15:36:11 +12:00
|
|
|
{this.props.core.artists ? Object.keys(this.props.core.artists).length : '0'}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Playlists:
|
|
|
|
|
{' '}
|
2019-09-05 15:36:11 +12:00
|
|
|
{this.props.core.playlists ? Object.keys(this.props.core.playlists).length : '0'}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Tracks:
|
|
|
|
|
{' '}
|
2019-09-05 15:36:11 +12:00
|
|
|
{this.props.core.tracks ? Object.keys(this.props.core.tracks).length : '0'}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Users:
|
|
|
|
|
{' '}
|
2019-09-05 15:36:11 +12:00
|
|
|
{this.props.core.users ? Object.keys(this.props.core.users).length : '0'}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Notifications:
|
|
|
|
|
{' '}
|
2019-09-05 15:36:11 +12:00
|
|
|
{this.props.ui.notifications ? Object.keys(this.props.ui.notifications).length : '0'}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Processes:
|
|
|
|
|
{' '}
|
2019-09-05 15:36:11 +12:00
|
|
|
{this.props.ui.processes ? Object.keys(this.props.ui.processes).length : '0'}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Enqueue batches:
|
|
|
|
|
{' '}
|
2019-09-05 15:36:11 +12:00
|
|
|
{this.props.mopidy.enqueue_uris_batches ? this.props.mopidy.enqueue_uris_batches.length : '0'}
|
|
|
|
|
</div>
|
2019-09-10 06:59:44 +12:00
|
|
|
<div className="debug-info-item">
|
|
|
|
|
Cached URLs:
|
|
|
|
|
{' '}
|
2020-03-05 21:32:54 +13:00
|
|
|
{Object.keys(getStorage('cache')).length}
|
2019-09-10 06:59:44 +12:00
|
|
|
</div>
|
2019-09-05 15:36:11 +12:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className="debug-info-section">
|
|
|
|
|
<h5>Config</h5>
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Slim mode:
|
|
|
|
|
{' '}
|
2019-09-05 15:36:11 +12:00
|
|
|
{this.props.ui.slim_mode ? 'on' : 'off'}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Test mode:
|
|
|
|
|
{' '}
|
2019-09-05 15:36:11 +12:00
|
|
|
{this.props.ui.test_mode ? 'on' : 'off'}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Touch:
|
|
|
|
|
{' '}
|
2020-03-03 16:39:37 +13:00
|
|
|
{isTouchDevice() ? 'on' : 'off'}
|
2019-09-05 15:36:11 +12:00
|
|
|
</div>
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
LocalStorage usage:
|
|
|
|
|
{' '}
|
|
|
|
|
{localStorageUsage.used}
|
|
|
|
|
kb (~
|
|
|
|
|
{localStorageUsage.percent}
|
2019-09-05 15:36:11 +12:00
|
|
|
%)
|
|
|
|
|
</div>
|
|
|
|
|
<div className="debug-info-item">
|
2019-09-10 06:59:44 +12:00
|
|
|
Selected tracks:
|
|
|
|
|
{' '}
|
|
|
|
|
{this.props.ui.selected_tracks.length}
|
2019-09-05 15:36:11 +12:00
|
|
|
<br />
|
|
|
|
|
{
|
|
|
|
|
this.props.ui.selected_tracks.map((track_key, index) => (
|
|
|
|
|
<div key={`${track_key}_${index}`}>{track_key}</div>
|
|
|
|
|
))
|
2018-08-02 16:24:12 +12:00
|
|
|
}
|
2019-09-05 15:36:11 +12:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2018-08-02 16:24:12 +12:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
<div className="debug-info-section">
|
|
|
|
|
<h5>Load queue</h5>
|
2020-09-13 20:59:46 +12:00
|
|
|
{this.renderload_queue()}
|
2019-09-05 15:36:11 +12:00
|
|
|
</div>
|
2018-08-02 16:24:12 +12:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-01-29 12:54:06 +13:00
|
|
|
}
|
|
|
|
|
|
2020-09-07 21:04:28 +12:00
|
|
|
const mapStateToProps = (state) => ({
|
2019-09-05 15:36:11 +12:00
|
|
|
core: state.core,
|
|
|
|
|
ui: state.ui,
|
|
|
|
|
mopidy: state.mopidy,
|
|
|
|
|
});
|
2017-01-29 12:54:06 +13:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
|
|
|
|
});
|
2017-01-29 12:54:06 +13:00
|
|
|
|
2019-09-10 06:59:44 +12:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(DebugInfo);
|