Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 45fb7d9

Browse files
authoredMay 3, 2020
fix: only try to open links if non-null url (#405)
1 parent 3cd4238 commit 45fb7d9

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed
 

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"prettier": "prettier --single-quote --trailing-comma es5 --write 'src/**/*.{js,ts,tsx}'",
1414
"jest": "jest",
1515
"test": "yarn jest",
16-
"start": "electron . –enable-logging"
16+
"start": "electron . -–enable-logging"
1717
},
1818
"repository": {
1919
"type": "git",

‎src/js/components/notification.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,11 @@ export const NotificationItem: React.FC<IProps> = (props) => {
7979
};
8080

8181
const openBrowser = () => {
82-
const url = generateGitHubWebUrl(props.notification.subject.url);
83-
shell.openExternal(url);
82+
// Some Notification types from GitHub are missing urls in their subjects.
83+
if (props.notification.subject.url) {
84+
const url = generateGitHubWebUrl(props.notification.subject.url);
85+
shell.openExternal(url);
86+
}
8487
};
8588

8689
const markAsRead = () => {

‎src/js/utils/helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Constants from './constants';
77
import { loginUser } from '../actions';
88
import { AuthState } from '../../types/reducers';
99

10-
export function getEnterpriseAccountToken(hostname, accounts) {
10+
export function getEnterpriseAccountToken(hostname, accounts): string {
1111
return accounts.find((obj) => obj.hostname === hostname).token;
1212
}
1313

@@ -18,12 +18,12 @@ export function generateGitHubAPIUrl(hostname) {
1818
: `https://api.${hostname}/`;
1919
}
2020

21-
export function generateGitHubWebUrl(url) {
21+
export function generateGitHubWebUrl(url: string) {
2222
const { hostname } = parse(url);
2323
const isEnterprise =
2424
hostname !== `api.${Constants.DEFAULT_AUTH_OPTIONS.hostname}`;
2525

26-
let newUrl = isEnterprise
26+
let newUrl: string = isEnterprise
2727
? url.replace(`${hostname}/api/v3/repos`, hostname)
2828
: url.replace('api.github.com/repos', 'github.com');
2929

‎src/js/utils/notifications.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ const { remote } = require('electron');
22

33
import { generateGitHubWebUrl } from '../utils/helpers';
44
import { reOpenWindow, openExternalLink } from '../utils/comms';
5-
import { SubjectType } from '../../types/github';
5+
import { Notification } from '../../types/github';
66
import { SettingsState } from '../../types/reducers';
77

88
export default {
9-
setup(notifications, notificationsCount, settings: SettingsState) {
9+
setup(
10+
notifications: Notification[],
11+
notificationsCount,
12+
settings: SettingsState
13+
) {
1014
// If there are no new notifications just stop there
1115
if (!notificationsCount) {
1216
return;
@@ -21,11 +25,15 @@ export default {
2125
}
2226
},
2327

24-
raiseNativeNotification(notifications, count) {
25-
let title, body, icon, notificationUrl;
28+
raiseNativeNotification(notifications, count: number) {
29+
let title: string;
30+
let body: string;
31+
let notificationUrl: string | null;
2632

2733
if (count === 1) {
28-
const notification = notifications.find((obj) => obj.length > 0)[0];
34+
const notification: Notification = notifications.find(
35+
(obj) => obj.length > 0
36+
)[0];
2937
title = `Gitify - ${notification.repository.full_name}`;
3038
body = notification.subject.title;
3139
notificationUrl = notification.subject.url;
@@ -42,10 +50,13 @@ export default {
4250
nativeNotification.onclick = function () {
4351
if (count === 1) {
4452
const appWindow = remote.getCurrentWindow();
45-
const url = generateGitHubWebUrl(notificationUrl);
46-
4753
appWindow.hide();
48-
openExternalLink(url);
54+
55+
// Some Notification types from GitHub are missing urls in their subjects.
56+
if (notificationUrl) {
57+
const url = generateGitHubWebUrl(notificationUrl);
58+
openExternalLink(url);
59+
}
4960
} else {
5061
reOpenWindow();
5162
}

0 commit comments

Comments
 (0)
Please sign in to comment.