Skip to content

Commit 24bb73d

Browse files
committed
Merge branch 'feature/client-certificates' into develop
2 parents 4f6d198 + 814a0cd commit 24bb73d

File tree

11 files changed

+985
-486
lines changed

11 files changed

+985
-486
lines changed

app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class ArcInit {
242242
*/
243243
commandHandler(e, action, ...args) {
244244
// console.info('Renderer command handled: ', action);
245-
const app = this.app;
245+
const { app } = this;
246246
switch (action) {
247247
case 'show-settings': app.openSettings(); break;
248248
case 'about': app.openAbout(); break;
@@ -267,6 +267,7 @@ class ArcInit {
267267
case 'open-onboarding': app.openOnboarding(); break;
268268
case 'open-workspace-details': app.openWorkspaceDetails(); break;
269269
case 'export-workspace': this.exportWorkspace(); break;
270+
case 'open-client-certificates': app.openClientCertificates(); break;
270271
default:
271272
console.warn('Unknown command', action, args);
272273
}

menus/darwin.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@
265265
"label": "Cookie manager",
266266
"command": "application:open-cookie-manager"
267267
},
268+
{
269+
"label": "Client certificates",
270+
"command": "application:open-client-certificates"
271+
},
268272
{
269273
"type": "separator"
270274
},

menus/linux.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@
214214
"label": "Cookie manager",
215215
"command": "application:open-cookie-manager"
216216
},
217+
{
218+
"label": "Client certificates",
219+
"command": "application:open-client-certificates"
220+
},
217221
{
218222
"type": "separator"
219223
},

menus/win.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@
220220
"label": "Cookie manager",
221221
"command": "application:open-cookie-manager"
222222
},
223+
{
224+
"label": "Client certificates",
225+
"command": "application:open-client-certificates"
226+
},
223227
{
224228
"type": "separator"
225229
},

package-lock.json

Lines changed: 861 additions & 420 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@
4040
"@advanced-rest-client/arc-icons": "^3.0.5",
4141
"@advanced-rest-client/arc-info-messages": "^3.0.0",
4242
"@advanced-rest-client/arc-onboarding": "^3.0.1",
43+
"@advanced-rest-client/client-certificates-panel": "^1.0.4",
4344
"@advanced-rest-client/eslint-config": "^1.1.4",
4445
"@advanced-rest-client/exchange-search-panel": "^3.0.3",
4546
"@advanced-rest-client/host-rules-editor": "^3.0.0",
4647
"@advanced-rest-client/rest-apis-list-panel": "^3.0.0",
4748
"@advanced-rest-client/themes-panel": "^3.0.0",
49+
"@anypoint-web-components/anypoint-dialog": "^0.1.1",
4850
"@api-components/api-candidates-dialog": "^3.0.0",
4951
"@api-components/api-documentation": "^4.0.4",
5052
"@api-components/api-navigation": "^4.0.2",
@@ -286,7 +288,12 @@
286288
"@anypoint-web-components/anypoint-item/anypoint-item.js",
287289
"lit-html/directives/repeat.js",
288290
"@advanced-rest-client/arc-onboarding/arc-onboarding.js",
289-
"@advanced-rest-client/rest-apis-list-panel/rest-apis-list-panel.js"
291+
"@advanced-rest-client/rest-apis-list-panel/rest-apis-list-panel.js",
292+
"@advanced-rest-client/client-certificates-panel/client-certificates-panel.js",
293+
"@advanced-rest-client/client-certificates-panel/certificate-import.js",
294+
"@advanced-rest-client/arc-models/client-certificate-model.js",
295+
"@anypoint-web-components/anypoint-dialog/anypoint-dialog.js",
296+
"@anypoint-web-components/anypoint-dialog/anypoint-dialog-scrollable.js"
290297
]
291298
}
292299
}

