From c74721f74e4abc6e65dca1f664d3767b9d5aff4d Mon Sep 17 00:00:00 2001 From: CyanSalt Date: Sun, 29 Sep 2024 20:21:15 +0800 Subject: [PATCH] feat: add camera addon --- addons/camera/index.js | 10 + addons/camera/package.json | 19 ++ addons/camera/src/main/index.ts | 16 ++ addons/camera/src/renderer/CameraAnchor.vue | 197 ++++++++++++++++++ .../src/renderer/assets/icon-stroked.svg | 12 ++ addons/camera/src/renderer/index.ts | 8 + resources/settings.spec.json | 4 +- 7 files changed, 264 insertions(+), 2 deletions(-) create mode 100644 addons/camera/index.js create mode 100644 addons/camera/package.json create mode 100644 addons/camera/src/main/index.ts create mode 100644 addons/camera/src/renderer/CameraAnchor.vue create mode 100644 addons/camera/src/renderer/assets/icon-stroked.svg create mode 100644 addons/camera/src/renderer/index.ts diff --git a/addons/camera/index.js b/addons/camera/index.js new file mode 100644 index 00000000..5a2a32d3 --- /dev/null +++ b/addons/camera/index.js @@ -0,0 +1,10 @@ +/** + * @param {import('@commas/api/types').API} commas + */ +module.exports = function (commas) { + if (commas.app.isMainProcess()) { + require('./dist/main').default() + } else { + require('./dist/renderer').default() + } +} diff --git a/addons/camera/package.json b/addons/camera/package.json new file mode 100644 index 00000000..93b39ed0 --- /dev/null +++ b/addons/camera/package.json @@ -0,0 +1,19 @@ +{ + "name": "@commas/camera", + "private": true, + "version": "0.1.0", + "productName": "Camera", + "description": "Capture page contents", + "main": "index.js", + "author": "commas", + "license": "ISC", + "commas:icon": { + "name": "lucide-camera" + }, + "commas:i18n": { + "zh-CN": { + "productName": "照相机", + "description": "捕获页面内容" + } + } +} diff --git a/addons/camera/src/main/index.ts b/addons/camera/src/main/index.ts new file mode 100644 index 00000000..ac04ccf5 --- /dev/null +++ b/addons/camera/src/main/index.ts @@ -0,0 +1,16 @@ +import * as commas from 'commas:api/main' +import type { NativeImage, Rectangle } from 'electron' + +declare module '@commas/electron-ipc' { + export interface Commands { + 'capture-page': (rect: Rectangle) => NativeImage, + } +} + +export default () => { + + commas.ipcMain.handle('capture-page', async (event, rect) => { + return event.sender.capturePage(rect) + }) + +} diff --git a/addons/camera/src/renderer/CameraAnchor.vue b/addons/camera/src/renderer/CameraAnchor.vue new file mode 100644 index 00000000..2471bfa3 --- /dev/null +++ b/addons/camera/src/renderer/CameraAnchor.vue @@ -0,0 +1,197 @@ + + + diff --git a/addons/camera/src/renderer/assets/icon-stroked.svg b/addons/camera/src/renderer/assets/icon-stroked.svg new file mode 100644 index 00000000..c9f0656e --- /dev/null +++ b/addons/camera/src/renderer/assets/icon-stroked.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/addons/camera/src/renderer/index.ts b/addons/camera/src/renderer/index.ts new file mode 100644 index 00000000..dcca5596 --- /dev/null +++ b/addons/camera/src/renderer/index.ts @@ -0,0 +1,8 @@ +import * as commas from 'commas:api/renderer' +import CameraAnchor from './CameraAnchor.vue' + +export default () => { + + commas.context.provide('terminal.ui-right-action-anchor', CameraAnchor) + +} diff --git a/resources/settings.spec.json b/resources/settings.spec.json index cf1739da..1b6833c5 100644 --- a/resources/settings.spec.json +++ b/resources/settings.spec.json @@ -445,7 +445,7 @@ "type": "string" } }, - "recommendations": ["addon-manager", "ai", "cleaner", "cli", "clippy", "editor", "git", "iterm2", "l10n-ext", "launcher", "power-mode", "preference", "proxy", "settings", "sync", "theme", "updater"], - "default": ["addon-manager", "ai", "cleaner", "cli", "editor", "git", "iterm2", "l10n-ext", "launcher", "power-mode", "preference", "proxy", "settings", "sync", "theme", "updater"] + "recommendations": ["addon-manager", "ai", "camera", "cleaner", "cli", "clippy", "editor", "git", "iterm2", "l10n-ext", "launcher", "power-mode", "preference", "proxy", "settings", "sync", "theme", "updater"], + "default": ["addon-manager", "ai", "camera", "cleaner", "cli", "editor", "git", "iterm2", "l10n-ext", "launcher", "power-mode", "preference", "proxy", "settings", "sync", "theme", "updater"] } ]