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,
.download-folder-path {
background: #eeeeee;
padding: 10px;
margin-top: 10px;
padding: 5px 10px;
margin-right: 10px;
display: flex;
width: 90%;
@@ -565,7 +564,7 @@ input.toggle-round:checked+label:after {
.certificate-input {
width:100%;
margin-top: 10px;
margin-top: 10px;
display:inline-flex;
}

View File

@@ -10,19 +10,21 @@ function handleExternalLink(event) {
const { url } = event;
const domainPrefix = DomainUtil.getDomain(this.props.index).url;
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 {
isInternalUrl: isWhiteListURL,
isUploadsUrl: isUploadsURL
} = LinkUtil.isInternal(domainPrefix, url);
isInternalUrl: isWhiteListURL,
isUploadsUrl: isUploadsURL
} = LinkUtil.isInternal(domainPrefix, url);
if (isWhiteListURL) {
event.preventDefault();
// download txt, pdf, mp3, mp4 etc.. by using downloadURL in the
// main process which allows the user to save the files to their desktop
// and not trigger webview reload while image in webview will
// do nothing and will not save it
// download txt, pdf, mp3, mp4 etc.. by using downloadURL in the
// main process which allows the user to save the files to their desktop
// and not trigger webview reload while image in webview will
// do nothing and will not save it
if (!LinkUtil.isImage(url) && isUploadsURL) {
ipcRenderer.send('downloadFile', url, downloadPath);
ipcRenderer.once('downloadFileCompleted', (event, filePath, fileName) => {
@@ -37,7 +39,13 @@ function handleExternalLink(event) {
}
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');
});
@@ -51,7 +59,7 @@ function handleExternalLink(event) {
return;
}
// open internal urls inside the current webview.
// open internal urls inside the current webview.
this.$el.loadURL(url);
} else {
event.preventDefault();

View File

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

View File

@@ -97,6 +97,10 @@ class GeneralSection extends BaseSection {
</div>
<div class="title">Advanced</div>
<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-description">
Default download location
@@ -108,6 +112,7 @@ class GeneralSection extends BaseSection {
<div class="download-folder-path">${ConfigUtil.getConfigItem('downloadsPath', `${app.getPath('downloads')}`)}</div>
</div>
</div>
</div>
<div class="title">Reset Application Data</div>
<div class="settings-card">
@@ -138,6 +143,7 @@ class GeneralSection extends BaseSection {
this.showCustomCSSPath();
this.removeCustomCSS();
this.downloadFolder();
this.showDownloadFolder();
// 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;