Showing
6 changed files
with
16 additions
and
4 deletions
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
| 1 | +import { ServiceLocator } from './service-locator'; | ||
| 1 | import { NodeFileHandler } from './file-handler/node-file-handler'; | 2 | import { NodeFileHandler } from './file-handler/node-file-handler'; |
| 2 | 3 | ||
| 3 | export default class Bsync { | 4 | export default class Bsync { |
| 4 | 5 | ||
| 6 | + static NodeFileHandler = NodeFileHandler; | ||
| 7 | + | ||
| 8 | + static ServiceLocator = ServiceLocator; | ||
| 9 | + | ||
| 5 | static configIpcMain(ipcMain: any, basePath: string) { | 10 | static configIpcMain(ipcMain: any, basePath: string) { |
| 6 | 11 | ||
| 7 | ipcMain.on('bsync-download', (event, args) => { | 12 | ipcMain.on('bsync-download', (event, args) => { | ... | ... |
| 1 | +import {NodeFileHandler} from './file-handler/node-file-handler'; | ||
| 1 | import {FileHandler} from './api/file-handler'; | 2 | import {FileHandler} from './api/file-handler'; |
| 2 | import {ElectronFileHandler} from './file-handler/electron-file-handler'; | 3 | import {ElectronFileHandler} from './file-handler/electron-file-handler'; |
| 3 | import {CordovaFileHandler} from './file-handler/cordova-file-handler'; | 4 | import {CordovaFileHandler} from './file-handler/cordova-file-handler'; |
| ... | @@ -12,6 +13,7 @@ import { | ... | @@ -12,6 +13,7 @@ import { |
| 12 | CONFIG_TARGET_DIRECTORY | 13 | CONFIG_TARGET_DIRECTORY |
| 13 | } from './config'; | 14 | } from './config'; |
| 14 | 15 | ||
| 16 | +export const ENV_NODE = "node"; | ||
| 15 | export const ENV_ELECTRON = "electron"; | 17 | export const ENV_ELECTRON = "electron"; |
| 16 | export const ENV_CORDOVA = "cordova"; | 18 | export const ENV_CORDOVA = "cordova"; |
| 17 | export const ENV_UNKNOWN = "unknown"; | 19 | export const ENV_UNKNOWN = "unknown"; |
| ... | @@ -35,12 +37,15 @@ export class ServiceLocator { | ... | @@ -35,12 +37,15 @@ export class ServiceLocator { |
| 35 | } | 37 | } |
| 36 | 38 | ||
| 37 | static getEnvironment() { | 39 | static getEnvironment() { |
| 38 | - if (typeof window['require'] === 'function' && window['require']('electron')) { | 40 | + if (typeof window != 'undefined' && typeof window['require'] === 'function' && window['require']('electron')) { |
| 39 | return ENV_ELECTRON; | 41 | return ENV_ELECTRON; |
| 40 | } | 42 | } |
| 41 | - if (typeof window['FileTransfer'] === 'function') { | 43 | + if (typeof window != 'undefined' && typeof window['FileTransfer'] === 'function') { |
| 42 | return ENV_CORDOVA; | 44 | return ENV_CORDOVA; |
| 43 | } | 45 | } |
| 46 | + if (typeof process != 'undefined' && typeof process === 'object') { | ||
| 47 | + return ENV_NODE; | ||
| 48 | + } | ||
| 44 | 49 | ||
| 45 | return ENV_UNKNOWN; | 50 | return ENV_UNKNOWN; |
| 46 | } | 51 | } |
| ... | @@ -55,11 +60,13 @@ export class ServiceLocator { | ... | @@ -55,11 +60,13 @@ export class ServiceLocator { |
| 55 | if (environment === ENV_ELECTRON) { | 60 | if (environment === ENV_ELECTRON) { |
| 56 | return new ElectronFileHandler(window['require']('electron').ipcRenderer); | 61 | return new ElectronFileHandler(window['require']('electron').ipcRenderer); |
| 57 | } | 62 | } |
| 58 | - | ||
| 59 | if (environment === ENV_CORDOVA) { | 63 | if (environment === ENV_CORDOVA) { |
| 60 | return new CordovaFileHandler(); | 64 | return new CordovaFileHandler(); |
| 61 | } | 65 | } |
| 62 | - | 66 | + if (environment === ENV_NODE) { |
| 67 | + return new NodeFileHandler(); | ||
| 68 | + } | ||
| 69 | + | ||
| 63 | return null; | 70 | return null; |
| 64 | } | 71 | } |
| 65 | 72 | ... | ... |
-
Please register or login to post a comment