feat(desktop): add screenshot button in chatbox at electron env

pull/100/head
moonrailgun 2 years ago
parent 27eee90034
commit aebcd0d130

@ -1,5 +1,6 @@
import { generateInstallPluginScript } from '.'; import { generateInstallPluginScript } from '.';
import log from 'electron-log'; import log from 'electron-log';
import { startScreenshots } from '../screenshots';
export function handleTailchatMessage( export function handleTailchatMessage(
type: string, type: string,
@ -12,4 +13,9 @@ export function handleTailchatMessage(
webview.executeJavaScript(generateInstallPluginScript()); webview.executeJavaScript(generateInstallPluginScript());
return; return;
} }
if (type === 'callScreenshotsTool') {
startScreenshots();
return;
}
} }

@ -1,9 +1,13 @@
import { globalShortcut } from 'electron'; import { globalShortcut } from 'electron';
import Screenshots from 'electron-screenshots'; import Screenshots from 'electron-screenshots';
import _once from 'lodash/once'; import _once from 'lodash/once';
import log from 'electron-log';
let _screenshots: Screenshots;
export const initScreenshots = _once(() => { export const initScreenshots = _once(() => {
const screenshots = new Screenshots(); const screenshots = new Screenshots();
_screenshots = screenshots;
globalShortcut.register('ctrl+shift+a', () => { globalShortcut.register('ctrl+shift+a', () => {
screenshots.startCapture(); screenshots.startCapture();
@ -23,3 +27,12 @@ export const initScreenshots = _once(() => {
console.log('capture', buffer, bounds); console.log('capture', buffer, bounds);
}); });
}); });
export function startScreenshots() {
if (!_screenshots) {
log.warn('_screenshots not inited');
return;
}
_screenshots.startCapture();
}

@ -1,4 +1,10 @@
import { regCustomPanel } from '@capital/common'; import {
regCustomPanel,
regChatInputButton,
postMessageEvent,
} from '@capital/common';
import { Icon } from '@capital/component';
import React from 'react';
import { DeviceInfoPanel } from './DeviceInfoPanel'; import { DeviceInfoPanel } from './DeviceInfoPanel';
import { Translate } from './translate'; import { Translate } from './translate';
@ -13,3 +19,18 @@ regCustomPanel({
label: Translate.deviceInfo, label: Translate.deviceInfo,
render: DeviceInfoPanel, render: DeviceInfoPanel,
}); });
regChatInputButton({
render: () => {
return (
<Icon
className="text-2xl cursor-pointer"
icon="mdi:content-cut"
rotate={3}
onClick={() => {
postMessageEvent('callScreenshotsTool');
}}
/>
);
},
});

@ -32,6 +32,7 @@ export {
appendUrlSearch, appendUrlSearch,
} from '@/utils/url-helper'; } from '@/utils/url-helper';
export { getServiceWorkerRegistration } from '@/utils/sw-helper'; export { getServiceWorkerRegistration } from '@/utils/sw-helper';
export { postMessageEvent } from '@/utils/event-helper';
import { import {
/** /**
* : Tailchat requestimport axios() * : Tailchat requestimport axios()

Loading…
Cancel
Save