Skip to content

Commit

Permalink
feat: support markdown and pdf export
Browse files Browse the repository at this point in the history
  • Loading branch information
dice2o committed Mar 21, 2023
1 parent 045042d commit 8ea02a7
Show file tree
Hide file tree
Showing 5 changed files with 340 additions and 84 deletions.
14 changes: 7 additions & 7 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
iconUrl: 'https://github.com/dice2o/BingGPT/raw/main/icon.ico',
setupIcon: 'icon.ico',
authors: 'dice2o',
description: 'AI-powered answer engine',
description: 'AI-powered copilot',
},
},
{
Expand All @@ -37,9 +37,9 @@ module.exports = {
bin: 'BingGPT',
name: 'binggpt',
productName: 'BingGPT',
description: 'AI-powered answer engine',
productDescription: 'AI-powered answer engine',
version: '0.2.1',
description: 'AI-powered copilot',
productDescription: 'AI-powered copilot',
version: '0.3.0',
categories: ['Utility'],
maintainer: 'dice2o',
homepage: 'https://github.com/dice2o/BingGPT',
Expand All @@ -54,9 +54,9 @@ module.exports = {
bin: 'BingGPT',
name: 'binggpt',
productName: 'BingGPT',
description: 'AI-powered answer engine',
productDescription: 'AI-powered answer engine',
version: '0.2.1',
description: 'AI-powered copilot',
productDescription: 'AI-powered copilot',
version: '0.3.0',
categories: ['Utility'],
maintainer: 'dice2o',
homepage: 'https://github.com/dice2o/BingGPT',
Expand Down
49 changes: 39 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,26 @@ const createWindow = () => {
{
label: 'Export',
visible: parameters.selectionText.trim().length === 0,
click: () => {
mainWindow.webContents.send('export', isDarkMode)
},
submenu: [
{
label: 'Markdown',
click() {
mainWindow.webContents.send('export', 'md', isDarkMode)
},
},
{
label: 'PNG',
click() {
mainWindow.webContents.send('export', 'png', isDarkMode)
},
},
{
label: 'PDF',
click() {
mainWindow.webContents.send('export', 'pdf', isDarkMode)
},
},
],
},
{
type: 'separator',
Expand Down Expand Up @@ -205,7 +222,7 @@ const createWindow = () => {
},
},
{
label: 'BingGPT v0.2.1',
label: 'BingGPT v0.3.0',
visible: parameters.selectionText.trim().length === 0,
click: () => {
shell.openExternal('https://github.com/dice2o/BingGPT/releases')
Expand Down Expand Up @@ -281,19 +298,31 @@ const createWindow = () => {
}

app.whenReady().then(() => {
// Export conversation as image
ipcMain.on('export-data', (event, dataURL) => {
if (dataURL) {
// Save to file
ipcMain.on('export-data', (event, format, dataURL) => {
if (format) {
const fileName = `BingGPT-${Math.floor(Date.now() / 1000)}.${format}`
let filters
switch (format) {
case 'md':
filters = [{ name: 'Markdown', extensions: ['md'] }]
break
case 'png':
filters = [{ name: 'Image', extensions: ['png'] }]
break
case 'pdf':
filters = [{ name: 'PDF', extensions: ['pdf'] }]
}
dialog
.showSaveDialog(BrowserWindow.getAllWindows()[0], {
title: 'Export',
defaultPath: `BingGPT-${Math.floor(Date.now() / 1000)}.png`,
filters: [{ name: 'Images', extensions: ['png'] }],
defaultPath: fileName,
filters: filters,
})
.then((result) => {
if (!result.canceled) {
const filePath = result.filePath
const data = dataURL.replace(/^data:image\/\w+;base64,/, '')
const data = dataURL.replace(/^data:\S+;base64,/, '')
fs.writeFile(filePath, data, 'base64', (err) => {
if (err) {
dialog.showMessageBox({
Expand Down
Loading

0 comments on commit 8ea02a7

Please sign in to comment.