Skip to content

Commit 729c01a

Browse files
committed
feat: re-adding in-app messages
Signed-off-by: Pawel Psztyc <[email protected]>
1 parent 340f2db commit 729c01a

File tree

8 files changed

+138
-28
lines changed

8 files changed

+138
-28
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"cSpell.words": [
33
"Renderable",
4+
"actionurl",
45
"advancedrestclient",
56
"appresources",
67
"arccontextmenu",

package-lock.json

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

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@advanced-rest-client/arc-icons": "^3.2.2",
4242
"@advanced-rest-client/arc-ie": "^1.0.3",
4343
"@advanced-rest-client/arc-menu": "^4.0.3",
44+
"@advanced-rest-client/arc-messages": "^0.1.0",
4445
"@advanced-rest-client/arc-models": "^4.2.8",
4546
"@advanced-rest-client/arc-request-ui": "^0.1.9",
4647
"@advanced-rest-client/arc-settings": "^0.1.2",
@@ -52,7 +53,7 @@
5253
"@advanced-rest-client/request-engine": "^0.1.10",
5354
"@advanced-rest-client/requests-list": "^0.1.8",
5455
"@anypoint-web-components/anypoint-button": "^1.1.1",
55-
"@anypoint-web-components/anypoint-dialog": "^0.1.6",
56+
"@anypoint-web-components/anypoint-dialog": "^0.1.7",
5657
"@anypoint-web-components/anypoint-item": "^1.1.0",
5758
"@anypoint-web-components/anypoint-switch": "^0.1.4",
5859
"@open-wc/dedupe-mixin": "^1.3.0",
@@ -425,7 +426,11 @@
425426
"@advanced-rest-client/exchange-search-panel/*.js",
426427
"@advanced-rest-client/exchange-search-panel/*.d.ts",
427428
"@advanced-rest-client/exchange-search-panel/src/*.js",
428-
"@advanced-rest-client/exchange-search-panel/src/*.d.ts"
429+
"@advanced-rest-client/exchange-search-panel/src/*.d.ts",
430+
"@advanced-rest-client/arc-messages/*.js",
431+
"@advanced-rest-client/arc-messages/*.d.ts",
432+
"@advanced-rest-client/arc-messages/src/*.js",
433+
"@advanced-rest-client/arc-messages/src/*.d.ts"
429434
]
430435
}
431436
}

src/app/scripts/arc/AdvancedRestClientApplication.js

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { html } from '../../../../web_modules/lit-html/lit-html.js';
55
import { MonacoLoader } from '../../../../web_modules/@advanced-rest-client/monaco-support/index.js';
66
import { ArcNavigationEventTypes, ProjectActions, ConfigEventTypes, DataImportEventTypes, WorkspaceEvents, ImportEvents, WorkspaceEventTypes, ArcNavigationEvents, RestApiEventTypes } from '../../../../web_modules/@advanced-rest-client/arc-events/index.js';
77
import { ArcModelEvents, ArcModelEventTypes, ImportFactory, ImportNormalize, isSingleRequest } from '../../../../web_modules/@advanced-rest-client/arc-models/index.js';
8+
import { ArcMessagingService } from '../../../../web_modules/@advanced-rest-client/arc-messages/index.js';
89
import { ModulesRegistry, RequestCookies } from '../../../../web_modules/@advanced-rest-client/request-engine/index.js';
910
import { classMap } from '../../../../web_modules/lit-html/directives/class-map.js';
1011
import { styleMap } from '../../../../web_modules/lit-html/directives/style-map.js';
@@ -43,6 +44,7 @@ import '../../../../web_modules/@api-components/api-navigation/api-navigation.js
4344
import '../../../../web_modules/@advanced-rest-client/exchange-search-panel/exchange-search-panel.js';
4445
// import '../../../../web_modules/@api-components/api-request-panel/api-request-panel.js';
4546
// import '../../../../web_modules/@api-components/api-documentation/api-documentation.js';
47+
import '../../../../web_modules/@advanced-rest-client/arc-messages/arc-messages-dialog.js';
4648
import { Request } from './Request.js';
4749
import { ContextMenu } from '../context-menu/ContextMenu.js';
4850
import { ContextMenuStyles } from '../context-menu/ContextMenu.styles.js';
@@ -145,6 +147,9 @@ const arcNavigationTemplate = Symbol('arcNavigationTemplate');
145147
const exchangeSearchTemplate = Symbol('exchangeSearchTemplate');
146148
const exchangeSelectionHandler = Symbol('exchangeSelectionHandler');
147149
const themeActivateHandler = Symbol('themeActivateHandler');
150+
const unreadMessagesTemplate = Symbol('unreadMessagesTemplate');
151+
const appMessagesDialogTemplate = Symbol('appMessagesDialogTemplate');
152+
const openMessagesHandler = Symbol('openMessagesHandler');
148153

