1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Various changes

This commit is contained in:
Laurent Cozic 2017-07-07 23:25:03 +01:00
parent e0664167eb
commit 38c9d49cdb
29 changed files with 108 additions and 185 deletions

View File

@ -63,7 +63,7 @@ function randomWord() {
function execCommand(client, command, options = {}) {
let exePath = 'node ' + joplinAppPath;
let cmd = exePath + ' --profile ' + client.profileDir + ' ' + command;
let cmd = exePath + ' --env dev --profile ' + client.profileDir + ' ' + command;
logger.info(client.id + ': ' + command);
if (options.killAfter) {
@ -80,7 +80,7 @@ function execCommand(client, command, options = {}) {
reject(error);
}
} else {
resolve(stdout);
resolve(stdout.trim());
}
});

View File

@ -40,6 +40,7 @@ const packageJson = require('./package.json');
let initArgs = {
profileDir: null,
env: 'prod',
}
const fsDriver = new FsDriverNode();
@ -821,6 +822,13 @@ async function handleStartFlags(argv) {
continue;
}
if (arg == '--env') {
if (!nextArg) throw new Error(_('Usage: --env <dev|prod>'));
initArgs.env = nextArg;
argv.splice(0, 2);
continue;
}
if (arg == '--redraw-disabled') {
vorpalUtils.setRedrawEnabled(false);
argv.splice(0, 1);
@ -913,27 +921,19 @@ async function main() {
let argv = process.argv;
argv = await handleStartFlags(argv);
if (argv.length) showPromptString = false;
const profileDir = initArgs.profileDir ? initArgs.profileDir : os.homedir() + '/.config/' + Setting.value('appName');
const resourceDir = profileDir + '/resources';
const tempDir = profileDir + '/tmp';
Setting.setConstant('env', initArgs.env);
Setting.setConstant('profileDir', profileDir);
Setting.setConstant('resourceDir', resourceDir);
Setting.setConstant('tempDir', tempDir);
await fs.mkdirp(profileDir, 0o755);
await fs.mkdirp(resourceDir, 0o755);
await fs.mkdirp(tempDir, 0o755);
// let logDatabase = new Database(new DatabaseDriverNode());
// await logDatabase.open({ name: profileDir + '/database-log.sqlite' });
// await logDatabase.exec(Logger.databaseCreateTableSql());
logger.addTarget('file', { path: profileDir + '/log.txt' });
// logger.addTarget('database', { database: logDatabase, source: 'main' });
logger.setLevel(logLevel);
dbLogger.addTarget('file', { path: profileDir + '/log-database.txt' });
@ -943,6 +943,7 @@ async function main() {
syncLogger.setLevel(logLevel);
logger.info(sprintf('Starting %s %s...', packageJson.name, packageJson.version));
logger.info('Environment: ' + Setting.value('env'));
logger.info('Profile directory: ' + profileDir);
// That's not good, but it's to avoid circular dependency issues
@ -969,7 +970,9 @@ async function main() {
// If we still have arguments, pass it to Vorpal and exit
if (argv.length) {
vorpal.show();
//vorpal.delimiter(' AAAAAAAAAAAAAAAAAAAAA');
//console.info(vorpal.ui.inquirer);
//vorpal.show();
let cmd = shellArgsToString(argv);
await vorpal.exec(cmd);
await vorpal.exec('exit');

View File

@ -1,6 +1,6 @@
#!/bin/bash
set -e
CLIENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes2 --stack-trace-enabled --log-level debug --redraw-disabled "$@"
bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes2 --stack-trace-enabled --log-level debug --redraw-disabled --env dev "$@"
#bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes import-enex --fuzzy-matching /home/laurent/Desktop/afaire.enex afaire
#bash $CLIENT_DIR/build.sh && NODE_PATH="$CLIENT_DIR/build/" node build/main.js --profile ~/Temp/TestNotes import-enex --fuzzy-matching /home/laurent/Desktop/Laurent.enex laurent

1
CliClient/test.txt Normal file
View File

@ -0,0 +1 @@
[]

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@ -45,12 +45,12 @@ android_library(
android_build_config(
name = "build_config",
package = "com.awesomeproject",
package = "net.cozic.joplin",
)
android_resource(
name = "res",
package = "com.awesomeproject",
package = "net.cozic.joplin",
res = "src/main/res",
)

View File

@ -75,7 +75,7 @@ apply from: "../../node_modules/react-native/react.gradle"
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = false
def enableSeparateBuildPerCPUArchitecture = true
/**
* Run Proguard to shrink the Java bytecode in release builds.
@ -87,11 +87,11 @@ android {
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.awesomeproject"
applicationId "net.cozic.joplin"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
versionCode 2
versionName "0.8.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}

View File

@ -1,12 +1,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.awesomeproject"
android:versionCode="1"
android:versionName="1.0">
xmlns:tools="http://schemas.android.com/tools"
package="net.cozic.joplin"
android:versionCode="2"
android:versionName="0.8.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove"/>
<uses-sdk
android:minSdkVersion="16"

View File

@ -1,4 +1,4 @@
package com.awesomeproject;
package net.cozic.joplin;
import com.facebook.react.ReactActivity;
@ -10,6 +10,6 @@ public class MainActivity extends ReactActivity {
*/
@Override
protected String getMainComponentName() {
return "AwesomeProject";
return "Joplin";
}
}

View File

@ -1,4 +1,4 @@
package com.awesomeproject;
package net.cozic.joplin;
import android.app.Application;

View File

@ -1,3 +1,3 @@
<resources>
<string name="app_name">AwesomeProject</string>
<string name="app_name">Joplin</string>
</resources>

View File

@ -1,4 +1,4 @@
rootProject.name = 'AwesomeProject'
rootProject.name = 'Joplin'
include ':react-native-fs'
project(':react-native-fs').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fs/android')

View File

@ -1,10 +1,10 @@
{
"name": "AwesomeProject",
"displayName": "AwesomeProject",
"name": "Joplin",
"displayName": "Joplin",
"expo": {
"name": "AwesomeProject",
"description": "No description",
"slug": "AwesomeProject",
"name": "Joplin",
"description": "Joplin for Android",
"slug": "Joplin",
"privacy": "public",
"sdkVersion": "18.0.0",
"version": "1.0.0",

View File

@ -12,7 +12,7 @@ import {
View
} from 'react-native';
export default class AwesomeProject extends Component {
export default class Joplin extends Component {
render() {
return (
<View style={styles.container}>
@ -50,4 +50,4 @@ const styles = StyleSheet.create({
},
});
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
AppRegistry.registerComponent('Joplin', () => Joplin);

View File

@ -94,9 +94,7 @@ ScreenHeaderComponent.defaultProps = {
};
const ScreenHeader = connect(
(state) => {
return { user: state.user };
}
//(state) => {}
)(ScreenHeaderComponent)
export { ScreenHeader };

View File

@ -1,91 +0,0 @@
import React, { Component } from 'react';
import { View, Button, TextInput, Text } from 'react-native';
import { connect } from 'react-redux'
import { Log } from 'lib/log.js'
import { Setting } from 'lib/models/setting.js';
import { ScreenHeader } from 'lib/components/screen-header.js';
import { _ } from 'lib/locale.js';
class LoginScreenComponent extends React.Component {
static navigationOptions(options) {
return { header: null };
}
constructor() {
super();
this.state = {
email: '',
password: '',
errorMessage: null,
};
}
componentWillMount() {
this.setState({ email: this.props.user.email });
}
email_changeText(text) {
this.setState({ email: text });
}
password_changeText(text) {
this.setState({ password: text });
}
loginButton_press() {
this.setState({ errorMessage: null });
// return Registry.api().post('sessions', null, {
// 'email': this.state.email,
// 'password': this.state.password,
// 'client_id': Setting.value('clientId'),
// }).then((session) => {
// Log.info('Got session', session);
// let user = {
// email: this.state.email,
// session: session.id,
// };
// Setting.setObject('user', user);
// this.props.dispatch({
// type: 'USER_SET',
// user: user,
// });
// this.props.dispatch({
// type: 'Navigation/BACK',
// });
// Registry.api().setSession(session.id);
// //Registry.synchronizer().start();
// }).catch((error) => {
// this.setState({ errorMessage: _('Could not login: %s)', error.message) });
// });
}
render() {
return (
<View style={{flex: 1}}>
<ScreenHeader navState={this.props.navigation.state} />
<TextInput value={this.state.email} onChangeText={(text) => this.email_changeText(text)} keyboardType="email-address" />
<TextInput value={this.state.password} onChangeText={(text) => this.password_changeText(text)} secureTextEntry={true} />
{ this.state.errorMessage && <Text style={{color:'#ff0000'}}>{this.state.errorMessage}</Text> }
<Button title="Login" onPress={() => this.loginButton_press()} />
</View>
);
}
}
const LoginScreen = connect(
(state) => {
return {
user: state.user,
};
}
)(LoginScreenComponent)
export { LoginScreen };

View File

@ -48,9 +48,7 @@ class SideMenuContentComponent extends Component {
}
folder_press(folder) {
this.props.dispatch({
type: 'SIDE_MENU_CLOSE',
});
this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
NotesScreenUtils.openNoteList(folder.id);
}
@ -64,6 +62,7 @@ class SideMenuContentComponent extends Component {
line.push(_('Remote items to delete: %d/%d.', report.deleteRemote, report.remotesToDelete));
line.push(_('Items to download: %d/%d.', report.createLocal + report.updateLocal, report.localsToUdpate));
line.push(_('Local items to delete: %d/%d.', report.deleteLocal, report.localsToDelete));
line.push(_('Sync state: %s.', report.state));
this.setState({ syncReportText: line.join("\n") });
},
};
@ -75,6 +74,8 @@ class SideMenuContentComponent extends Component {
Log.error(error);
}
} else {
this.props.dispatch({ type: 'SIDE_MENU_CLOSE' });
this.props.dispatch({
type: 'Navigation/NAVIGATE',
routeName: 'OneDriveLogin',

View File

@ -1,11 +0,0 @@
import { BaseModel } from 'lib/base-model.js';
class Session extends BaseModel {
static login(email, password) {
}
}
export { Session };

View File

@ -144,7 +144,6 @@ class Setting extends BaseModel {
}
Setting.defaults_ = {
'clientId': { value: '', type: 'string', public: false },
'activeFolderId': { value: '', type: 'string', public: false },
'sync.onedrive.auth': { value: '', type: 'string', public: false },
'sync.local.path': { value: '', type: 'string', public: true },
@ -155,12 +154,12 @@ Setting.defaults_ = {
// Contains constants that are set by the application and
// cannot be modified by the user:
Setting.constants_ = {
'env': 'SET_ME',
'appName': 'joplin',
'appId': 'SET_ME', // Each app should set this identifier
'appType': 'SET_ME', // 'cli' or 'mobile'
'resourceDir': '',
'profileDir': '',
'tempDir': '',
}
export { Setting };

View File

@ -160,7 +160,7 @@ class OneDriveApi {
let errorResponse = await response.json();
let error = this.oneDriveErrorResponseToError(errorResponse);
if (error.code == 'InvalidAuthenticationToken') {
if (error.code == 'InvalidAuthenticationToken' || error.code == 'unauthenticated') {
await this.refreshAccessToken();
continue;
} else if (error && ((error.error && error.error.code == 'generalException') || (error.code == 'generalException'))) {

View File

@ -0,0 +1,23 @@
import { Setting } from 'lib/models/setting.js';
const parameters_ = {};
parameters_.dev = {
oneDrive: {
id: 'cbabb902-d276-4ea4-aa88-062a5889d6dc',
secret: 'YSvrgQMqw9NzVqgiLfuEky1',
},
};
parameters_.prod = {
oneDrive: {
id: 'e09fc0de-c958-424f-83a2-e56a721d331b',
secret: 'JA3cwsqSGHFtjMwd5XoF5L5',
},
};
function parameters() {
return parameters_[Setting.value('env')];
}
export { parameters }

View File

@ -1,6 +1,7 @@
import { Logger } from 'lib/logger.js';
import { Setting } from 'lib/models/setting.js';
import { OneDriveApi } from 'lib/onedrive-api.js';
import { parameters } from 'lib/parameters.js';
import { FileApi } from 'lib/file-api.js';
import { Synchronizer } from 'lib/synchronizer.js';
import { FileApiDriverOneDrive } from 'lib/file-api-driver-onedrive.js';
@ -18,11 +19,9 @@ reg.logger = () => {
reg.oneDriveApi = () => {
if (reg.oneDriveApi_) return reg.oneDriveApi_;
const CLIENT_ID = 'e09fc0de-c958-424f-83a2-e56a721d331b';
const CLIENT_SECRET = 'JA3cwsqSGHFtjMwd5XoF5L5';
const isPublic = Setting.value('appType') != 'cli';
reg.oneDriveApi_ = new OneDriveApi(CLIENT_ID, CLIENT_SECRET, isPublic);
reg.oneDriveApi_ = new OneDriveApi(parameters().oneDrive.id, parameters().oneDrive.secret, isPublic);
reg.oneDriveApi_.on('authRefreshed', (a) => {
reg.logger().info('Saving updated OneDrive auth.');

View File

@ -121,6 +121,8 @@ class Synchronizer {
deleteRemote: 0,
itemConflict: 0,
noteConflict: 0,
state: this.state(),
};
try {
@ -369,12 +371,13 @@ class Synchronizer {
throw error;
}
options.onProgress(report);
this.logger().info('Synchronization complete [' + synchronizationId + ']:');
await this.logSyncSummary(report);
this.state_ = 'idle';
report.state = this.state();
options.onProgress(report);
}
}

View File

@ -11,7 +11,7 @@ import { Log } from 'lib/log.js'
import { Root } from './root.js';
function main() {
AppRegistry.registerComponent('AwesomeProject', () => Root);
AppRegistry.registerComponent('Joplin', () => Root);
console.ignoredYellowBox = ['Remote debugger'];
Log.info('START ======================================================================================================');
// Note: The final part of the initialization process is in

View File

@ -1,37 +1,37 @@
{
"name": "AwesomeProject",
"version": "0.0.1",
"name": "Joplin",
"description": "Joplin for Android",
"license": "MIT",
"version": "0.8.0",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"dropbox": "^2.5.4",
"form-data": "^2.1.4",
"moment": "^2.18.1",
"react": "16.0.0-alpha.12",
"react-native": "0.46.0",
"react-native-action-button": "^2.6.9",
"react-native-checkbox": "^1.1.0",
"react-native-fetch-blob": "^0.10.6",
"react-native-fs": "^2.3.3",
"react-native-popup-menu": "^0.7.4",
"react-native-side-menu": "^0.20.1",
"react-native-vector-icons": "^2.0.3",
"react-navigation": "^1.0.0-beta.9",
"uuid": "^3.0.1"
},
"devDependencies": {
"babel-jest": "19.0.0",
"babel-preset-react-native": "1.9.1",
"jest": "19.0.2",
"react-test-renderer": "16.0.0-alpha.6",
"uuid": "^3.0.1",
"redux": "3.6.0",
"react-redux": "4.4.8",
"query-string": "4.3.4",
"react-native-sqlite-storage": "3.3.*"
},
"devDependencies": {
"babel-jest": "19.0.0",
"babel-preset-react-native": "1.9.1",
"jest": "19.0.2",
"react-test-renderer": "16.0.0-alpha.6"
},
"jest": {
"preset": "react-native"
}

View File

@ -24,7 +24,6 @@ import { NotesScreenUtils } from 'lib/components/screens/notes-utils.js'
import { NoteScreen } from 'lib/components/screens/note.js'
import { FolderScreen } from 'lib/components/screens/folder.js'
import { FoldersScreen } from 'lib/components/screens/folders.js'
import { LoginScreen } from 'lib/components/screens/login.js'
import { LogScreen } from 'lib/components/screens/log.js'
import { LoadingScreen } from 'lib/components/screens/loading.js'
import { OneDriveLoginScreen } from 'lib/components/screens/onedrive-login.js'
@ -43,7 +42,6 @@ let defaultState = {
selectedNoteId: null,
selectedItemType: 'note',
selectedFolderId: null,
user: { email: 'laurent@cozic.net', session: null },
showSideMenu: false,
};
@ -100,6 +98,8 @@ const reducer = (state = defaultState, action) => {
// update it within the note array if it already exists.
case 'NOTES_UPDATE_ONE':
if (action.note.parent_id != state.selectedFolderId) break;
let newNotes = state.notes.splice(0);
var found = false;
for (let i = 0; i < newNotes.length; i++) {
@ -155,12 +155,6 @@ const reducer = (state = defaultState, action) => {
newState.folders = newFolders;
break;
case 'USER_SET':
newState = Object.assign({}, state);
newState.user = action.user;
break;
case 'SIDE_MENU_TOGGLE':
newState = Object.assign({}, state);
@ -193,7 +187,6 @@ const AppNavigator = StackNavigator({
Note: { screen: NoteScreen },
Folder: { screen: FolderScreen },
Folders: { screen: FoldersScreen },
Login: { screen: LoginScreen },
Loading: { screen: LoadingScreen },
OneDriveLogin: { screen: OneDriveLoginScreen },
Log: { screen: LogScreen },
@ -237,15 +230,17 @@ class AppComponent extends React.Component {
}
}
Setting.setConstant('appId', 'net.cozic.joplin-android');
Setting.setConstant('env', __DEV__ ? 'dev' : 'prod');
Setting.setConstant('appId', 'net.cozic.joplin');
Setting.setConstant('appType', 'mobile');
Setting.setConstant('resourceDir', RNFetchBlob.fs.dirs.DocumentDir);
const logDatabase = new Database(new DatabaseDriverReactNative());
await logDatabase.open({ name: 'log.sqlite' });
await logDatabase.exec(Logger.databaseCreateTableSql());
reg.logger().addTarget('database', { database: logDatabase, source: 'm' });
reg.logger().info('Starting application' + Setting.value('appId'));
reg.logger().info('Starting application ' + Setting.value('appId') + ' (' + Setting.value('env') + ')');
let db = new JoplinDatabase(new DatabaseDriverReactNative());
reg.setDb(db);
@ -261,23 +256,24 @@ class AppComponent extends React.Component {
BaseItem.loadClass('NoteTag', NoteTag);
try {
await db.open({ name: 'joplin-50.sqlite' })
if (Setting.value('env') == 'prod') {
await db.open({ name: 'joplin.sqlite' })
} else {
await db.open({ name: 'joplin-51.sqlite' })
// await db.exec('DELETE FROM notes');
// await db.exec('DELETE FROM folders');
// await db.exec('DELETE FROM tags');
// await db.exec('DELETE FROM note_tags');
// await db.exec('DELETE FROM resources');
// await db.exec('DELETE FROM deleted_items');
}
reg.logger().info('Database is ready.');
//await db.exec('DELETE FROM notes');
//await db.exec('DELETE FROM folders');
//await db.exec('DELETE FROM tags');
//await db.exec('DELETE FROM note_tags');
//await db.exec('DELETE FROM resources');
//await db.exec('DELETE FROM deleted_items');
reg.logger().info('Loading settings...');
await Setting.load();
Setting.setConstant('resourceDir', RNFetchBlob.fs.dirs.DocumentDir);
reg.logger().info('Loading folders...');
let folders = await Folder.all();
this.props.dispatch({