Browse Source

Fixed links, images and attachments in Skype

Fixes #116
pull/223/head
Ramiro Saenz 9 years ago
parent
commit
4e01724c71
  1. 4
      app/package.json
  2. 9
      app/ux/WebView.js
  3. 42
      electron/main.js
  4. 4
      package.json

4
app/package.json

@ -28,6 +28,8 @@
"auto-launch": "^2.1.0", "auto-launch": "^2.1.0",
"electron-window-state": "^3.0.3", "electron-window-state": "^3.0.3",
"firebase": "^3.0.5", "firebase": "^3.0.5",
"firebase-token-generator": "^2.0.0" "firebase-token-generator": "^2.0.0",
"tmp": "0.0.28",
"mime": "^1.3.4"
} }
} }

9
app/ux/WebView.js

@ -120,6 +120,15 @@ Ext.define('Rambox.ux.WebView',{
// Open links in default browser // Open links in default browser
webview.addEventListener('new-window', function(e) { webview.addEventListener('new-window', function(e) {
// hack to fix multiple browser tabs on Skype link click, re #11
if ( e.url.match('https:\/\/web.skype.com\/..\/undefined') ) {
e.preventDefault();
return;
} else if ( e.url.indexOf('imgpsh_fullsize') >= 0 ) {
require('electron').ipcRenderer.send('image:download', e.url, e.target.partition);
e.preventDefault();
return;
}
const protocol = require('url').parse(e.url).protocol; const protocol = require('url').parse(e.url).protocol;
if (protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:') { if (protocol === 'http:' || protocol === 'https:' || protocol === 'mailto:') {
e.preventDefault(); e.preventDefault();

42
electron/main.js

@ -213,6 +213,48 @@ app.on('certificate-error', function(event, webContents, url, error, certificate
} }
}); });
// Code for downloading images as temporal files
// Credit: Ghetto Skype (https://github.com/stanfieldr/ghetto-skype)
const tmp = require('tmp');
const mime = require('mime');
var imageCache = {};
electron.ipcMain.on('image:download', function(event, url, partition) {
let file = imageCache[url];
if (file) {
if (file.complete) {
electron.shell.openItem(file.path);
}
// Pending downloads intentionally do not proceed
return;
}
let tmpWindow = new BrowserWindow({
show: false
,webPreferences: {
partition: partition
}
});
tmpWindow.webContents.session.once('will-download', (event, downloadItem) => {
imageCache[url] = file = {
path: tmp.tmpNameSync() + '.' + mime.extension(downloadItem.getMimeType())
,complete: false
};
downloadItem.setSavePath(file.path);
downloadItem.once('done', () => {
tmpWindow.destroy();
tmpWindow = null;
electron.shell.openItem(file.path);
file.complete = true;
});
});
tmpWindow.webContents.downloadURL(url);
});
// This method will be called when Electron has finished // This method will be called when Electron has finished
// initialization and is ready to create browser windows. // initialization and is ready to create browser windows.
app.on('ready', createWindow); app.on('ready', createWindow);

4
package.json

@ -109,6 +109,8 @@
"auto-launch": "^2.1.0", "auto-launch": "^2.1.0",
"electron-window-state": "^3.0.3", "electron-window-state": "^3.0.3",
"firebase": "^3.0.5", "firebase": "^3.0.5",
"firebase-token-generator": "^2.0.0" "firebase-token-generator": "^2.0.0",
"tmp": "0.0.28",
"mime": "^1.3.4"
} }
} }

Loading…
Cancel
Save