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

Mobile: Add startup screen to show progress of db migration

This commit is contained in:
Laurent Cozic 2020-09-04 17:07:57 +01:00
parent 2530ecfc86
commit 569355a318
8 changed files with 89 additions and 33 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -3,6 +3,7 @@ const { Database } = require('lib/database.js');
const { sprintf } = require('sprintf-js'); const { sprintf } = require('sprintf-js');
const Resource = require('lib/models/Resource'); const Resource = require('lib/models/Resource');
const { shim } = require('lib/shim.js'); const { shim } = require('lib/shim.js');
const EventEmitter = require('events');
const structureSql = ` const structureSql = `
CREATE TABLE folders ( CREATE TABLE folders (
@ -125,6 +126,11 @@ class JoplinDatabase extends Database {
this.tableFields_ = null; this.tableFields_ = null;
this.version_ = null; this.version_ = null;
this.tableFieldNames_ = {}; this.tableFieldNames_ = {};
this.eventEmitter_ = new EventEmitter();
}
eventEmitter() {
return this.eventEmitter_;
} }
initialized() { initialized() {
@ -350,6 +356,8 @@ class JoplinDatabase extends Database {
let queries = []; let queries = [];
this.eventEmitter_.emit('startMigration', { version: targetVersion });
if (targetVersion == 1) { if (targetVersion == 1) {
queries = this.wrapQueries(this.sqlStringToLines(structureSql)); queries = this.wrapQueries(this.sqlStringToLines(structureSql));
} }

View File

@ -2,7 +2,7 @@ import setUpQuickActions from './setUpQuickActions';
import PluginAssetsLoader from './PluginAssetsLoader'; import PluginAssetsLoader from './PluginAssetsLoader';
const React = require('react'); const React = require('react');
const { AppState, Keyboard, NativeModules, BackHandler, Animated, View, StatusBar } = require('react-native'); const { AppState, Keyboard, NativeModules, BackHandler, Animated, View, StatusBar, Text, Image } = require('react-native');
const SafeAreaView = require('lib/components/SafeAreaView'); const SafeAreaView = require('lib/components/SafeAreaView');
const { connect, Provider } = require('react-redux'); const { connect, Provider } = require('react-redux');
const { BackButtonService } = require('lib/services/back-button.js'); const { BackButtonService } = require('lib/services/back-button.js');
@ -376,7 +376,7 @@ function decryptionWorker_resourceMetadataButNotBlobDecrypted() {
ResourceFetcher.instance().scheduleAutoAddResources(); ResourceFetcher.instance().scheduleAutoAddResources();
} }
async function initialize(dispatch) { async function initialize(dispatch, messageHandler) {
shimInit(); shimInit();
Setting.setConstant('env', __DEV__ ? 'dev' : 'prod'); Setting.setConstant('env', __DEV__ ? 'dev' : 'prod');
@ -414,8 +414,13 @@ async function initialize(dispatch) {
dbLogger.setLevel(Logger.LEVEL_INFO); dbLogger.setLevel(Logger.LEVEL_INFO);
} }
const db_startUpgrade = (event) => {
messageHandler(`Upgrading database to v${event.version}...`);
};
const db = new JoplinDatabase(new DatabaseDriverReactNative()); const db = new JoplinDatabase(new DatabaseDriverReactNative());
db.setLogger(dbLogger); db.setLogger(dbLogger);
db.eventEmitter().on('startMigration', db_startUpgrade);
reg.setDb(db); reg.setDb(db);
reg.dispatch = dispatch; reg.dispatch = dispatch;
@ -452,9 +457,13 @@ async function initialize(dispatch) {
// await db.clearForTesting(); // await db.clearForTesting();
} }
db.eventEmitter().removeListener('startMigration', db_startUpgrade);
reg.logger().info('Database is ready.'); reg.logger().info('Database is ready.');
reg.logger().info('Loading settings...'); reg.logger().info('Loading settings...');
messageHandler('Initialising application...');
await loadKeychainServiceAndSettings(KeychainServiceDriverMobile); await loadKeychainServiceAndSettings(KeychainServiceDriverMobile);
if (!Setting.value('clientId')) Setting.setValue('clientId', uuid.create()); if (!Setting.value('clientId')) Setting.setValue('clientId', uuid.create());
@ -601,6 +610,7 @@ class AppComponent extends React.Component {
this.state = { this.state = {
sideMenuContentOpacity: new Animated.Value(0), sideMenuContentOpacity: new Animated.Value(0),
initMessage: '',
}; };
this.lastSyncStarted_ = defaultState.syncStarted; this.lastSyncStarted_ = defaultState.syncStarted;
@ -614,20 +624,19 @@ class AppComponent extends React.Component {
}; };
} }
async componentDidMount() { componentDidMount() {
if (this.props.appState == 'starting') { setTimeout(async () => {
// We run initialization code with a small delay to give time
// to the view to render "please wait" messages.
this.props.dispatch({ this.props.dispatch({
type: 'APP_STATE_SET', type: 'APP_STATE_SET',
state: 'initializing', state: 'initializing',
}); });
await initialize(this.props.dispatch); await initialize(this.props.dispatch, (message) => {
this.setState({ initMessage: message });
this.props.dispatch({
type: 'APP_STATE_SET',
state: 'ready',
}); });
}
BackButtonService.initialize(this.backButtonHandler_); BackButtonService.initialize(this.backButtonHandler_);
@ -648,13 +657,19 @@ class AppComponent extends React.Component {
reg.logger.info('Cannot handle share - default folder id is not set'); reg.logger.info('Cannot handle share - default folder id is not set');
} }
} }
this.props.dispatch({
type: 'APP_STATE_SET',
state: 'ready',
});
}, 100);
} }
componentWillUnmount() { componentWillUnmount() {
AppState.removeEventListener('change', this.onAppStateChange_); AppState.removeEventListener('change', this.onAppStateChange_);
} }
componentDidUpdate(prevProps) { async componentDidUpdate(prevProps) {
if (this.props.showSideMenu !== prevProps.showSideMenu) { if (this.props.showSideMenu !== prevProps.showSideMenu) {
Animated.timing(this.state.sideMenuContentOpacity, { Animated.timing(this.state.sideMenuContentOpacity, {
toValue: this.props.showSideMenu ? 0.5 : 0, toValue: this.props.showSideMenu ? 0.5 : 0,
@ -699,8 +714,22 @@ class AppComponent extends React.Component {
}); });
} }
renderStartupScreen() {
return (
<View style={{ alignItems: 'center', justifyContent: 'center', flex: 1 }}>
<View style={{ alignItems: 'center' }}>
<Image style={{ marginBottom: 5 }} source={require('./images/StartUpIcon.png')} />
<Text style={{ color: '#444444' }}>{this.state.initMessage}</Text>
</View>
</View>
);
}
render() { render() {
if (this.props.appState != 'ready') return null; if (this.props.appState != 'ready') {
return this.renderStartupScreen();
}
const theme = themeStyle(this.props.theme); const theme = themeStyle(this.props.theme);
let sideMenuContent = null; let sideMenuContent = null;

View File

@ -281,6 +281,29 @@ const operations = [
iconWidth: 46, iconWidth: 46,
iconHeight: 46, iconHeight: 46,
}, },
// ============================================================================
// Mobile startup icon
// ============================================================================
{
source: 7,
dest: 'ReactNativeClient/images/StartUpIcon.png',
width: 64,
height: 64,
},
{
source: 7,
dest: 'ReactNativeClient/images/StartUpIcon@2x.png',
width: 128,
height: 128,
},
{
source: 7,
dest: 'ReactNativeClient/images/StartUpIcon@3x.png',
width: 192,
height: 192,
},
]; ];
async function main() { async function main() {

View File

@ -3,11 +3,7 @@
{ {
"name": ".", "name": ".",
"path": "." "path": "."
}, }
{
"name": "D:/Web/www/nextcloud/apps/joplin",
"path": "D:/Web/www/nextcloud/apps/joplin"
},
], ],
"settings": { "settings": {
"files.exclude": { "files.exclude": {