diff --git a/package.json b/package.json index b1a5c7e89..46d7f7de9 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "prettier": "prettier --single-quote --trailing-comma es5 --write 'src/**/*.{js,ts,tsx}'", "jest": "jest", "test": "yarn jest", - "start": "electron . –enable-logging" + "start": "electron . -–enable-logging" }, "repository": { "type": "git", diff --git a/src/js/components/notification.tsx b/src/js/components/notification.tsx index f6643a9d9..552875c80 100644 --- a/src/js/components/notification.tsx +++ b/src/js/components/notification.tsx @@ -79,8 +79,11 @@ export const NotificationItem: React.FC = (props) => { }; const openBrowser = () => { - const url = generateGitHubWebUrl(props.notification.subject.url); - shell.openExternal(url); + // Some Notification types from GitHub are missing urls in their subjects. + if (props.notification.subject.url) { + const url = generateGitHubWebUrl(props.notification.subject.url); + shell.openExternal(url); + } }; const markAsRead = () => { diff --git a/src/js/utils/helpers.ts b/src/js/utils/helpers.ts index ca4fd13d2..fac12063e 100644 --- a/src/js/utils/helpers.ts +++ b/src/js/utils/helpers.ts @@ -7,7 +7,7 @@ import Constants from './constants'; import { loginUser } from '../actions'; import { AuthState } from '../../types/reducers'; -export function getEnterpriseAccountToken(hostname, accounts) { +export function getEnterpriseAccountToken(hostname, accounts): string { return accounts.find((obj) => obj.hostname === hostname).token; } @@ -18,12 +18,12 @@ export function generateGitHubAPIUrl(hostname) { : `https://api.${hostname}/`; } -export function generateGitHubWebUrl(url) { +export function generateGitHubWebUrl(url: string) { const { hostname } = parse(url); const isEnterprise = hostname !== `api.${Constants.DEFAULT_AUTH_OPTIONS.hostname}`; - let newUrl = isEnterprise + let newUrl: string = isEnterprise ? url.replace(`${hostname}/api/v3/repos`, hostname) : url.replace('api.github.com/repos', 'github.com'); diff --git a/src/js/utils/notifications.ts b/src/js/utils/notifications.ts index a41abc4ad..b8f758197 100644 --- a/src/js/utils/notifications.ts +++ b/src/js/utils/notifications.ts @@ -2,11 +2,15 @@ const { remote } = require('electron'); import { generateGitHubWebUrl } from '../utils/helpers'; import { reOpenWindow, openExternalLink } from '../utils/comms'; -import { SubjectType } from '../../types/github'; +import { Notification } from '../../types/github'; import { SettingsState } from '../../types/reducers'; export default { - setup(notifications, notificationsCount, settings: SettingsState) { + setup( + notifications: Notification[], + notificationsCount, + settings: SettingsState + ) { // If there are no new notifications just stop there if (!notificationsCount) { return; @@ -21,11 +25,15 @@ export default { } }, - raiseNativeNotification(notifications, count) { - let title, body, icon, notificationUrl; + raiseNativeNotification(notifications, count: number) { + let title: string; + let body: string; + let notificationUrl: string | null; if (count === 1) { - const notification = notifications.find((obj) => obj.length > 0)[0]; + const notification: Notification = notifications.find( + (obj) => obj.length > 0 + )[0]; title = `Gitify - ${notification.repository.full_name}`; body = notification.subject.title; notificationUrl = notification.subject.url; @@ -42,10 +50,13 @@ export default { nativeNotification.onclick = function () { if (count === 1) { const appWindow = remote.getCurrentWindow(); - const url = generateGitHubWebUrl(notificationUrl); - appWindow.hide(); - openExternalLink(url); + + // Some Notification types from GitHub are missing urls in their subjects. + if (notificationUrl) { + const url = generateGitHubWebUrl(notificationUrl); + openExternalLink(url); + } } else { reOpenWindow(); }