Skip to content

Commit

Permalink
fix: macos无法截屏、服务打包 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
027xiguapi committed Jan 11, 2024
1 parent a811595 commit 4f29f69
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 44 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# node-linker=hoisted

shamefully-hoist=true
node-linker=hoisted

# 在国内使用pnpm安装electron需要配置一下electron的下载路径
registry="https://registry.npm.taobao.org/"
Expand Down
24 changes: 16 additions & 8 deletions README.de-DE.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,28 @@ github: https://github.com/027xiguapi/pear-rec
Bevor Sie dieses Repository klonen und ausführen, müssen Sie [Git](https://git-scm.com), [Node.js](https://nodejs.org/en/download/) (mit [npm](https://www.npmjs.com/)) und [pnpm](https://pnpm.io/) auf Ihrem Computer installiert haben. Kommandozeilenaufrufe:

```shell
# Repository klonen
# Clone this repository
git clone https://github.com/027xiguapi/pear-rec.git
# In das Repository wechseln
# Go into the repository
cd pear-rec
# Abhängigkeiten installieren
# Install dependencies
pnpm install
# Electron neu bauen
pnpm run rebuild:desktop
# Web Version ausführen
# Run the web
pnpm run dev:web
# Web Version bauen
# Run the server
pnpm run dev:server
# Run the desktop
pnpm run dev:desktop
# Run the web
pnpm run start:web
# Run the desktop
pnpm run start:desktop
# Build the web
pnpm run build:web
# Desktop Version bauen
# Build the desktop
pnpm run build:desktop
# Clear node_modules
pnpm run clear
```

## Internationalization(I18n)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pnpm run start:desktop
pnpm run build:web
# Build the desktop
pnpm run build:desktop
# Clear node_modules
pnpm run clear
```

## Functions
Expand Down
2 changes: 2 additions & 0 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ pnpm run start:web
pnpm run start:desktop
# 编译软件
pnpm run build:desktop
# 清除 node_modules
pnpm run clear
```

## 功能
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dev:screenshot": "pnpm run -C packages/screenshot dev",
"build:screenshot": "pnpm run -C packages/screenshot build",
"watch:screenshot": "pnpm run -C packages/screenshot watch",
"clear": "concurrently -s \"pnpm run -C packages/web clear\" \"pnpm run -C packages/server clear\" \"pnpm run -C packages/desktop clear\"",
"copy": "node tools/copy-web-files.js",
"changeset": "changeset",
"vp": "changeset version",
Expand Down
7 changes: 5 additions & 2 deletions packages/desktop/electron/main/ipcMain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, BrowserWindow, webContents, ipcMain, desktopCapturer, dialog, shell } from 'electron';
import { app, BrowserWindow, webContents, ipcMain, desktopCapturer, dialog, shell, screen } from 'electron';
import * as mainWin from '../win/mainWin';
import * as shotScreenWin from '../win/shotScreenWin';
import * as recorderScreenWin from '../win/recorderScreenWin';
Expand Down Expand Up @@ -134,6 +134,7 @@ function initIpcMain() {
ipcMain.handle('cs:get-bounds', () => clipScreenWin.getBoundsClipScreenWin());
// 截图
ipcMain.handle('ss:get-shot-screen-img', async () => {
const { id } = screen.getPrimaryDisplay();
const { width, height } = utils.getScreenSize();
const sources = [
...(await desktopCapturer.getSources({
Expand All @@ -144,7 +145,9 @@ function initIpcMain() {
},
})),
];
const source = sources.filter((e: any) => e.id == 'screen:0:0')[0];

let source = sources.filter((e: any) => parseInt(e.display_id, 10) == id)[0];
source || (source = sources[0])
const img = source.thumbnail.toDataURL();
return img;
});
Expand Down
24 changes: 0 additions & 24 deletions packages/desktop/electron/win/shotScreenWin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
app,
BrowserWindow,
shell,
dialog,
DownloadItem,
WebContents,
Expand Down Expand Up @@ -46,29 +45,6 @@ function createShotScreenWin(): BrowserWindow {
shotScreenWin.maximize();
shotScreenWin.setFullScreen(true);

shotScreenWin?.webContents.session.on(
'will-download',
async (e: any, item: DownloadItem, webContents: WebContents) => {
const url = item.getURL();
// if (downloadSet.has(url)) {
// const fileName = item.getFilename();
// const filePath = (await getFilePath()) as string;
// const ssFilePath = join(savePath || `${filePath}/ss`, `${fileName}`);
// item.setSavePath(ssFilePath);
// item.once('done', (event: any, state: any) => {
// if (state === 'completed') {
// copyImg(ssFilePath);
// setHistoryImg(ssFilePath);
// setTimeout(() => {
// closeShotScreenWin();
// openViewImageWin({ imgUrl: ssFilePath });
// }, 1000 * 0.5);
// }
// });
// }
},
);

return shotScreenWin;
}

Expand Down
5 changes: 3 additions & 2 deletions packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"pree2e": "vite build --mode=test",
"e2e": "playwright test",
"release": "electron-builder -p always",
"server": "node dist-electron/server/main"
"server": "node dist-electron/server/main",
"clear": "rimraf node_modules"
},
"dependencies": {
"electron-updater": "^6.1.1"
Expand All @@ -43,4 +44,4 @@
"engines": {
"node": "^14.18.0 || >=16.0.0"
}
}
}
3 changes: 2 additions & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"start": "nest start",
"dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main"
"start:prod": "node dist/main",
"clear": "rimraf node_modules"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
Expand Down
12 changes: 7 additions & 5 deletions packages/server/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
'@nestjs/websockets/socket-module',
'cache-manager',
'class-validator',
'class-transformer'
'class-transformer',
];
if (!lazyImports.includes(resource)) {
return false;
Expand All @@ -59,9 +59,11 @@ module.exports = {
}),
new ForkTsCheckerWebpackPlugin(),
new CopyPlugin({
patterns: [{
from: './node_modules/sql.js/dist/sql-wasm.wasm'
}]
}),
patterns: [
{
from: '../../node_modules/sql.js/dist/sql-wasm.wasm',
},
],
}),
],
};
5 changes: 3 additions & 2 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"build": "rimraf dist && tsc && vite build",
"watch": "tsc && vite build --mode lib -w",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"preview": "vite preview",
"clear": "rimraf node_modules"
},
"dependencies": {
"@pear-rec/recorder": "workspace:^",
Expand Down Expand Up @@ -68,4 +69,4 @@
"lib": "lib"
},
"description": ""
}
}

0 comments on commit 4f29f69

Please sign in to comment.