Skip to content

Commit 8ea02a7

Browse files
committed
feat: support markdown and pdf export
1 parent 045042d commit 8ea02a7

File tree

5 files changed

+340
-84
lines changed

5 files changed

+340
-84
lines changed

forge.config.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
iconUrl: 'https://github.com/dice2o/BingGPT/raw/main/icon.ico',
1616
setupIcon: 'icon.ico',
1717
authors: 'dice2o',
18-
description: 'AI-powered answer engine',
18+
description: 'AI-powered copilot',
1919
},
2020
},
2121
{
@@ -37,9 +37,9 @@ module.exports = {
3737
bin: 'BingGPT',
3838
name: 'binggpt',
3939
productName: 'BingGPT',
40-
description: 'AI-powered answer engine',
41-
productDescription: 'AI-powered answer engine',
42-
version: '0.2.1',
40+
description: 'AI-powered copilot',
41+
productDescription: 'AI-powered copilot',
42+
version: '0.3.0',
4343
categories: ['Utility'],
4444
maintainer: 'dice2o',
4545
homepage: 'https://github.com/dice2o/BingGPT',
@@ -54,9 +54,9 @@ module.exports = {
5454
bin: 'BingGPT',
5555
name: 'binggpt',
5656
productName: 'BingGPT',
57-
description: 'AI-powered answer engine',
58-
productDescription: 'AI-powered answer engine',
59-
version: '0.2.1',
57+
description: 'AI-powered copilot',
58+
productDescription: 'AI-powered copilot',
59+
version: '0.3.0',
6060
categories: ['Utility'],
6161
maintainer: 'dice2o',
6262
homepage: 'https://github.com/dice2o/BingGPT',

main.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,26 @@ const createWindow = () => {
8181
{
8282
label: 'Export',
8383
visible: parameters.selectionText.trim().length === 0,
84-
click: () => {
85-
mainWindow.webContents.send('export', isDarkMode)
86-
},
84+
submenu: [
85+
{
86+
label: 'Markdown',
87+
click() {
88+
mainWindow.webContents.send('export', 'md', isDarkMode)
89+
},
90+
},
91+
{
92+
label: 'PNG',
93+
click() {
94+
mainWindow.webContents.send('export', 'png', isDarkMode)
95+
},
96+
},
97+
{
98+
label: 'PDF',
99+
click() {
100+
mainWindow.webContents.send('export', 'pdf', isDarkMode)
101+
},
102+
},
103+
],
87104
},
88105
{
89106
type: 'separator',
@@ -205,7 +222,7 @@ const createWindow = () => {
205222
},
206223
},
207224
{
208-
label: 'BingGPT v0.2.1',
225+
label: 'BingGPT v0.3.0',
209226
visible: parameters.selectionText.trim().length === 0,
210227
click: () => {
211228
shell.openExternal('https://github.com/dice2o/BingGPT/releases')
@@ -281,19 +298,31 @@ const createWindow = () => {
281298
}
282299

283300
app.whenReady().then(() => {
284-
// Export conversation as image
285-
ipcMain.on('export-data', (event, dataURL) => {
286-
if (dataURL) {
301+
// Save to file
302+
ipcMain.on('export-data', (event, format, dataURL) => {
303+
if (format) {
304+
const fileName = `BingGPT-${Math.floor(Date.now() / 1000)}.${format}`
305+
let filters
306+
switch (format) {
307+
case 'md':
308+
filters = [{ name: 'Markdown', extensions: ['md'] }]
309+
break
310+
case 'png':
311+
filters = [{ name: 'Image', extensions: ['png'] }]
312+
break
313+
case 'pdf':
314+
filters = [{ name: 'PDF', extensions: ['pdf'] }]
315+
}
287316
dialog
288317
.showSaveDialog(BrowserWindow.getAllWindows()[0], {
289318
title: 'Export',
290-
defaultPath: `BingGPT-${Math.floor(Date.now() / 1000)}.png`,
291-
filters: [{ name: 'Images', extensions: ['png'] }],
319+
defaultPath: fileName,
320+
filters: filters,
292321
})
293322
.then((result) => {
294323
if (!result.canceled) {
295324
const filePath = result.filePath
296-
const data = dataURL.replace(/^data:image\/\w+;base64,/, '')
325+
const data = dataURL.replace(/^data:\S+;base64,/, '')
297326
fs.writeFile(filePath, data, 'base64', (err) => {
298327
if (err) {
299328
dialog.showMessageBox({

0 commit comments

Comments
 (0)