Skip to content

Commit

Permalink
feat: 重置设置、显示快捷键
Browse files Browse the repository at this point in the history
  • Loading branch information
027xiguapi committed Dec 8, 2023
1 parent ed75aa6 commit 91c764f
Show file tree
Hide file tree
Showing 30 changed files with 473 additions and 276 deletions.
4 changes: 4 additions & 0 deletions packages/desktop/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @pear-rec/desktop

## 1.3.4

feat: 重置设置、显示快捷键

## 1.3.3

fix: 录屏 bug
Expand Down
4 changes: 4 additions & 0 deletions packages/desktop/electron/i18n/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
"setting": {
"userSetting": "Nutzereinstellungen",
"basicSetting": "Basiseinstellungen",
"serverSetting": "server",
"shortcutSetting": "shortcut",
"address": "web address",
"openFilePath": "open folder",
"language": "Sprache",
"filePath": "Dateipfad",
"openAtLogin": "Bei Anmeldung öffnen",
Expand Down
13 changes: 10 additions & 3 deletions packages/desktop/electron/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,20 @@
"emptyBtn": "open video"
},
"setting": {
"userSetting": "userSetting",
"basicSetting": "basicSetting",
"userSetting": "user",
"basicSetting": "basic",
"serverSetting": "server",
"shortcutSetting": "shortcut",
"address": "web address",
"openFilePath": "open folder",
"reset": "reset",
"language": "language",
"filePath": "filePath",
"openAtLogin": "openAtLogin",
"open": "open",
"close": "close",
"download": "download"
"download": "download",
"openServer": "open server",
"serverPath": "server path"
}
}
9 changes: 8 additions & 1 deletion packages/desktop/electron/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,18 @@
"setting": {
"userSetting": "账户设置",
"basicSetting": "通用设置",
"serverSetting": "服务设置",
"shortcutSetting": "快捷键",
"address": "软件地址",
"openFilePath": "打开下载文件夹",
"reset": "重置",
"language": "语言",
"filePath": "保存地址",
"openAtLogin": "开机自启动",
"open": "开启",
"close": "关闭",
"download": "浏览器下载"
"download": "浏览器下载",
"openServer": "打开服务",
"serverPath": "服务地址"
}
}
80 changes: 55 additions & 25 deletions packages/desktop/electron/main/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,43 @@ import jsonfile from 'jsonfile';
import * as fs from 'node:fs';
import { v5 as uuidv5 } from 'uuid';
import dayjs from 'dayjs';
import { PEAR_FILES_PATH, CONFIG_FILE_PATH } from './contract';

const defaultConfig = {
user: {
uuid: uuidv5('https://www.w3.org/', uuidv5.URL),
userName: `pear-rec:user`,
userType: 1,
createdAt: dayjs().format(),
},
language: 'zh',
};
import { PEAR_FILES_PATH, CONFIG_FILE_PATH, DEFAULT_CONFIG_FILE_PATH } from './contract';

export function initConfig() {
let config: any = {};
if (!fs.existsSync(PEAR_FILES_PATH)) {
fs.mkdirSync(PEAR_FILES_PATH, { recursive: true }); // 不存在则创建目录
fs.mkdirSync(PEAR_FILES_PATH, { recursive: true });
}
try {
config = jsonfile.readFileSync(CONFIG_FILE_PATH);
config.user || (config = editConfig('user', defaultConfig.user));
config.language || (config = editConfig('language', defaultConfig.language));
} catch (err) {
jsonfile.writeFileSync(CONFIG_FILE_PATH, defaultConfig, {
spaces: 2,
EOL: '\r\n',
});
console.log('initConfig :', err);
}
return config;
fs.access(DEFAULT_CONFIG_FILE_PATH, fs.constants.F_OK, (err) => {
if (err) {
initDefaultConfig();
return;
}
});
}

function initDefaultConfig() {
const defaultConfig = {
user: {
uuid: uuidv5('https://www.w3.org/', uuidv5.URL),
userName: `pear-rec:user`,
userType: 1,
createdAt: dayjs().format(),
},
isProxy: false,
proxyPort: '7890',
language: 'zh',
filePath: PEAR_FILES_PATH,
openAtLogin: false,
serverPath: 'http://localhost:9190/',
};
jsonfile.writeFileSync(CONFIG_FILE_PATH, defaultConfig, {
spaces: 2,
EOL: '\r\n',
});
jsonfile.writeFileSync(DEFAULT_CONFIG_FILE_PATH, defaultConfig, {
spaces: 2,
EOL: '\r\n',
});
}