scripts/main/app-prompts.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,37 @@ class AppPrompts {
99
* Listens for the application events.
1010
*/
1111
listen() {
12-
ipcMain.on('save-dialog', this._saveDialogHandler.bind(this));
12+
ipcMain.handle('save-dialog', this._saveDialogHandler.bind(this));
1313
}
1414
/**
1515
* Hasnles save action dialog. Opens "save as..." dialog and returns
1616
* the result to the app.
1717
*
18-
* This method emmits `saved-file` event to the sender window with
19-
* file location as it's only argument. The argument is `undefined`
20-
* when the user cancels the action.
21-
*
2218
* @param {Event} e Event emitted by the BrowserWindow
2319
* @param {Object} args Prompt dialog options:
2420
* - file {String} - File name to suggest to the user.
21+
* @return {Promise}
2522
*/
26-
_saveDialogHandler(e, args) {
23+
_saveDialogHandler(e, args={}) {
2724
log.debug('Save dialog requested', args);
28-
args = args || {};
2925
const options = {
3026
title: 'Save to file'
3127
};
3228
if (args.file) {
3329
options.defaultPath = args.file;
3430
}
35-
dialog.showSaveDialog(options, function(filename) {
36-
e.sender.send('saved-file', filename);
37-
});
31+
return dialog.showSaveDialog(options);
3832
}
3933
/**
4034
* A dialog that renders error message about missing workspace file.
4135
* @param {String} file Requested workspace file location.
36+
* @return {Promise}
4237
*/
43-
static workspaceMissing(file) {
38+
static async workspaceMissing(file) {
4439
let message = 'Workspace file cannot be located. Probably it was deleted or';
4540
message += ' renamed.\n\n';
4641
message += 'Requested file: ' + file;
47-
dialog.showMessageBox({
42+
return await dialog.showMessageBox({
4843
type: 'error',
4944
message
5045
});

scripts/main/arc-environment.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ class ArcEnvironment {
4141
ipcMain.on('open-external-url', this._externalUrlHandler.bind(this));
4242
}
4343

44-
loadEnvironment() {
44+
async loadEnvironment() {
4545
log.debug('Loading user configuration.');
46-
return this.config.load()
47-
.then((settings) => {
48-
log.debug('User configuration ready.');
49-
this._postConfig(settings);
50-
});
46+
const settings = await this.config.load();
47+
log.debug('User configuration ready.');
48+
this._postConfig(settings);
5149
}
5250

5351
registerHandlers() {

scripts/renderer/filesystem-proxy.js

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,72 +15,64 @@ const path = require('path');
1515
class FilesystemProxy {
1616
constructor() {
1717
this._exportHandler = this._exportHandler.bind(this);
18-
this._fileSavedHandler = this._fileSavedHandler.bind(this);
1918
}
2019

2120
listen() {
2221
window.addEventListener('file-data-save', this._exportHandler);
23-
ipc.on('saved-file', this._fileSavedHandler);
2422
}
2523

2624
unlisten() {
2725
window.removeEventListener('file-data-save', this._exportHandler);
28-
ipc.removeListener('saved-file', this._fileSavedHandler);
29-
}
30-
31-
_clear() {
32-
this.lastType = undefined;
33-
this.lastContent = undefined;
34-
this.lastResolve = undefined;
35-
this.lastReject = undefined;
3626
}
3727

3828
_exportHandler(e) {
3929
if (e.defaultPrevented) {
4030
return;
4131
}
4232
e.preventDefault();
43-
const { content, file, options } = e.detail;
44-
e.detail.result = this.exportFileData(content, options && options.contentType, file);
33+
const { content, file, options={} } = e.detail;
34+
e.detail.result = this.exportFileData(content, options.contentType, file);
4535
}
46-
47-
exportFileData(content, mime, file) {
48-
ipc.send('save-dialog', {
36+
/**
37+
* Requests a save file dialog and saves the data to selected path if not cancelled.
38+
* This does nothing when dialog is canceled.
39+
*
40+
* @param {String|Object|Buffer} content Data to write
41+
* @param {String=} mime Content media type. Currently only `application/json` is
42+
* supported when the `content` is an object or an array.
43+
* @param {String=} file Suggested file name
44+
* @return {Promise}
45+
*/
46+
async exportFileData(content, mime, file) {
47+
const opts = {
4948
file
50-
});
51-
this.lastContent = content;
52-
this.lastType = mime;
53-
new Promise((resolve, reject) => {
54-
this.lastResolve = resolve;
55-
this.lastReject = reject;
56-
});
57-
}
58-
59-
_fileSavedHandler(e, selectedPath) {
60-
if (!selectedPath) {
61-
this.lastResolve();
62-
this._clear();
49+
};
50+
const result = await ipc.invoke('save-dialog', opts)
51+
const { filePath, canceled } = result;
52+
if (canceled) {
6353
return;
6454
}
65-
return this._writeContent(selectedPath)
66-
.then(() => this.lastResolve())
67-
.catch((cause) => this.lastReject(cause))
68-
.then(() => this._clear());
55+
await this._writeContent(filePath, content, mime);
6956
}
70-
71-
_writeContent(path) {
72-
let data = this.lastContent;
73-
if (typeof data !== 'string') {
74-
data = this._prepareData(data);
57+
/**
58+
* Writes content to a file
59+
* @param {String} path Absolute path to a file
60+
* @param {String|Object|Buffer} content Data to be written
61+
* @param {String=} mime Content media type.
62+
* @return {Promise}
63+
*/
64+
_writeContent(path, content, mime) {
65+
if (typeof content !== 'string') {
66+
content = this._prepareData(content, mime);
7567
}
76-
return fs.writeFile(path, data, 'utf8');
68+
return fs.writeFile(path, content, 'utf8');
7769
}
7870

79-
_prepareData(data) {
80-
switch (this.lastType) {
71+
_prepareData(data, mime) {
72+
switch (mime) {
8173
case 'application/json': return JSON.stringify(data);
74+
default: return String(data);
8275
}
83-
return String(data);
8476
}
8577
/**
8678
* Allows to read file from user filesystem.

src/arc-electron.js

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import PouchQuickSearch from
88
import marked from '../web_modules/marked/lib/marked.js';
99
import styles from '../web_modules/@advanced-rest-client/arc-app-mixin/AppStyles.js';
1010
import '../web_modules/@api-components/api-candidates-dialog/api-candidates-dialog.js';
11+
import '../web_modules/@advanced-rest-client/arc-models/client-certificate-model.js';
12+
import '../web_modules/@anypoint-web-components/anypoint-dialog/anypoint-dialog.js';
13+
import '../web_modules/@anypoint-web-components/anypoint-dialog/anypoint-dialog-scrollable.js';
14+
import '../web_modules/@advanced-rest-client/client-certificates-panel/certificate-import.js';
1115
import './electron-http-transport/electron-http-transport.js';
1216
import poweredIcon from './poweredby.js';
1317
window.PouchDB = PouchDB;
@@ -32,6 +36,11 @@ class ArcElectron extends ArcAppMixin(LitElement) {
3236
* When true it is rendering API console view.
3337
*/
3438
isApiConsole: { type: Boolean },
39+
/**
40+
* When set the certificates import panel is currently rendered.
41+
* @type {Object}
42+
*/
43+
ccImportOpened: { type: Boolean },
3544
};
3645
}
3746

@@ -46,10 +55,12 @@ class ArcElectron extends ArcAppMixin(LitElement) {
4655
this._exchangeAssetHandler = this._exchangeAssetHandler.bind(this);
4756
this._activeThemeHandler = this._activeThemeHandler.bind(this);
4857
this._apiDataHandler = this._apiDataHandler.bind(this);
58+
this._certCcImportHandler = this._certCcImportHandler.bind(this);
4959
/* global log */
5060
this.log = log;
5161
this.sysVars = process.env;
5262
this.withEncrypt = true;
63+
this.clientCertificateImport = true;
5364
}
5465

5566
connectedCallback() {
@@ -59,6 +70,7 @@ class ArcElectron extends ArcAppMixin(LitElement) {
5970
window.addEventListener('theme-activated', this._activeThemeHandler);
6071
window.addEventListener('api-data-ready', this._apiDataHandler);
6172
this.addEventListener('process-exchange-asset-data', this._exchangeAssetHandler);
73+
window.addEventListener('client-certificate-import', this._certCcImportHandler);
6274
}
6375

6476
disconnectedCallback() {
@@ -67,6 +79,7 @@ class ArcElectron extends ArcAppMixin(LitElement) {
6779
window.removeEventListener('content-copy', this._copyContentHandler);
6880
window.removeEventListener('theme-activated', this._activeThemeHandler);
6981
window.removeEventListener('api-data-ready', this._apiDataHandler);
82+
window.removeEventListener('client-certificate-import', this._certCcImportHandler);
7083
}
7184

7285
_routeDataChanged() {
@@ -109,6 +122,11 @@ class ArcElectron extends ArcAppMixin(LitElement) {
109122
path = 'host-rules-editor/host-rules-editor';
110123
scope = '@advanced-rest-client';
111124
break;
125+
case 'client-certificates':
126+
id = 'client-certificates-panel';
127+
path = 'client-certificates-panel/client-certificates-panel';
128+
scope = '@advanced-rest-client';
129+
break;
112130
}
113131
if (id) {
114132
const cls = window.customElements.get(id);
@@ -577,12 +595,29 @@ class ArcElectron extends ArcAppMixin(LitElement) {
577595
`;
578596
}
579597

598+
/**
599+
* Opens cliet cetrificates panel by setting `page` to `client-certificates`.
600+
*/
601+
openClientCertificates() {
602+
this.page = 'client-certificates';
603+
}
604+
605+
_certCcImportHandler() {
606+
this.ccImportOpened = true;
607+
}
608+
609+
_closeCcImportHandler() {
610+
this.ccImportOpened = false;
611+
}
612+
580613
render() {
581614
return html`
582615
${this.applicationTemplate()}
583616
${this.apiCandidatedViewTemplate()}
617+
${this._ccImportDialogTemplate()}
584618
<arc-onboarding></arc-onboarding>
585-
<paper-toast id="errorToast" duration="5000"></paper-toast>`;
619+
<paper-toast id="errorToast" duration="5000"></paper-toast>
620+
<client-certificate-model></client-certificate-model>`;
586621
}
587622

588623
_pageTemplate() {
@@ -598,6 +633,7 @@ class ArcElectron extends ArcAppMixin(LitElement) {
598633
case 'rest-projects': return this.restApisViewTemplate({ explore: true });
599634
case 'hosts-rules': return this.hostsViewTemplate();
600635
case 'themes-panel': return this.themesViewTemplate();
636+
case 'client-certificates': return this.clientCertificatesTemplate();
601637
default: return super._pageTemplate();
602638
}
603639
}
@@ -829,13 +865,27 @@ class ArcElectron extends ArcAppMixin(LitElement) {
829865
</div>`;
830866
}
831867

832-
apiCandidatedViewTemplate(opts) {
833-
const {
834-
compatibility
835-
} = this;
868+
apiCandidatedViewTemplate(opts={}) {
869+
const { compatibility } = this;
836870
return html`<api-candidates-dialog
837871
?compatibility="${compatibility}"
838872
></api-candidates-dialog>`;
839873
}
874+
875+
clientCertificatesTemplate() {
876+
return html`<client-certificates-panel></client-certificates-panel>`;
877+
}
878+
879+
_ccImportDialogTemplate() {
880+
const { ccImportOpened } = this;
881+
return html`
882+
<anypoint-dialog ?opened="${ccImportOpened}" modal>
883+
<h2>Import a certificate</h2>
884+
<anypoint-dialog-scrollable>
885+
<certificate-import @close="${this._closeCcImportHandler}"></certificate-import>
886+
</anypoint-dialog-scrollable>
887+
</anypoint-dialog>
888+
`;
889+
}
840890
}
841891
window.customElements.define('arc-electron', ArcElectron);

0 commit comments

Comments
 (0)