...
 
Commits (2)
......@@ -141,13 +141,13 @@ function createView() {
mainWindow.setBrowserView(mainView);
const toolbarHeight = 40;
const offsetY = 440;
const windowBounds = mainWindow.getBounds();
mainView.setBounds({
x: 0,
y: toolbarHeight,
y: offsetY,
width: windowBounds.width,
height: windowBounds.height - toolbarHeight
height: windowBounds.height - offsetY
});
mainView.setAutoResize({
......@@ -226,11 +226,6 @@ function createView() {
event.returnValue = undefined;
});
ipcMain.on('browserView_executeJavaScript', (event, ...args) => {
mainView.webContents.executeJavaScript(...args);
event.returnValue = undefined;
});
//ipcMain.on('ipcMessage', (event) => {});
const appConfigStore = new ElectronStore({name: appConfigStoreStorage});
......@@ -275,14 +270,24 @@ function previewpicFilename(itemKey) {
return btoa(itemKey).slice(-255);
}
function downloadPreviewpic(itemKey, url) {
if (!isDirectory(previewpicDirectory)) {
fs.mkdirSync(previewpicDirectory);
}
const path = `${previewpicDirectory}/${previewpicFilename(itemKey)}`;
request.get(url).on('error', (error) => {
console.error(error);
}).pipe(fs.createWriteStream(path));
function downloadPreviewpic(itemKey) {
const selector = 'meta[property="og:image"]';
mainView.webContents.executeJavaScript(
`document.querySelector('${selector}').content`,
false,
(result) => {
const previewpicUrl = result || '';
if (previewpicUrl) {
if (!isDirectory(previewpicDirectory)) {
fs.mkdirSync(previewpicDirectory);
}
const path = `${previewpicDirectory}/${previewpicFilename(itemKey)}`;
request.get(previewpicUrl).on('error', (error) => {
console.error(error);
}).pipe(fs.createWriteStream(path));
}
}
);
}
function removePreviewpic(itemKey) {
......@@ -353,15 +358,15 @@ ipcMain.on('store', (event, key, value) => {
event.returnValue = key ? appConfigStore.get(key) : appConfigStore.store;
});
ipcMain.on('previewpic', (event, kind, itemKey, url) => {
ipcMain.on('previewpic', (event, kind, itemKey) => {
if (kind === 'directory') {
event.returnValue = previewpicDirectory;
}
else if (kind === 'path' && itemKey) {
event.returnValue = `${previewpicDirectory}/${previewpicFilename(itemKey)}`;
}
else if (kind === 'download' && itemKey && url) {
downloadPreviewpic(itemKey, url);
else if (kind === 'download' && itemKey) {
downloadPreviewpic(itemKey);
event.returnValue = undefined;
}
else if (kind === 'remove' && itemKey) {
......
......@@ -185,30 +185,7 @@ export default class OcsManagerHandler {
});
// Download preview picture
const selector = 'meta[property="og:image"]';
// TODO: make download method inside main process
this._webviewComponent.executeJavaScript(
`document.querySelector('${selector}').content`,
false,
(result) => {
let previewpicUrl = result || '';
// FIXME: previewpic API maybe deprecated
/*
if (!previewpicUrl
&& message.data[0].metadata.command === 'install'
&& message.data[0].metadata.provider
&& message.data[0].metadata.content_id
) {
previewpicUrl = `${message.data[0].metadata.provider}content/previewpic/${message.data[0].metadata.content_id}`;
}
*/
if (previewpicUrl) {
this._ipcRenderer.sendSync('previewpic', 'download', message.data[0].metadata.url, previewpicUrl);
}
}
);
this._ipcRenderer.sendSync('previewpic', 'download', message.data[0].metadata.url);
})
.set('ItemHandler::downloadFinished', (message) => {
if (message.data[0].status !== 'success_download') {
......