export function getConfig() {
Expand All @@ -42,6 +50,28 @@ export function getConfig() {
}
}

export function getDefaultConfig() {
try {
let defaultConfig = jsonfile.readFileSync(DEFAULT_CONFIG_FILE_PATH) || {};
return defaultConfig;
} catch (err) {
console.log('getConfig :', err);
}
}

export function resetConfig() {
try {
let defaultConfig = jsonfile.readFileSync(DEFAULT_CONFIG_FILE_PATH) || {};
jsonfile.writeFileSync(CONFIG_FILE_PATH, defaultConfig, {
spaces: 2,
EOL: '\r\n',
});
return defaultConfig;
} catch (err) {
console.log('getConfig :', err);
}
}

export function editConfig(key: string, value: any, cb?: Function) {
try {
let config = jsonfile.readFileSync(CONFIG_FILE_PATH) || {};
Expand Down
2 changes: 2 additions & 0 deletions packages/desktop/electron/main/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ export const PEAR_FILES_PATH = path.join(DOCS_PATH, 'Pear Files');

export const CONFIG_FILE_PATH = path.join(PEAR_FILES_PATH, `config.json`);

export const DEFAULT_CONFIG_FILE_PATH = path.join(PEAR_FILES_PATH, `default-config.json`);

export const DB_PATH = path.join(PEAR_FILES_PATH, 'db/pear-rec.db');
15 changes: 0 additions & 15 deletions packages/desktop/electron/main/ipcMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,6 @@ function initIpcMain() {
ipcMain.on('rs:focus', () => {
recorderScreenWin.focusRecorderScreenWin();
});
ipcMain.on('rs:shotScreen', async () => {
const { width, height } = utils.getScreenSize();
const sources = [
...(await desktopCapturer.getSources({
types: ['screen'],
thumbnailSize: {
width,
height,
},
})),
];
const source = sources.filter((e: any) => e.id == 'screen:0:0')[0];
const img = source.thumbnail.toPNG();
recorderScreenWin.shotScreen(img);
});
// 录屏截图
ipcMain.on('cs:open-win', () => {
clipScreenWin.closeClipScreenWin();
Expand Down
1 change: 0 additions & 1 deletion packages/desktop/electron/preload/electronAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ contextBridge.exposeInMainWorld('electronAPI', {
invokeRsGetCursorScreenPoint: () => ipcRenderer.invoke('rs:get-cursor-screen-point'),
invokeRsIsFocused: () => ipcRenderer.invoke('rs:is-focused'),
sendRsFocus: () => ipcRenderer.send('rs:focus'),
sendRsShotScreen: () => ipcRenderer.send('rs:shotScreen'),
sendRsSetIgnoreMouseEvents: (ignore: boolean, options: any) => {
ipcRenderer.send('rs:set-ignore-mouse-events', ignore, options);
},
Expand Down
7 changes: 2 additions & 5 deletions packages/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
"version": "1.3.3",
"main": "dist-electron/main/index.js",
"description": "pear-rec",
"author": {
"name": "027xiguapi",
"email": "[email protected]"
},
"author": "027xiguapi",
"license": "Apache-2.0",
"private": true,
"debug": {
Expand Down Expand Up @@ -46,4 +43,4 @@
"engines": {
"node": "^14.18.0 || >=16.0.0"
}
}
}
4 changes: 4 additions & 0 deletions packages/server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# @pear-rec/server

## 1.2.5

feat: 重置设置

## 1.2.4

perf: 设置保存地址
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"sql.js": "^1.8.0",
"typeorm": "^0.3.17"
}
}
}
3 changes: 2 additions & 1 deletion packages/server/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export default {
input: 'src/index.ts',
output: {
file: 'dist/index.js',
format: 'es',
format: 'cjs',
sourcemap: true,
},
context: 'window',
external: ['typeorm', 'sql.js'],
Expand Down
Loading

0 comments on commit 91c764f

Please sign in to comment.