Skip to content

Commit

Permalink
fix: linux 图标无法显示 bug、服务打包 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
027xiguapi committed Jan 12, 2024
1 parent 4f29f69 commit 2e89111
Show file tree
Hide file tree
Showing 24 changed files with 46 additions and 64 deletions.
4 changes: 0 additions & 4 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# 将pnpm变成扁平化架构
# node-linker=hoisted

shamefully-hoist=true
node-linker=hoisted

# 在国内使用pnpm安装electron需要配置一下electron的下载路径
registry="https://registry.npm.taobao.org/"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +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\"",
"clear": "concurrently --names \"SERVER,WEB,DESKTOP\" \"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
3 changes: 1 addition & 2 deletions packages/desktop/electron-builder.json5
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
{
appId: 'com.electron.pear-rec',
productName: 'pear-rec',
copyright: 'Copyright © 2023 ${author}',
// asar: false,
copyright: 'Copyright © 2024 ${author}',
asar: true,
directories: {
output: 'release/${version}',
Expand Down
16 changes: 7 additions & 9 deletions packages/desktop/electron/main/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@ import path from 'node:path';
process.env.DIST_ELECTRON = path.join(__dirname, '../');
process.env.DIST = path.join(process.env.DIST_ELECTRON, '../dist');

export const isMac = process.platform === 'darwin';
export const isLinux = process.platform == 'linux';
export const isWin = process.platform == 'win32';

export const url = import.meta.env.VITE_DEV_SERVER_URL;
export const WEB_URL = import.meta.env.VITE_WEB_URL;
export const VITE_API_URL = import.meta.env.VITE_API_URL;
// export const url = 'http://127.0.0.1:7777/';
// export const WEB_URL = 'http://127.0.0.1:9191/';
// export const VITE_API_URL = 'http://127.0.0.1:9190/';

export const preload = path.join(__dirname, '../preload/index.js');
export const serverPath = path.join(__dirname, '../server/main.js');
export const DIST_ELECTRON = path.join(__dirname, '../');
export const DIST = path.join(DIST_ELECTRON, '../dist');

export const PUBLIC = url ? path.join(DIST_ELECTRON, '../public') : process.env.DIST;
export const ICON = url
? path.join(PUBLIC, './imgs/logo/favicon.ico')
: path.join(DIST, './imgs/logo/favicon.ico');
export const PEAR_FILES = path.join(DIST_ELECTRON, `../Pear Files`);

export const DOCS_PATH = path.join(homedir(), 'Documents');
export const ICON = path.join(PUBLIC, './imgs/icons/png/32x32.png');

export const filePath = path.join(DOCS_PATH, `Pear Files`);
export const DOCS_PATH = path.join(homedir(), 'Documents');

export const PEAR_FILES_PATH = path.join(DOCS_PATH, 'Pear Files');

Expand Down
15 changes: 8 additions & 7 deletions packages/desktop/electron/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { app, BrowserWindow, shell, utilityProcess } from 'electron';
import { getConfig, initConfig } from '@pear-rec/server/src/config';
import { BrowserWindow, app } from 'electron';
import { release } from 'node:os';
import * as mainWin from '../win/mainWin';
import { initTray } from './tray';
import { update } from './update';
import { registerFileProtocol } from './protocol';
import { isWin } from './contract';
import { registerGlobalShortcut, unregisterAllGlobalShortcut } from './globalShortcut';
import { initConfig, getConfig } from '@pear-rec/server/src/config';
import { initServerProcess, quitServerProcess } from './serverProcess';
import './ipcMain';
import './logger';
import { registerFileProtocol } from './protocol';
import { initServerProcess, quitServerProcess } from './serverProcess';
import { initTray } from './tray';
import { update } from './update';

initServerProcess();
initConfig();
Expand All @@ -30,7 +31,7 @@ initConfig();
if (release().startsWith('6.1')) app.disableHardwareAcceleration();

// Set application name for Windows 10+ notifications
if (process.platform === 'win32') app.setAppUserModelId(app.getName());
if (isWin) app.setAppUserModelId(app.getName());

app.commandLine.appendSwitch('in-process-gpu');

Expand Down
14 changes: 7 additions & 7 deletions packages/desktop/electron/main/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { screen } from 'electron';
import * as fs from 'node:fs';
import path from 'node:path';
import { PEAR_FILES } from './contract';
import { PEAR_FILES_PATH } from './contract';

function getScreenSize() {
const { size, scaleFactor } = screen.getPrimaryDisplay();
Expand All @@ -16,7 +16,7 @@ function downloadFile(fileInfo: any) {
fileName || (fileName = Number(new Date()));
const url = base64String.split(',')[1]; // 移除前缀,获取base64数据部分
const buffer = Buffer.from(url, 'base64'); // 将base64数据转化为buffer
const imagePath = path.join(PEAR_FILES, `/ss/${fileName}.${fileType}`); // 下载路径
const imagePath = path.join(PEAR_FILES_PATH, `/ss/${fileName}.${fileType}`); // 下载路径

const directory = path.dirname(imagePath); // 获取文件目录
if (!fs.existsSync(directory)) {
Expand All @@ -31,7 +31,7 @@ function saveFile(fileInfo: any) {
fileName || (fileName = Number(new Date()));
const url = base64String.split(',')[1]; // 移除前缀,获取base64数据部分
const buffer = Buffer.from(url, 'base64'); // 将base64数据转化为buffer
const filePath = path.join(PEAR_FILES, `/ss/${fileName}.${fileType}`); // 下载路径
const filePath = path.join(PEAR_FILES_PATH, `/ss/${fileName}.${fileType}`); // 下载路径

const directory = path.dirname(filePath); // 获取文件目录
if (!fs.existsSync(directory)) {
Expand Down Expand Up @@ -132,11 +132,11 @@ function readDirectoryImg(filePath: string) {
}

export {
getScreenSize,
downloadFile,
saveFile,
getAudiosByAudioUrl,
getImgsByImgUrl,
readDirectoryVideo,
getScreenSize,
readDirectoryImg,
getAudiosByAudioUrl,
readDirectoryVideo,
saveFile,
};
Binary file added packages/desktop/public/imgs/icons/mac/icon.icns
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/desktop/public/imgs/icons/png/16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/desktop/public/imgs/icons/png/24x24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/desktop/public/imgs/icons/png/32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/desktop/public/imgs/icons/png/48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/desktop/public/imgs/icons/png/64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/desktop/public/imgs/icons/win/icon.ico
Binary file not shown.
Binary file added packages/desktop/public/imgs/logo/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pear-rec/server",
"version": "1.3.4",
"scripts": {
"build": "nest build --webpack --webpackPath=./webpack.config.js",
"build": "rimraf node_modules && npm install && nest build --webpack --webpackPath=./webpack.config.js",
"webpack": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
Expand Down Expand Up @@ -50,6 +50,7 @@
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"tslib": "^2.6.2",
"typescript": "^5.1.3"
}
}
}
3 changes: 2 additions & 1 deletion packages/server/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = {
},
resolve: {
extensions: ['.js', '.ts', '.json'],
symlinks: true,
},
plugins: [
// 需要进行忽略的插件
Expand Down Expand Up @@ -61,7 +62,7 @@ module.exports = {
new CopyPlugin({
patterns: [
{
from: '../../node_modules/sql.js/dist/sql-wasm.wasm',
from: './node_modules/sql.js/dist/sql-wasm.wasm',
},
],
}),
Expand Down
3 changes: 2 additions & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"clear": "rimraf node_modules"
},
"dependencies": {
"@ant-design/icons": "^5.2.6",
"@pear-rec/recorder": "workspace:^",
"@pear-rec/screenshot": "workspace:^",
"@pear-rec/timer": "workspace:^",
Expand Down Expand Up @@ -69,4 +70,4 @@
"lib": "lib"
},
"description": ""
}
}
15 changes: 5 additions & 10 deletions tools/copy-files-server2desktop.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs-extra');
const { rimraf, rimrafSync } = require('rimraf');
const { rm } = require('node:fs');

const copyFiles = async () => {
try {
Expand All @@ -13,15 +13,10 @@ const copyFiles = async () => {
function deleteFolderFiles() {
const folderPath = './packages/desktop/dist-electron/server';

rimraf
.rimraf(folderPath)
.then(() => {
console.log('Desktop files delete successfully');
copyFiles();
})
.catch((err) => {
console.error('deleteFolderFiles', err);
});
rm(folderPath, () => {
console.log('Desktop files delete successfully');
copyFiles();
});
}

deleteFolderFiles();
15 changes: 5 additions & 10 deletions tools/copy-files-web2desktop.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs-extra');
const { rimraf, rimrafSync } = require('rimraf');
const { rm } = require('node:fs');

const copyFiles = async () => {
try {
Expand All @@ -13,15 +13,10 @@ const copyFiles = async () => {
function deleteFolderFiles() {
const folderPath = './packages/desktop/dist';

rimraf
.rimraf(folderPath)
.then(() => {
console.log('Server files delete successfully');
copyFiles();
})
.catch((err) => {
console.error('deleteFolderFiles', err);
});
rm(folderPath, () => {
console.log('Server files delete successfully');
copyFiles();
});
}

deleteFolderFiles();
15 changes: 5 additions & 10 deletions tools/copy-files-web2server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs-extra');
const { rimraf, rimrafSync } = require('rimraf');
const { rm } = require('node:fs');

const copyFiles = async () => {
try {
Expand All @@ -13,15 +13,10 @@ const copyFiles = async () => {
function deleteFolderFiles() {
const folderPath = './packages/server/public';

rimraf
.rimraf(folderPath)
.then(() => {
console.log('Server files delete successfully');
copyFiles();
})
.catch((err) => {
console.error('deleteFolderFiles', err);
});
rm(folderPath, () => {
console.log('Server files delete successfully');
copyFiles();
});
}

deleteFolderFiles();

0 comments on commit 2e89111

Please sign in to comment.