Skip to content

Commit

Permalink
Merge pull request #2 from laurent22/master
Browse files Browse the repository at this point in the history
Update fork from original repository
  • Loading branch information
rtmkrlv authored Feb 1, 2018
2 parents 44bf518 + 42c7826 commit 37e7ea0
Show file tree
Hide file tree
Showing 135 changed files with 6,146 additions and 1,145 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ _vieux/
_mydocs
.DS_Store
Assets/DownloadBadges*.psd
node_modules
node_modules
Tools/github_oauth_token.txt
_releases
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Only build tags (Doesn't work - doesn't build anything)
if: tag IS present

rvm: 2.3.3

matrix:
Expand Down Expand Up @@ -45,5 +48,4 @@ script:
- |
cd ElectronClient/app
rsync -aP --delete ../../ReactNativeClient/lib/ lib/
npm install
yarn dist
npm install && yarn dist
2 changes: 2 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ yarn dist

If there's an error `while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory`, run `sudo apt-get install libgconf-2-4`

For node-gyp to work, you might need to install the `windows-build-tools` using `npm install --global windows-build-tools`.

That will create the executable file in the `dist` directory.

From `/ElectronClient` you can also run `run.sh` to run the app for testing.
Expand Down
16 changes: 15 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Reporting a bug