149154
/**
150155
* A routes that does not go through the router and should not be remembered in the history.
@@ -268,6 +273,11 @@ export class AdvancedRestClientApplication extends ApplicationPage {
268273

269274
ga = new GoogleAnalytics();
270275

276+
/**
277+
* A service that requests fro the data from the ARC server fore new messages.
278+
*/
279+
appMessages = new ArcMessagingService('electron');
280+
271281
/**
272282
* @returns {ArcRequestWorkspaceElement}
273283
*/
@@ -323,6 +333,7 @@ export class AdvancedRestClientApplication extends ApplicationPage {
323333
'workspaceSendButton', 'workspaceProgressInfo', 'workspaceBodyEditor', 'workspaceAutoEncode',
324334
'navigationWidth',
325335
'requestDetailsOpened', 'requestMetaOpened', 'metaRequestId', 'metaRequestType',
336+
'unreadAppMessages', 'applicationMessages',
326337
);
327338

328339
/**
@@ -421,6 +432,11 @@ export class AdvancedRestClientApplication extends ApplicationPage {
421432
this.requestMetaOpened = false;
422433
this.metaRequestId = undefined;
423434
this.metaRequestType = undefined;
435+
436+
/**
437+
* @type {number} The number of unread messages in the application.
438+
*/
439+
this.unreadAppMessages = 0;
424440
}
425441

