file-attachment: Add a setting option to show downloaded file in file manager.

This commit is contained in:
Akash Nimare
2018-08-01 23:50:02 +05:30
parent 3f6d256910
commit a5c1ae8726
4 changed files with 40 additions and 14 deletions

View File

@@ -388,8 +388,7 @@ i.open-tab-button {
.selected-css-path, .selected-css-path,
.download-folder-path { .download-folder-path {
background: #eeeeee; background: #eeeeee;
padding: 10px; padding: 5px 10px;
margin-top: 10px;
margin-right: 10px; margin-right: 10px;
display: flex; display: flex;
width: 90%; width: 90%;

View File

@@ -10,19 +10,21 @@ function handleExternalLink(event) {
const { url } = event; const { url } = event;
const domainPrefix = DomainUtil.getDomain(this.props.index).url; const domainPrefix = DomainUtil.getDomain(this.props.index).url;
const downloadPath = ConfigUtil.getConfigItem('downloadsPath', `${app.getPath('downloads')}`); const downloadPath = ConfigUtil.getConfigItem('downloadsPath', `${app.getPath('downloads')}`);
// Whitelist URLs which are allowed to be opened in the app const shouldShowInFolder = ConfigUtil.getConfigItem('showDownloadFolder', false);
// Whitelist URLs which are allowed to be opened in the app
const { const {
isInternalUrl: isWhiteListURL, isInternalUrl: isWhiteListURL,
isUploadsUrl: isUploadsURL isUploadsUrl: isUploadsURL
} = LinkUtil.isInternal(domainPrefix, url); } = LinkUtil.isInternal(domainPrefix, url);
if (isWhiteListURL) { if (isWhiteListURL) {
event.preventDefault(); event.preventDefault();
// download txt, pdf, mp3, mp4 etc.. by using downloadURL in the // download txt, pdf, mp3, mp4 etc.. by using downloadURL in the
// main process which allows the user to save the files to their desktop // main process which allows the user to save the files to their desktop
// and not trigger webview reload while image in webview will // and not trigger webview reload while image in webview will
// do nothing and will not save it // do nothing and will not save it
if (!LinkUtil.isImage(url) && isUploadsURL) { if (!LinkUtil.isImage(url) && isUploadsURL) {
ipcRenderer.send('downloadFile', url, downloadPath); ipcRenderer.send('downloadFile', url, downloadPath);
ipcRenderer.once('downloadFileCompleted', (event, filePath, fileName) => { ipcRenderer.once('downloadFileCompleted', (event, filePath, fileName) => {
@@ -37,7 +39,13 @@ function handleExternalLink(event) {
} }
downloadNotification.onclick = () => { downloadNotification.onclick = () => {
shell.openItem(filePath); if (shouldShowInFolder) {
// Reveal file in download folder
shell.showItemInFolder(filePath);
} else {
// Open file in the default native app
shell.openItem(filePath);
}
}; };
ipcRenderer.removeAllListeners('downloadFileFailed'); ipcRenderer.removeAllListeners('downloadFileFailed');
}); });
@@ -51,7 +59,7 @@ function handleExternalLink(event) {
return; return;
} }
// open internal urls inside the current webview. // open internal urls inside the current webview.
this.$el.loadURL(url); this.$el.loadURL(url);
} else { } else {
event.preventDefault(); event.preventDefault();

View File

@@ -117,7 +117,8 @@ class ServerManagerView {
showNotification: true, showNotification: true,
silent: false silent: false
}, },
downloadsPath: `${app.getPath('downloads')}` downloadsPath: `${app.getPath('downloads')}`,
showDownloadFolder: false
}; };
// Platform specific settings // Platform specific settings

View File

@@ -97,6 +97,10 @@ class GeneralSection extends BaseSection {
</div> </div>
<div class="title">Advanced</div> <div class="title">Advanced</div>
<div class="settings-card"> <div class="settings-card">
<div class="setting-row" id="show-download-folder">
<div class="setting-description">Show downloaded file in the file manager</div>
<div class="setting-control"></div>
</div>
<div class="setting-row" id="download-folder"> <div class="setting-row" id="download-folder">
<div class="setting-description"> <div class="setting-description">
Default download location Default download location
@@ -108,6 +112,7 @@ class GeneralSection extends BaseSection {
<div class="download-folder-path">${ConfigUtil.getConfigItem('downloadsPath', `${app.getPath('downloads')}`)}</div> <div class="download-folder-path">${ConfigUtil.getConfigItem('downloadsPath', `${app.getPath('downloads')}`)}</div>
</div> </div>
</div> </div>
</div> </div>
<div class="title">Reset Application Data</div> <div class="title">Reset Application Data</div>
<div class="settings-card"> <div class="settings-card">
@@ -138,6 +143,7 @@ class GeneralSection extends BaseSection {
this.showCustomCSSPath(); this.showCustomCSSPath();
this.removeCustomCSS(); this.removeCustomCSS();
this.downloadFolder(); this.downloadFolder();
this.showDownloadFolder();
// Platform specific settings // Platform specific settings
@@ -385,6 +391,18 @@ class GeneralSection extends BaseSection {
}); });
} }
showDownloadFolder() {
this.generateSettingOption({
$element: document.querySelector('#show-download-folder .setting-control'),
value: ConfigUtil.getConfigItem('showDownloadFolder', false),
clickHandler: () => {
const newValue = !ConfigUtil.getConfigItem('showDownloadFolder');
ConfigUtil.setConfigItem('showDownloadFolder', newValue);
this.showDownloadFolder();
}
});
}
} }
module.exports = GeneralSection; module.exports = GeneralSection;