// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React, {useCallback, useEffect, useState} from 'react'; import ReactDOM from 'react-dom'; import classNames from 'classnames'; import {FormattedMessage} from 'react-intl'; import {DownloadedItem} from 'types/downloads'; import { DOWNLOADS_DROPDOWN_MENU_CANCEL_DOWNLOAD, DOWNLOADS_DROPDOWN_MENU_CLEAR_FILE, DOWNLOADS_DROPDOWN_MENU_OPEN_FILE, DOWNLOADS_DROPDOWN_SHOW_FILE_IN_FOLDER, REQUEST_DOWNLOADS_DROPDOWN_MENU_INFO, UPDATE_DOWNLOADS_DROPDOWN_MENU, } from 'common/communication'; import IntlProvider from './intl_provider'; import './css/downloadsDropdownMenu.scss'; const DownloadsDropdownMenu = () => { const [item, setItem] = useState(null); const [darkMode, setDarkMode] = useState(false); useEffect(() => { const handleMessageEvent = (event: MessageEvent) => { if (event.data.type === UPDATE_DOWNLOADS_DROPDOWN_MENU) { const {item, darkMode} = event.data.data; setItem(item); setDarkMode(darkMode); } }; window.addEventListener('message', handleMessageEvent); window.postMessage({type: REQUEST_DOWNLOADS_DROPDOWN_MENU_INFO}, window.location.href); return () => { window.removeEventListener('message', handleMessageEvent); }; }, []); const preventPropagation = (event: React.MouseEvent) => { event.stopPropagation(); }; const getOSFileManager = () => { switch (window.process.platform) { case 'darwin': return ( ); case 'linux': return ( ); case 'win32': return ( ); default: return ( ); } }; const openFile = useCallback(() => { if (item?.type === 'update') { return; } window.postMessage({type: DOWNLOADS_DROPDOWN_MENU_OPEN_FILE, payload: {item}}, window.location.href); }, [item]); const showInFolder = useCallback(() => { if (item?.type === 'update') { return; } window.postMessage({type: DOWNLOADS_DROPDOWN_SHOW_FILE_IN_FOLDER, payload: {item}}, window.location.href); }, [item]); const clearFile = useCallback(() => { if (item?.type === 'update') { return; } window.postMessage({type: DOWNLOADS_DROPDOWN_MENU_CLEAR_FILE, payload: {item}}, window.location.href); }, [item]); const cancelDownload = useCallback(() => { if (item?.state !== 'progressing') { return; } window.postMessage({type: DOWNLOADS_DROPDOWN_MENU_CANCEL_DOWNLOAD, payload: {item}}, window.location.href); }, [item]); return (
{getOSFileManager()}
); }; ReactDOM.render( , document.getElementById('app'), );