diff --git a/ElectronClient/app/envFromArgs.js b/ElectronClient/app/envFromArgs.js new file mode 100644 index 000000000..1180d413b --- /dev/null +++ b/ElectronClient/app/envFromArgs.js @@ -0,0 +1,11 @@ +// Flags are parsed properly in BaseApplication, however it's better to have +// the env as early as possible to enable debugging capabilities. +function envFromArgs(args) { + if (!args) return 'prod'; + const envIndex = args.indexOf('--env'); + const devIndex = args.indexOf('dev'); + if (envIndex === devIndex - 1) return 'dev'; + return 'prod'; +} + +module.exports = envFromArgs; diff --git a/ElectronClient/app/main.js b/ElectronClient/app/main.js index 04a18e948..2510093e5 100644 --- a/ElectronClient/app/main.js +++ b/ElectronClient/app/main.js @@ -8,22 +8,13 @@ const { ElectronAppWrapper } = require('./ElectronAppWrapper'); const { initBridge } = require('./bridge'); const { Logger } = require('lib/logger.js'); const { FsDriverNode } = require('lib/fs-driver-node.js'); +const envFromArgs = require('./envFromArgs'); process.on('unhandledRejection', (reason, p) => { console.error('Unhandled promise rejection', p, 'reason:', reason); process.exit(1); }); -// Flags are parsed properly in BaseApplication, however it's better to have -// the env as early as possible to enable debugging capabilities. -function envFromArgs(args) { - if (!args) return 'prod'; - const envIndex = args.indexOf('--env'); - const devIndex = args.indexOf('dev'); - if (envIndex === devIndex - 1) return 'dev'; - return 'prod'; -} - // Likewise, we want to know if a profile is specified early, in particular // to save the window state data. function profileFromArgs(args) { diff --git a/ReactNativeClient/lib/BaseApplication.js b/ReactNativeClient/lib/BaseApplication.js index 0faa04cb2..a1e905def 100644 --- a/ReactNativeClient/lib/BaseApplication.js +++ b/ReactNativeClient/lib/BaseApplication.js @@ -40,13 +40,6 @@ const SearchEngine = require('lib/services/SearchEngine'); const KvStore = require('lib/services/KvStore'); const MigrationService = require('lib/services/MigrationService'); -SyncTargetRegistry.addClass(SyncTargetFilesystem); -SyncTargetRegistry.addClass(SyncTargetOneDrive); -SyncTargetRegistry.addClass(SyncTargetOneDriveDev); -SyncTargetRegistry.addClass(SyncTargetNextcloud); -SyncTargetRegistry.addClass(SyncTargetWebDAV); -SyncTargetRegistry.addClass(SyncTargetDropbox); - class BaseApplication { constructor() { this.logger_ = new Logger(); @@ -580,6 +573,13 @@ class BaseApplication { Setting.setConstant('resourceDir', resourceDir); Setting.setConstant('tempDir', tempDir); + SyncTargetRegistry.addClass(SyncTargetFilesystem); + SyncTargetRegistry.addClass(SyncTargetOneDrive); + if (Setting.value('env') === 'dev') SyncTargetRegistry.addClass(SyncTargetOneDriveDev); + SyncTargetRegistry.addClass(SyncTargetNextcloud); + SyncTargetRegistry.addClass(SyncTargetWebDAV); + SyncTargetRegistry.addClass(SyncTargetDropbox); + await shim.fsDriver().remove(tempDir); await fs.mkdirp(profileDir, 0o755); diff --git a/ReactNativeClient/lib/BaseSyncTarget.js b/ReactNativeClient/lib/BaseSyncTarget.js index e0d2c7528..d0da78c32 100644 --- a/ReactNativeClient/lib/BaseSyncTarget.js +++ b/ReactNativeClient/lib/BaseSyncTarget.js @@ -33,6 +33,11 @@ class BaseSyncTarget { return this.db_; } + // If [] is returned it means all platforms are supported + static unsupportedPlatforms() { + return []; + } + async isAuthenticated() { return false; } diff --git a/ReactNativeClient/lib/SyncTargetFilesystem.js b/ReactNativeClient/lib/SyncTargetFilesystem.js index 7d14391aa..f0c289818 100644 --- a/ReactNativeClient/lib/SyncTargetFilesystem.js +++ b/ReactNativeClient/lib/SyncTargetFilesystem.js @@ -18,6 +18,10 @@ class SyncTargetFilesystem extends BaseSyncTarget { return _('File system'); } + static unsupportedPlatforms() { + return ['ios']; + } + async isAuthenticated() { return true; } diff --git a/ReactNativeClient/lib/SyncTargetRegistry.js b/ReactNativeClient/lib/SyncTargetRegistry.js index e85293d65..cd217f987 100644 --- a/ReactNativeClient/lib/SyncTargetRegistry.js +++ b/ReactNativeClient/lib/SyncTargetRegistry.js @@ -35,11 +35,15 @@ class SyncTargetRegistry { return this.idToMetadata(id).name; } - static idAndLabelPlainObject() { + static idAndLabelPlainObject(os) { let output = {}; for (let n in this.reg_) { if (!this.reg_.hasOwnProperty(n)) continue; - output[n] = this.reg_[n].label; + const info = this.reg_[n]; + if (info.classRef.unsupportedPlatforms().indexOf(os) >= 0) { + continue; + } + output[n] = info.label; } return output; } diff --git a/ReactNativeClient/lib/models/Setting.js b/ReactNativeClient/lib/models/Setting.js index ebf9a29c6..bb144fd4f 100644 --- a/ReactNativeClient/lib/models/Setting.js +++ b/ReactNativeClient/lib/models/Setting.js @@ -62,7 +62,7 @@ class Setting extends BaseModel { return appType !== 'cli' ? null : _('The target to synchonise to. Each sync target may have additional parameters which are named as `sync.NUM.NAME` (all documented below).'); }, options: () => { - return SyncTargetRegistry.idAndLabelPlainObject(); + return SyncTargetRegistry.idAndLabelPlainObject(platform); }, }, diff --git a/ReactNativeClient/lib/shim.js b/ReactNativeClient/lib/shim.js index 8a9e069e8..09e05f2cc 100644 --- a/ReactNativeClient/lib/shim.js +++ b/ReactNativeClient/lib/shim.js @@ -33,7 +33,7 @@ shim.isMac = () => { }; shim.platformName = function() { - if (shim.isReactNative()) return 'mobile'; + if (shim.isReactNative()) return shim.mobilePlatform(); if (shim.isMac()) return 'darwin'; if (shim.isWindows()) return 'win32'; if (shim.isLinux()) return 'linux'; diff --git a/ReactNativeClient/root.js b/ReactNativeClient/root.js index b30a7f176..49f164696 100644 --- a/ReactNativeClient/root.js +++ b/ReactNativeClient/root.js @@ -70,8 +70,9 @@ const SyncTargetOneDriveDev = require('lib/SyncTargetOneDriveDev.js'); const SyncTargetNextcloud = require('lib/SyncTargetNextcloud.js'); const SyncTargetWebDAV = require('lib/SyncTargetWebDAV.js'); const SyncTargetDropbox = require('lib/SyncTargetDropbox.js'); + SyncTargetRegistry.addClass(SyncTargetOneDrive); -SyncTargetRegistry.addClass(SyncTargetOneDriveDev); +if (__DEV__) SyncTargetRegistry.addClass(SyncTargetOneDriveDev); SyncTargetRegistry.addClass(SyncTargetNextcloud); SyncTargetRegistry.addClass(SyncTargetWebDAV); SyncTargetRegistry.addClass(SyncTargetDropbox);