Skip to content

Commit

Permalink
add capture
Browse files Browse the repository at this point in the history
  • Loading branch information
SchneeHertz committed Sep 22, 2023
1 parent ecf7a85 commit d575cdb
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 4 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ const createWindow = () => {
})
win.once('ready-to-show', () => {
win.show()
setTimeout(sendHistory, 1000)
})
return win
}
Expand Down Expand Up @@ -511,9 +510,12 @@ ipcMain.handle('switch-speech-talk', async () => {
ipcMain.handle('switch-audio', async () => {
STATUS.isAudioPlay = !STATUS.isAudioPlay
})
ipcMain.handle('empty-history', async()=>{
ipcMain.handle('empty-history', async () => {
setStore('history', [])
})
ipcMain.handle('load-history', async() => {
sendHistory()
})
ipcMain.handle('restart-app', async()=>{
app.relaunch()
app.exit(0)
Expand Down
87 changes: 85 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"axios": "^1.4.0",
"electron-window-state": "^5.0.3",
"html-to-text": "^9.0.5",
"html2canvas": "^1.4.1",
"https-proxy-agent": "^7.0.1",
"js-beautify": "^1.14.9",
"js-tiktoken": "^1.0.7",
Expand Down
17 changes: 17 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import hljs from 'highlight.js'
import 'highlight.js/styles/github-dark.css'
import { Microphone, MicrophoneSlash } from '@vicons/fa'
import { Speaker216Filled, SpeakerOff16Filled } from '@vicons/fluent'
import html2canvas from 'html2canvas'
import CopyButtonPlugin from 'highlightjs-copy'
hljs.addPlugin(new CopyButtonPlugin())
Expand Down Expand Up @@ -51,6 +52,7 @@ onMounted(() => {
})
})
})
ipcRenderer.invoke('load-history')
})
const inputText = ref('')
const inputArea = ref(null)
Expand Down Expand Up @@ -111,6 +113,19 @@ const switchAudio = () => {
const emptyHistory = () => {
ipcRenderer.invoke('empty-history')
}
const saveCapture = async () => {
const screenshotTarget = document.querySelector('#message-list')
const canvas = await html2canvas(screenshotTarget, {
height: screenshotTarget.scrollHeight,
windowHeight: screenshotTarget.scrollHeight
})
const base64image = canvas.toDataURL('image/jpeg', 0.85)
let exportFileDefaultName = 'export.jpg'
let linkElement = document.createElement('a')
linkElement.setAttribute('href', base64image)
linkElement.setAttribute('download', exportFileDefaultName)
linkElement.click()
}
</script>

Expand Down Expand Up @@ -151,6 +166,7 @@ const emptyHistory = () => {
<n-icon><Speaker216Filled v-if="isAudioPlay" /><SpeakerOff16Filled v-else /></n-icon>
</template>
</n-button>
<n-button type="primary" tertiary @click="saveCapture">保存对话</n-button>
<n-button type="primary" tertiary @click="emptyHistory">清除对话历史</n-button>
<Setting ref="setting"/>
</n-space>
Expand All @@ -165,6 +181,7 @@ const emptyHistory = () => {
#message-list
max-height: calc(100vh - 85px)
overflow-y: auto
padding-left: 16px
.message-card
margin: 4px 0 6px
.n-card-header
Expand Down

0 comments on commit d575cdb

Please sign in to comment.