1
0
mirror of https://github.com/laurent22/joplin.git synced 2026-05-22 09:05:38 +02:00

Got sync to work

This commit is contained in:
Laurent Cozic
2017-11-06 21:11:15 +00:00
parent c1cb020283
commit 26d9b57923
6 changed files with 49 additions and 43 deletions
@@ -6,7 +6,7 @@ const { Header } = require('./Header.min.js');
const { themeStyle } = require('../theme.js'); const { themeStyle } = require('../theme.js');
const { _ } = require('lib/locale.js'); const { _ } = require('lib/locale.js');
class OneDriveAuthScreenComponent extends React.Component { class OneDriveLoginScreenComponent extends React.Component {
constructor() { constructor() {
super(); super();
@@ -104,6 +104,6 @@ const mapStateToProps = (state) => {
return {}; return {};
}; };
const OneDriveAuthScreen = connect(mapStateToProps)(OneDriveAuthScreenComponent); const OneDriveLoginScreen = connect(mapStateToProps)(OneDriveLoginScreenComponent);
module.exports = { OneDriveAuthScreen }; module.exports = { OneDriveLoginScreen };
+2 -2
View File
@@ -4,7 +4,7 @@ const { createStore } = require('redux');
const { connect, Provider } = require('react-redux'); const { connect, Provider } = require('react-redux');
const { MainScreen } = require('./MainScreen.min.js'); const { MainScreen } = require('./MainScreen.min.js');
const { OneDriveAuthScreen } = require('./OneDriveAuthScreen.min.js'); const { OneDriveLoginScreen } = require('./OneDriveLoginScreen.min.js');
const { Navigator } = require('./Navigator.min.js'); const { Navigator } = require('./Navigator.min.js');
const { app } = require('../app'); const { app } = require('../app');
@@ -51,7 +51,7 @@ class RootComponent extends React.Component {
const screens = { const screens = {
Main: { screen: MainScreen }, Main: { screen: MainScreen },
OneDriveAuth: { screen: OneDriveAuthScreen }, OneDriveLogin: { screen: OneDriveLoginScreen },
}; };
return ( return (
+2 -5
View File
@@ -19,11 +19,8 @@ class SideBarComponent extends React.Component {
}); });
} }
sync_click() { async sync_click() {
this.props.dispatch({ await shared.synchronize_press(this);
type: 'NAV_GO',
routeName: 'OneDriveAuth',
});
} }
folderItem(folder, selected) { folderItem(folder, selected) {
+8 -7
View File
@@ -182,13 +182,13 @@ class BaseApplication {
reducerActionToString(action) { reducerActionToString(action) {
let o = [action.type]; let o = [action.type];
if (action.id) o.push(action.id); if ('id' in action) o.push(action.id);
if (action.noteId) o.push(action.noteId); if ('noteId' in action) o.push(action.noteId);
if (action.folderId) o.push(action.folderId); if ('folderId' in action) o.push(action.folderId);
if (action.tagId) o.push(action.tagId); if ('tagId' in action) o.push(action.tagId);
if (action.tag) o.push(action.tag.id); if ('tag' in action) o.push(action.tag.id);
if (action.folder) o.push(action.folder.id); if ('folder' in action) o.push(action.folder.id);
if (action.notesSource) o.push(JSON.stringify(action.notesSource)); if ('notesSource' in action) o.push(JSON.stringify(action.notesSource));
return o.join(', '); return o.join(', ');
} }
@@ -239,6 +239,7 @@ class BaseApplication {
this.store_ = createStore(this.reducer, applyMiddleware(this.generalMiddleware())); this.store_ = createStore(this.reducer, applyMiddleware(this.generalMiddleware()));
BaseModel.dispatch = this.store().dispatch; BaseModel.dispatch = this.store().dispatch;
FoldersScreenUtils.dispatch = this.store().dispatch; FoldersScreenUtils.dispatch = this.store().dispatch;
reg.dispatch = this.store().dispatch;
} }
async start(argv) { async start(argv) {
@@ -20,4 +20,36 @@ shared.renderTags = function(props, renderItem) {
return tagItems; return tagItems;
} }
shared.synchronize_press = async function(comp) {
const { Setting } = require('lib/models/setting.js');
const { reg } = require('lib/registry.js');
const action = comp.props.syncStarted ? 'cancel' : 'start';
if (Setting.value('sync.target') == Setting.SYNC_TARGET_ONEDRIVE && !reg.oneDriveApi().auth()) {
comp.props.dispatch({
type: 'NAV_GO',
routeName: 'OneDriveLogin',
});
return 'auth';
}
let sync = null;
try {
sync = await reg.synchronizer(Setting.value('sync.target'))
} catch (error) {
reg.logger().info('Could not acquire synchroniser:');
reg.logger().info(error);
return 'error';
}
if (action == 'cancel') {
sync.cancel();
return 'cancel';
} else {
reg.scheduleSync(0);
return 'sync';
}
}
module.exports = shared; module.exports = shared;
@@ -105,32 +105,8 @@ class SideMenuContentComponent extends Component {
} }
async synchronize_press() { async synchronize_press() {
const action = this.props.syncStarted ? 'cancel' : 'start'; const actionDone = await shared.synchronize_press(this);
if (actionDone === 'auth') this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
if (Setting.value('sync.target') == Setting.SYNC_TARGET_ONEDRIVE && !reg.oneDriveApi().auth()) {
this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
this.props.dispatch({
type: 'NAV_GO',
routeName: 'OneDriveLogin',
});
return;
}
let sync = null;
try {
sync = await reg.synchronizer(Setting.value('sync.target'))
} catch (error) {
reg.logger().info('Could not acquire synchroniser:');
reg.logger().info(error);
return;
}
if (action == 'cancel') {
sync.cancel();
} else {
reg.scheduleSync(0);
}
} }
folderItem(folder, selected) { folderItem(folder, selected) {