Skip to content

Commit

Permalink
feat(client): add App#getPlatform
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Nov 28, 2018
1 parent 47e144d commit 70b66b0
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 6 deletions.
18 changes: 17 additions & 1 deletion client/src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,13 +1099,29 @@ export class App extends Component {
this.openExternalUrl(options);
}

if (action === 'get-platform') {
return this.getPlatform();
}

const tab = this.tabRef.current;

return tab.triggerAction(action, options);
}

openExternalUrl(options) {
this.props.globals.backend.send('external:open-url', options);
const { globals } = this.props;

const { backend } = globals;

backend.send('external:open-url', options);
}

getPlatform() {
const { globals } = this.props;

const { backend } = globals;

return backend.getPlatform();
}

quit() {
Expand Down
21 changes: 21 additions & 0 deletions client/src/app/__tests__/AppSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,27 @@ describe('<App>', function() {
expect(sendSpy).to.have.been.calledWith('external:open-url', options);
});


it('#getPlatform', function() {

// given
const backend = new Backend({
getPlatform: () => 'darwin'
});

const { app } = createApp({
globals: {
backend
}
});

// when
const platform = app.getPlatform();

// then
expect(platform).to.equal('darwin');
});

});


Expand Down
7 changes: 6 additions & 1 deletion client/src/remote/Backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const ids = new Ids();
*/
export default class Backend {

constructor(ipcRenderer) {
constructor(ipcRenderer, process) {
this.ipcRenderer = ipcRenderer;
this.process = process;
}

/**
Expand Down Expand Up @@ -77,4 +78,8 @@ export default class Backend {
return this.send('menu:register', name, options);
}

getPlatform() {
return this.process.platform;
}

}
22 changes: 19 additions & 3 deletions client/src/remote/__tests__/BackendSpec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import Backend from '../Backend';

import {
IpcRenderer
IpcRenderer,
Process
} from './mocks';

describe('backend', function() {

let backend,
ipcRenderer;
ipcRenderer,
process;

beforeEach(function() {
ipcRenderer = new IpcRenderer();
process = new Process();

backend = new Backend(ipcRenderer);
backend = new Backend(ipcRenderer, process);
});


Expand Down Expand Up @@ -44,4 +47,17 @@ describe('backend', function() {
expect(result).not.to.exist;
});


it('should return platform darwin', function() {

// given
process.setPlatform('darwin');

// when
const platform = backend.getPlatform();

// then
expect(platform).to.equal('darwin');
});

});
10 changes: 10 additions & 0 deletions client/src/remote/__tests__/mocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ export class IpcRenderer {
once(event, callback) {
this.listener = callback;
}
}

export class Process {
constructor() {
this.platform = null;
}

setPlatform(platform) {
this.platform = platform;
}
}
4 changes: 3 additions & 1 deletion client/src/remote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import Workspace from './Workspace';

export const ipcRenderer = electronRequire('ipcRenderer');

export const backend = new Backend(ipcRenderer);
export const { process } = electronRequire('remote');

export const backend = new Backend(ipcRenderer, process);

export const fileSystem = new FileSystem(backend);

Expand Down

0 comments on commit 70b66b0

Please sign in to comment.