Skip to content

Commit

Permalink
update png file download dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
kimorkim committed Sep 27, 2017
1 parent 10cdb69 commit fdb0ba9
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 47 deletions.
20 changes: 11 additions & 9 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
{
"type": "node",
"request": "launch",
"protocol": "legacy",
"name": "Electron Main",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
},
"args" : ["."]
}, {
"type": "node",
"request": "launch",
"name": "Electron Main2",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge-vscode-nix",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge-vscode-win.cmd"
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron-forge-vscode-win.cmd"
},
// "port": 5858,
// "timeout": 10000,
// // runtimeArgs will be passed directly to your Electron application
// "runtimeArgs": [
// "--inspect=5858",
// "--debug"
// ],
"cwd": "${workspaceRoot}"
}
]
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"productName": "Entry",
"scripts": {
"clean": "rimraf dist",
"debug": "./node_modules/.bin/electron-forge-vscode-nix --debug=5858",
"dist": "build",
"comp": "set NODE_ENV=production&&electron-compile ./src",
"start": "electron-forge start",
Expand Down
24 changes: 24 additions & 0 deletions src/entry_offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ addBypassChecker((filePath) => {
return filePath.indexOf(app.getAppPath()) === -1 && bypassList.indexOf(ext) > -1;
});

const downloadFilterList = {
'image/png': [
{ name: 'PNG Image (*.png)', extensions: ['png'] },
{ name: 'All Files (*.*)', extensions: ['*'] }
],
}

global.sharedObject = {
roomId: '',
mainWindowId: '',
Expand Down Expand Up @@ -125,6 +132,23 @@ if (shouldQuit) {
mainWindow.show()
});

mainWindow.webContents.session.on('will-download', (event, downloadItem, webContents) => {
const filename = downloadItem.getFilename();
const option = {
defaultPath: filename,
}
const filters = downloadFilterList[downloadItem.getMimeType()];
if(filters) {
option.filters = filters;
}
var fileName = dialog.showSaveDialog(option);
if (typeof fileName == "undefined") {
downloadItem.cancel()
} else {
downloadItem.setSavePath(fileName);
}
});

mainUtils = new MainUtils(mainWindow);

mainWindow.webContents.on('crashed', () => {
Expand Down
1 change: 1 addition & 0 deletions src/renderer/src/sources/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class Util {
}

static showSaveDialog(option, callback) {
console.log('dasdas?')
if(isOsx) {
dialog.showSaveDialog(option, callback);
} else {
Expand Down
Loading

0 comments on commit fdb0ba9

Please sign in to comment.