Migrate app to TypeScript (#1637)

* Initial setup and migrated src/common

* WIP

* WIP

* WIP

* Main module basically finished

* Renderer process migrated

* Added CI step and some fixes

* Fixed remainder of issues and added proper ESLint config

* Fixed a couple issues

* Progress!

* Some more fixes

* Fixed a test

* Fix build step

* PR feedback
This commit is contained in:
Devin Binnie
2021-06-28 09:51:23 -04:00
committed by GitHub
parent 422673a740
commit 1b3d0eac8f
115 changed files with 16246 additions and 9921 deletions

View File

@@ -0,0 +1,77 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {shell, Notification} from 'electron';
import log from 'electron-log';
import {MentionData} from 'types/notification';
import {ServerFromURL} from 'types/utils';
import {PLAY_SOUND} from 'common/communication';
import * as windowManager from '../windows/windowManager';
import {Mention} from './Mention';
import {DownloadNotification} from './Download';
const currentNotifications = new Map();
export function displayMention(title: string, body: string, channel: {id: string}, teamId: string, silent: boolean, webcontents: Electron.WebContents, data: MentionData) {
if (!Notification.isSupported()) {
log.error('notification not supported');
return;
}
const serverName = windowManager.getServerNameByWebContentsId(webcontents.id);
const options = {
title: `${serverName}: ${title}`,
body,
silent,
data,
};
const mention = new Mention(options, channel, teamId);
const mentionKey = `${mention.teamId}:${mention.channel.id}`;
mention.on('show', () => {
// On Windows, manually dismiss notifications from the same channel and only show the latest one
if (process.platform === 'win32') {
if (currentNotifications.has(mentionKey)) {
log.info(`close ${mentionKey}`);
currentNotifications.get(mentionKey).close();
currentNotifications.delete(mentionKey);
}
currentNotifications.set(mentionKey, mention);
}
const notificationSound = mention.getNotificationSound();
if (notificationSound) {
windowManager.sendToRenderer(PLAY_SOUND, notificationSound);
}
windowManager.flashFrame(true);
});
mention.on('click', () => {
if (serverName) {
windowManager.switchServer(serverName);
webcontents.send('notification-clicked', {channel, teamId});
}
});
mention.show();
}
export function displayDownloadCompleted(fileName: string, path: string, serverInfo: ServerFromURL) {
if (!Notification.isSupported()) {
log.error('notification not supported');
return;
}
const download = new DownloadNotification(fileName, serverInfo);
download.on('show', () => {
windowManager.flashFrame(true);
});
download.on('click', () => {
shell.showItemInFolder(path.normalize());
});
download.show();
}