Skip to content

Commit

Permalink
feat: set frameworkPath how config
Browse files Browse the repository at this point in the history
BREAKING CHANGE: log now is set in Config removed of Options of the VPN
  • Loading branch information
ramonornela committed May 11, 2020
1 parent 09e1bef commit 5786ae7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ export interface Options {
server: string;
remoteId: string;
localId?: string;
}

export interface Config {
log?: any;
frameworkPath?: string;
}
40 changes: 24 additions & 16 deletions src/vpn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Options } from './interfaces';
import { Config, Options } from './interfaces';

const path = require('path'); // eslint-disable-line

Expand All @@ -7,33 +7,41 @@ export const $ = require('@ammora/nodobjc'); // eslint-disable-line
export class Bridge {
private vpnManager: any;

private readonly options: any;
private readonly config?: Config = {};

constructor(options: Options) {
const optionsDefault = {
log: console
};

this.options = { ...optionsDefault, ...options };
constructor(options: Options, config?: Config) {
this.config = config;

this.importFramework();
this.create(options);
}

private get log(): any {
return this.options.log;
let log = this.config?.log;

if (log === null || log === undefined) {
log = console;
}

if (typeof log.info !== 'function') {
throw new Error('Log invalid');
}

return log;
}

private importFramework(): void {
$.import(path.join(__dirname, '..', 'VPNManager.framework'));
let frameworkPath = this.config?.frameworkPath;

if (frameworkPath === null || frameworkPath === undefined) {
frameworkPath = path.join(__dirname, '..');
}

$.import(path.join(frameworkPath, 'VPNManager.framework'));

this.log.info('VPNManager Framework import');
}

/* get isConnected(): boolean {
return this.vpnManager('isConnected');
} */

get manager(): any {
return this.vpnManager;
}
Expand All @@ -55,5 +63,5 @@ export class Bridge {
}
}

export default (options: Options): Bridge =>
new Bridge(options);
export default (options: Options, config?: Config): Bridge =>
new Bridge(options, config);

0 comments on commit 5786ae7

Please sign in to comment.