1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-17 18:44:45 +02:00

Android: Fixes #3800: Simplify initialisation code to prevent sharing

with app to create multiple instance of app and break settings.

Revert "Mobile: Add startup screen to show progress of db migration"

This reverts commit 569355a318.
This commit is contained in:
Laurent Cozic 2020-10-08 11:35:29 +01:00
parent c2c7efee91
commit 73b33e8e32
8 changed files with 33 additions and 86 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

View File

@ -3,7 +3,6 @@ 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 (
@ -127,11 +126,6 @@ class JoplinDatabase extends Database {
this.version_ = null; this.version_ = null;
this.tableFieldNames_ = {}; this.tableFieldNames_ = {};
this.extensionToLoad = './build/lib/sql-extensions/spellfix'; this.extensionToLoad = './build/lib/sql-extensions/spellfix';
this.eventEmitter_ = new EventEmitter();
}
eventEmitter() {
return this.eventEmitter_;
} }
initialized() { initialized() {
@ -361,8 +355,6 @@ 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, Text, Image } = require('react-native'); const { AppState, Keyboard, NativeModules, BackHandler, Animated, View, StatusBar } = 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, messageHandler) { async function initialize(dispatch) {
shimInit(); shimInit();
Setting.setConstant('env', __DEV__ ? 'dev' : 'prod'); Setting.setConstant('env', __DEV__ ? 'dev' : 'prod');
@ -415,13 +415,8 @@ async function initialize(dispatch, messageHandler) {
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;
@ -458,13 +453,9 @@ async function initialize(dispatch, messageHandler) {
// 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());
@ -611,7 +602,6 @@ 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;
@ -625,52 +615,47 @@ class AppComponent extends React.Component {
}; };
} }
componentDidMount() { async componentDidMount() {
setTimeout(async () => { if (this.props.appState == 'starting') {
// 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, (message) => { await initialize(this.props.dispatch);
this.setState({ initMessage: message });
});
BackButtonService.initialize(this.backButtonHandler_);
AlarmService.setInAppNotificationHandler(async (alarmId) => {
const alarm = await Alarm.load(alarmId);
const notification = await Alarm.makeNotification(alarm);
this.dropdownAlert_.alertWithType('info', notification.title, notification.body ? notification.body : '');
});
AppState.addEventListener('change', this.onAppStateChange_);
const sharedData = await ShareExtension.data();
if (sharedData) {
reg.logger().info('Received shared data');
if (this.props.selectedFolderId) {
handleShared(sharedData, this.props.selectedFolderId, this.props.dispatch);
} else {
reg.logger.info('Cannot handle share - default folder id is not set');
}
}
this.props.dispatch({ this.props.dispatch({
type: 'APP_STATE_SET', type: 'APP_STATE_SET',
state: 'ready', state: 'ready',
}); });
}, 100); }
BackButtonService.initialize(this.backButtonHandler_);
AlarmService.setInAppNotificationHandler(async (alarmId) => {
const alarm = await Alarm.load(alarmId);
const notification = await Alarm.makeNotification(alarm);
this.dropdownAlert_.alertWithType('info', notification.title, notification.body ? notification.body : '');
});
AppState.addEventListener('change', this.onAppStateChange_);
const sharedData = await ShareExtension.data();
if (sharedData) {
reg.logger().info('Received shared data');
if (this.props.selectedFolderId) {
handleShared(sharedData, this.props.selectedFolderId, this.props.dispatch);
} else {
reg.logger.info('Cannot handle share - default folder id is not set');
}
}
} }
componentWillUnmount() { componentWillUnmount() {
AppState.removeEventListener('change', this.onAppStateChange_); AppState.removeEventListener('change', this.onAppStateChange_);
} }
async componentDidUpdate(prevProps) { 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,
@ -715,19 +700,8 @@ 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 this.renderStartupScreen(); if (this.props.appState != 'ready') return null;
const theme = themeStyle(this.props.themeId); const theme = themeStyle(this.props.themeId);
let sideMenuContent = null; let sideMenuContent = null;

View File

@ -281,29 +281,6 @@ 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,7 +3,11 @@
{ {
"name": ".", "name": ".",
"path": "." "path": "."
} },
{
"name": "D:/Web/www/nextcloud/apps/joplin",
"path": "D:/Web/www/nextcloud/apps/joplin"
},
], ],
"settings": { "settings": {
"files.exclude": { "files.exclude": {