Please check first that it [has not already been reported](https://github.com/laurent22/joplin/issues?utf8=%E2%9C%93&q=is%3Aissue). Also consider [enabling debug mode](https://github.com/laurent22/joplin/blob/master/README_debugging.md) before reporting the issue so that you can provide as much details as possible to help fix it.

If possible, **please provide a screenshot**. A screenshot showing the problem is often more useful than a paragraph describing it as it can make it immediately clear what the issue is.

# Feature requests

Again, please check that it has not already been requested. If it has, simply **up-vote the issue** - the ones with the most up-votes are likely to be implemented. Adding a "+1" comment does nothing.

# Adding new features

If you want to add a new feature, consider asking about it before implementing it to make sure it is within the scope of the project. Of course you are free to create the pull request directly but it is not guaranteed it is going to be accepted.

# Style
Building the apps is relatively easy - please [see the build instructions](https://github.com/laurent22/joplin/blob/master/BUILD.md) for more details.

# Coding style

- Only use tabs for indentation, not spaces.
- Do not remove or add optional characters from other lines (such as colons or new line characters) as it can make the commit needlessly big, and create conflicts with other changes.
12 changes: 5 additions & 7 deletions CliClient/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const os = require('os');
const fs = require('fs-extra');
const { cliUtils } = require('./cli-utils.js');
const EventEmitter = require('events');
const Cache = require('lib/Cache');

class Application extends BaseApplication {

Expand All @@ -34,6 +35,7 @@ class Application extends BaseApplication {
this.allCommandsLoaded_ = false;
this.showStackTraces_ = false;
this.gui_ = null;
this.cache_ = new Cache();
}

gui() {
Expand Down Expand Up @@ -223,12 +225,8 @@ class Application extends BaseApplication {
async commandMetadata() {
if (this.commandMetadata_) return this.commandMetadata_;

const osTmpdir = require('os-tmpdir');
const storage = require('node-persist');
await storage.init({ dir: osTmpdir() + '/commandMetadata', ttl: 1000 * 60 * 60 * 24 });

let output = await storage.getItem('metadata');
if (Setting.value('env') != 'dev' && output) {
let output = await this.cache_.getItem('metadata');
if (output) {
this.commandMetadata_ = output;
return Object.assign({}, this.commandMetadata_);
}
Expand All @@ -242,7 +240,7 @@ class Application extends BaseApplication {
output[n] = cmd.metadata();
}

await storage.setItem('metadata', output);
await this.cache_.setItem('metadata', output, 1000 * 60 * 60 * 24);

this.commandMetadata_ = output;
return Object.assign({}, this.commandMetadata_);
Expand Down
20 changes: 17 additions & 3 deletions CliClient/app/autocompletion.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var Folder = require('lib/models/Folder.js');
var Tag = require('lib/models/Tag.js');
var { cliUtils } = require('./cli-utils.js');
var yargParser = require('yargs-parser');
var fs = require('fs-extra');

async function handleAutocompletionPromise(line) {
// Auto-complete the command name
Expand Down Expand Up @@ -48,7 +49,7 @@ async function handleAutocompletionPromise(line) {
if (options.length > 1 && options[1].indexOf(next) === 0) {
l.push(options[1]);
} else if (options[0].indexOf(next) === 0) {
l.push(options[2]);
l.push(options[0]);
}
}
if (l.length === 0) {
Expand All @@ -71,8 +72,10 @@ async function handleAutocompletionPromise(line) {
let argName = cmdUsage[positionalArgs - 1];
argName = cliUtils.parseCommandArg(argName).name;

if (argName == 'note' || argName == 'note-pattern' && app().currentFolder()) {
const notes = await Note.previews(app().currentFolder().id, { titlePattern: next + '*' });
const currentFolder = app().currentFolder();

if (argName == 'note' || argName == 'note-pattern') {
const notes = currentFolder ? await Note.previews(currentFolder.id, { titlePattern: next + '*' }) : [];
l.push(...notes.map((n) => n.title));
}

Expand All @@ -81,11 +84,22 @@ async function handleAutocompletionPromise(line) {
l.push(...folders.map((n) => n.title));
}

if (argName == 'item') {
const notes = currentFolder ? await Note.previews(currentFolder.id, { titlePattern: next + '*' }) : [];
const folders = await Folder.search({ titlePattern: next + '*' });
l.push(...notes.map((n) => n.title), folders.map((n) => n.title));
}

if (argName == 'tag') {
let tags = await Tag.search({ titlePattern: next + '*' });
l.push(...tags.map((n) => n.title));
}

if (argName == 'file') {
let files = await fs.readdir('.');
l.push(...files);
}

if (argName == 'tag-command') {
let c = filterList(['add', 'remove', 'list'], next);
l.push(...c);
Expand Down
6 changes: 5 additions & 1 deletion CliClient/app/command-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ class Command extends BaseCommand {
const verbose = args.options.verbose;

const renderKeyValue = (name) => {
const value = Setting.value(name);
const md = Setting.settingMetadata(name);
let value = Setting.value(name);
if (typeof value === 'object' || Array.isArray(value)) value = JSON.stringify(value);
if (md.secure) value = '********';

if (Setting.isEnum(name)) {
return _('%s = %s (%s)', name, value, Setting.enumOptionsDoc(name));
} else {
Expand Down
3 changes: 2 additions & 1 deletion CliClient/app/command-e2ee.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ class Command extends BaseCommand {
} else if (stat.isDirectory()) {
continue;
} else {
itemCount++;
const content = await fs.readFile(fullPath, 'utf8');
const item = await BaseItem.unserialize(content);
const ItemClass = BaseItem.itemClass(item);
Expand All @@ -141,6 +140,8 @@ class Command extends BaseCommand {
continue;
}

itemCount++;

const isEncrypted = await EncryptionService.instance().itemIsEncrypted(item);

if (isEncrypted) {
Expand Down
4 changes: 3 additions & 1 deletion CliClient/app/command-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class Command extends BaseCommand {
const termState = app().gui().termSaveState();

const spawnSync = require('child_process').spawnSync;
spawnSync(editorPath, editorArgs, { stdio: 'inherit' });
const result = spawnSync(editorPath, editorArgs, { stdio: 'inherit' });

if (result.error) this.stdout(_('Error opening note in editor: %s', result.error.message));

app().gui().termRestoreState(termState);
app().gui().hideModalOverlay();
Expand Down
39 changes: 25 additions & 14 deletions CliClient/app/command-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const md5 = require('md5');
const locker = require('proper-lockfile');
const fs = require('fs-extra');
const osTmpdir = require('os-tmpdir');
const SyncTargetRegistry = require('lib/SyncTargetRegistry');

class Command extends BaseCommand {

Expand Down Expand Up @@ -61,14 +62,28 @@ class Command extends BaseCommand {
});
}

async doAuth(syncTargetId) {
async doAuth() {
const syncTarget = reg.syncTarget(this.syncTargetId_);
this.oneDriveApiUtils_ = new OneDriveApiNodeUtils(syncTarget.api());
const auth = await this.oneDriveApiUtils_.oauthDance({
log: (...s) => { return this.stdout(...s); }
});
this.oneDriveApiUtils_ = null;
return auth;
const syncTargetMd = SyncTargetRegistry.idToMetadata(this.syncTargetId_);

if (this.syncTargetId_ === 3 || this.syncTargetId_ === 4) { // OneDrive
this.oneDriveApiUtils_ = new OneDriveApiNodeUtils(syncTarget.api());
const auth = await this.oneDriveApiUtils_.oauthDance({
log: (...s) => { return this.stdout(...s); }
});
this.oneDriveApiUtils_ = null;

Setting.setValue('sync.' + this.syncTargetId_ + '.auth', auth ? JSON.stringify(auth) : null);
if (!auth) {
this.stdout(_('Authentication was not completed (did not receive an authentication token).'));
return false;
}

return true;
}

this.stdout(_('Not authentified with %s. Please provide any missing credentials.', syncTarget.label()));
return false;
}

cancelAuth() {
Expand All @@ -86,7 +101,7 @@ class Command extends BaseCommand {
this.releaseLockFn_ = null;

// Lock is unique per profile/database
const lockFilePath = osTmpdir() + '/synclock_' + md5(Setting.value('profileDir'));
const lockFilePath = osTmpdir() + '/synclock_' + md5(escape(Setting.value('profileDir'))); // https://github.com/pvorb/node-md5/issues/41
if (!await fs.pathExists(lockFilePath)) await fs.writeFile(lockFilePath, 'synclock');

try {
Expand Down Expand Up @@ -120,12 +135,8 @@ class Command extends BaseCommand {
app().gui().showConsole();
app().gui().maximizeConsole();

const auth = await this.doAuth(this.syncTargetId_);
Setting.setValue('sync.' + this.syncTargetId_ + '.auth', auth ? JSON.stringify(auth) : null);
if (!auth) {
this.stdout(_('Authentication was not completed (did not receive an authentication token).'));
return cleanUp();
}
const authDone = await this.doAuth();
if (!authDone) return cleanUp();
}

const sync = await syncTarget.synchronizer();
Expand Down
56 changes: 56 additions & 0 deletions CliClient/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
// Make it possible to require("/lib/...") without specifying full path
require('app-module-path').addPath(__dirname);

const compareVersion = require('compare-version');
const nodeVersion = process && process.versions && process.versions.node ? process.versions.node : '0.0.0';
if (compareVersion(nodeVersion, '8.0.0') < 0) {
console.error('Joplin requires Node 8+. Detected version ' + nodeVersion);
process.exit(1);
}

const { app } = require('./app.js');
const Folder = require('lib/models/Folder.js');
const Resource = require('lib/models/Resource.js');
Expand All @@ -16,12 +23,14 @@ const { Logger } = require('lib/logger.js');
const { FsDriverNode } = require('lib/fs-driver-node.js');
const { shimInit } = require('lib/shim-init-node.js');
const { _ } = require('lib/locale.js');
const { FileApiDriverLocal } = require('lib/file-api-driver-local.js');
const EncryptionService = require('lib/services/EncryptionService');

const fsDriver = new FsDriverNode();
Logger.fsDriver_ = fsDriver;
Resource.fsDriver_ = fsDriver;
EncryptionService.fsDriver_ = fsDriver;
FileApiDriverLocal.fsDriver_ = fsDriver;

// That's not good, but it's to avoid circular dependency issues
// in the BaseItem class.
Expand Down Expand Up @@ -57,6 +66,53 @@ process.stdout.on('error', function( err ) {
}
});





// async function main() {
// const WebDavApi = require('lib/WebDavApi');
// const api = new WebDavApi('http://nextcloud.local/remote.php/dav/files/admin/Joplin', { username: 'admin', password: '1234567' });
// const { FileApiDriverWebDav } = new require('lib/file-api-driver-webdav');
// const driver = new FileApiDriverWebDav(api);

// const stat = await driver.stat('');
// console.info(stat);

// // const stat = await driver.stat('testing.txt');
// // console.info(stat);


// // const content = await driver.get('testing.txta');
// // console.info(content);

// // const content = await driver.get('testing.txta', { target: 'file', path: '/var/www/joplin/CliClient/testing-file.txt' });
// // console.info(content);

// // const content = await driver.mkdir('newdir5');
// // console.info(content);

// //await driver.put('myfile4.md', 'this is my content');

// // await driver.put('testimg.jpg', null, { source: 'file', path: '/mnt/d/test.jpg' });

// // await driver.delete('myfile4.md');

// // const deltaResult = await driver.delta('', {
// // allItemIdsHandler: () => { return []; }
// // });
// // console.info(deltaResult);
// }

// main().catch((error) => { console.error(error); });








application.start(process.argv).catch((error) => {
console.error(_('Fatal error:'));
console.error(error);
Expand Down
Loading

0 comments on commit 37e7ea0

Please sign in to comment.