426442
async initialize() {
@@ -455,6 +471,7 @@ export class AdvancedRestClientApplication extends ApplicationPage {
455471
await this.afterInitialization();
456472
await this.loadMonaco();
457473
this.initializing = false;
474+
this.unreadAppMessages = await this.appMessages.run();
458475
}
459476

460477
/**
@@ -518,6 +535,7 @@ export class AdvancedRestClientApplication extends ApplicationPage {
518535
this.listType = cnf.view.listType;
519536
}
520537
}
538+
521539
if (cnf.requestEditor) {
522540
if (typeof cnf.requestEditor.sendButton === 'boolean') {
523541
this.workspaceSendButton = cnf.requestEditor.sendButton;
@@ -532,6 +550,13 @@ export class AdvancedRestClientApplication extends ApplicationPage {
532550
this.workspaceAutoEncode = cnf.requestEditor.autoEncode;
533551
}
534552
}
553+
554+
if (cnf.updater) {
555+
const { channel } = cnf.updater;
556+
if (typeof channel === 'string') {
557+
this.appMessages.channel = channel;
558+
}
559+
}
535560
}
536561

537562
/**
@@ -841,6 +866,7 @@ export class AdvancedRestClientApplication extends ApplicationPage {
841866
case 'export-workspace': this.exportWorkspace(); break;
842867
case 'login-external-webservice': this.workspaceElement.openWebUrlInput(); break;
843868
case 'open-workspace-details': this.workspaceElement.openWorkspaceDetails(); break;
869+
case 'open-messages': this.openAppMessages(); break;
844870
default:
845871
this.logger.warn(`Unhandled IO command ${action}`);
846872
}
@@ -1306,6 +1332,20 @@ export class AdvancedRestClientApplication extends ApplicationPage {
13061332
this.compatibility = e.detail === ThemeManager.anypointTheme;
13071333
}
13081334

1335+
[openMessagesHandler]() {
1336+
this.openAppMessages();
1337+
}
1338+
1339+
async openAppMessages() {
1340+
if (!this.applicationMessages) {
1341+
this.applicationMessages = await this.appMessages.readMessages();
1342+
}
1343+
const dialog = document.querySelector('arc-messages-dialog');
1344+
dialog.opened = true;
1345+
await this.appMessages.markAllRead();
1346+
this.unreadAppMessages = 0;
1347+
}
1348+
13091349
appTemplate() {
13101350
const { initializing } = this;
13111351
if (initializing) {
@@ -1320,6 +1360,7 @@ export class AdvancedRestClientApplication extends ApplicationPage {
13201360
${this[navigationTemplate]()}
13211361
${this[pageTemplate](this.route)}
13221362
</div>
1363+
${this[appMessagesDialogTemplate]()}
13231364
`;
13241365
}
13251366

@@ -1345,15 +1386,30 @@ export class AdvancedRestClientApplication extends ApplicationPage {
13451386
<header>
13461387
${isWorkspace ? '' :
13471388
html`
1348-
<anypoint-icon-button title="Back to the request workspace" @click="${this[mainBackHandler]}">
1389+
<anypoint-icon-button title="Back to the request workspace" @click="${this[mainBackHandler]}" class="header-action-button">
13491390
<arc-icon icon="arrowBack"></arc-icon>
13501391
</anypoint-icon-button>`}
13511392
API Client
13521393
<span class="spacer"></span>
1394+
${this[unreadMessagesTemplate]()}
13531395
${this[environmentTemplate]()}
13541396
</header>`;
13551397
}
13561398

1399+
/**
1400+
* @returns {TemplateResult|string} The template for the unread notifications icon button
1401+
*/
1402+
[unreadMessagesTemplate]() {
1403+
const { unreadAppMessages } = this;
1404+
if (!unreadAppMessages) {
1405+
return '';
1406+
}
1407+
return html`
1408+
<anypoint-icon-button title="You have unread messages" class="header-action-button" @click="${this[openMessagesHandler]}">
1409+
<arc-icon icon="notificationsActive"></arc-icon>
1410+
</anypoint-icon-button>`;
1411+
}
1412+
13571413
/**
13581414
* @returns {TemplateResult|string} The template for the environment selector and the overlay.
13591415
*/
@@ -1726,4 +1782,16 @@ export class AdvancedRestClientApplication extends ApplicationPage {
17261782
></exchange-search-panel>
17271783
`;
17281784
}
1785+
1786+
/**
1787+
* @returns {TemplateResult} The template for the dialog with application messages
1788+
*/
1789+
[appMessagesDialogTemplate]() {
1790+
return html`
1791+
<arc-messages-dialog
1792+
.messages="${this.applicationMessages}"
1793+
?compatibility="${this.compatibility}"
1794+
modal
1795+
></arc-messages-dialog>`;
1796+
}
17291797
}

src/app/styles/common.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ header {
6666
box-sizing: border-box;
6767
}
6868

69+
.header-action-button {
70+
margin-right: 8px;
71+
}
72+
73+
.header-action-button arc-icon {
74+
color: var(--arc-toolbar-color);
75+
}
76+
6977
main {
7078
flex: 1;
7179
display: flex;

src/menus/darwin.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@
351351
"label": "Frequently Asked Questions",
352352
"command": "application:open-faq"
353353
},
354+
{
355+
"label": "What's new",
356+
"command": "application:open-messages"
357+
},
354358
{
355359
"type": "separator"
356360
},

src/menus/linux.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@
324324
"label": "Frequently Asked Questions",
325325
"command": "application:open-faq"
326326
},
327+
{
328+
"label": "What's new",
329+
"command": "application:open-messages"
330+
},
327331
{
328332
"type": "separator"
329333
},

src/menus/win.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@
324324
"label": "Frequently Asked Questions",
325325
"command": "application:open-faq"
326326
},
327+
{
328+
"label": "What's new",
329+
"command": "application:open-messages"
330+
},
327331
{
328332
"type": "separator"
329333
},

0 commit comments

Comments
 (0)