From 78afd5846e66753c74b6912c61e06cddfa0da754 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Fri, 29 Sep 2023 11:16:29 -0400 Subject: [PATCH] [MM-54591] Use getVersion endpoint to report app name (#2862) (cherry picked from commit 8281bbbb37dcf7ba6f3d3fc4bbe0c1406abbc001) --- src/main/preload/desktopAPI.js | 4 +--- .../DownloadsDropdown/DownloadsDropdownItem.tsx | 11 +++++++++-- .../DownloadsDropdownItemFile.tsx | 5 +++-- .../Update/UpdateAvailable.tsx | 5 +++-- .../Update/UpdateDownloaded.tsx | 5 +++-- .../DownloadsDropdown/Update/UpdateWrapper.tsx | 17 ++++++++++++++--- src/renderer/downloadsDropdown.tsx | 9 +++++++++ src/types/window.ts | 2 -- 8 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/main/preload/desktopAPI.js b/src/main/preload/desktopAPI.js index 583a1240672..0692d9a862c 100644 --- a/src/main/preload/desktopAPI.js +++ b/src/main/preload/desktopAPI.js @@ -4,7 +4,7 @@ 'use strict'; -import {ipcRenderer, contextBridge, app} from 'electron'; +import {ipcRenderer, contextBridge} from 'electron'; import { GET_LANGUAGE_INFORMATION, @@ -110,8 +110,6 @@ contextBridge.exposeInMainWorld('mas', { }); contextBridge.exposeInMainWorld('desktop', { - getAppName: () => app.name, - quit: (reason, stack) => ipcRenderer.send(QUIT, reason, stack), openAppMenu: () => ipcRenderer.send(OPEN_APP_MENU), closeServersDropdown: () => ipcRenderer.send(CLOSE_SERVERS_DROPDOWN), diff --git a/src/renderer/components/DownloadsDropdown/DownloadsDropdownItem.tsx b/src/renderer/components/DownloadsDropdown/DownloadsDropdownItem.tsx index 01865a981cb..c2a1aa52606 100644 --- a/src/renderer/components/DownloadsDropdown/DownloadsDropdownItem.tsx +++ b/src/renderer/components/DownloadsDropdown/DownloadsDropdownItem.tsx @@ -10,17 +10,24 @@ import UpdateWrapper from './Update/UpdateWrapper'; type OwnProps = { activeItem?: DownloadedItem; item: DownloadedItem; + appName: string; } -const DownloadsDropdownItem = ({item, activeItem}: OwnProps) => { +const DownloadsDropdownItem = ({item, activeItem, appName}: OwnProps) => { if (item.type === 'update' && item.state !== 'progressing') { - return ; + return ( + + ); } return ( ); }; diff --git a/src/renderer/components/DownloadsDropdown/DownloadsDropdownItemFile.tsx b/src/renderer/components/DownloadsDropdown/DownloadsDropdownItemFile.tsx index b98cb2d91ee..0c27def88bf 100644 --- a/src/renderer/components/DownloadsDropdown/DownloadsDropdownItemFile.tsx +++ b/src/renderer/components/DownloadsDropdown/DownloadsDropdownItemFile.tsx @@ -15,9 +15,10 @@ import Thumbnail from './Thumbnail'; type OwnProps = { activeItem?: DownloadedItem; item: DownloadedItem; + appName: string; } -const DownloadsDropdownItemFile = ({item, activeItem}: OwnProps) => { +const DownloadsDropdownItemFile = ({item, activeItem, appName}: OwnProps) => { const [threeDotButtonVisible, setThreeDotButtonVisible] = useState(false); const translate = useIntl(); @@ -28,7 +29,7 @@ const DownloadsDropdownItemFile = ({item, activeItem}: OwnProps) => { }; const itemFilename = item.type === 'update' ? - translate.formatMessage({id: 'renderer.downloadsDropdown.Update.MattermostVersionX', defaultMessage: `{appName} version ${item.filename}`}, {version: item.filename, appName: window.desktop.getAppName()}) : + translate.formatMessage({id: 'renderer.downloadsDropdown.Update.MattermostVersionX', defaultMessage: `{appName} version ${item.filename}`}, {version: item.filename, appName}) : item.filename; return ( diff --git a/src/renderer/components/DownloadsDropdown/Update/UpdateAvailable.tsx b/src/renderer/components/DownloadsDropdown/Update/UpdateAvailable.tsx index 9f5856b017d..4f0a41cbb5f 100644 --- a/src/renderer/components/DownloadsDropdown/Update/UpdateAvailable.tsx +++ b/src/renderer/components/DownloadsDropdown/Update/UpdateAvailable.tsx @@ -12,9 +12,10 @@ import Thumbnail from '../Thumbnail'; type OwnProps = { item: DownloadedItem; + appName: string; } -const UpdateAvailable = ({item}: OwnProps) => { +const UpdateAvailable = ({item, appName}: OwnProps) => { const onButtonClick = (e: React.MouseEvent) => { e?.preventDefault?.(); window.desktop.downloadsDropdown.startUpdateDownload(); @@ -36,7 +37,7 @@ const UpdateAvailable = ({item}: OwnProps) => { defaultMessage={`A new version of the {appName} Desktop App (version ${item.filename}) is available to install.`} values={{ version: item.filename, - appName: window.desktop.getAppName(), + appName, }} /> diff --git a/src/renderer/components/DownloadsDropdown/Update/UpdateDownloaded.tsx b/src/renderer/components/DownloadsDropdown/Update/UpdateDownloaded.tsx index 128084d5b09..a38cd634b2b 100644 --- a/src/renderer/components/DownloadsDropdown/Update/UpdateDownloaded.tsx +++ b/src/renderer/components/DownloadsDropdown/Update/UpdateDownloaded.tsx @@ -15,9 +15,10 @@ import FileSizeAndStatus from '../FileSizeAndStatus'; type OwnProps = { item: DownloadedItem; + appName: string; } -const UpdateAvailable = ({item}: OwnProps) => { +const UpdateAvailable = ({item, appName}: OwnProps) => { const translate = useIntl(); const onButtonClick = (e: React.MouseEvent) => { @@ -31,7 +32,7 @@ const UpdateAvailable = ({item}: OwnProps) => {
- {translate.formatMessage({id: 'renderer.downloadsDropdown.Update.MattermostVersionX', defaultMessage: `{appName} version ${item.filename}`}, {version: item.filename, appName: window.desktop.getAppName()})} + {translate.formatMessage({id: 'renderer.downloadsDropdown.Update.MattermostVersionX', defaultMessage: `{appName} version ${item.filename}`}, {version: item.filename, appName})}
{ +const UpdateWrapper = ({item, appName}: OwnProps) => { if (item.state === 'available') { - return ; + return ( + + ); } if (item.state === 'completed') { - return ; + return ( + + ); } return null; }; diff --git a/src/renderer/downloadsDropdown.tsx b/src/renderer/downloadsDropdown.tsx index e37e3ef9913..150b251a713 100644 --- a/src/renderer/downloadsDropdown.tsx +++ b/src/renderer/downloadsDropdown.tsx @@ -18,6 +18,7 @@ type State = { darkMode?: boolean; windowBounds?: Electron.Rectangle; item?: DownloadedItem; + appName?: string; } class DownloadsDropdown extends React.PureComponent, State> { @@ -40,6 +41,9 @@ class DownloadsDropdown extends React.PureComponent, State window.desktop.downloadsDropdown.focus(); }); + window.desktop.getVersion().then(({name}) => { + this.setState({appName: name}); + }); window.desktop.downloadsDropdown.requestInfo(); } @@ -81,6 +85,10 @@ class DownloadsDropdown extends React.PureComponent, State } render() { + if (!this.state.appName) { + return null; + } + return (
, State item={downloadItem} key={downloadItem.filename} activeItem={this.state.item} + appName={this.state.appName || ''} /> ); })} diff --git a/src/types/window.ts b/src/types/window.ts index d1600d156e1..c4c2adcd442 100644 --- a/src/types/window.ts +++ b/src/types/window.ts @@ -31,8 +31,6 @@ declare global { getThumbnailLocation: (location: string) => Promise; }; desktop: { - getAppName: () => string; - quit: (reason: string, stack: string) => void; openAppMenu: () => void; closeServersDropdown: () => void;