Skip to content

Commit

Permalink
增加运行日志功能
Browse files Browse the repository at this point in the history
  • Loading branch information
niuniuland committed Dec 9, 2023
1 parent 7d4319c commit f56b2e0
Show file tree
Hide file tree
Showing 20 changed files with 342 additions and 35 deletions.
Empty file added logs/Api/2023-12-09.log
Empty file.
6 changes: 6 additions & 0 deletions logs/Main/2023-12-09.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Main | 2023-12-09 16:35:27 - info: env, is prod:, false
Main | 2023-12-09 16:37:46 - info: env, is prod:, false
Main | 2023-12-09 16:48:49 - info: env, is prod:, false
Main | 2023-12-09 16:51:26 - info: env, is prod:, false
Main | 2023-12-09 16:52:42 - info: env, is prod:, false
Main | 2023-12-09 16:55:12 - info: env, is prod:, false
Empty file added logs/Proxy/2023-12-09.log
Empty file.
114 changes: 114 additions & 0 deletions logs/Service/2023-12-09.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
Service | 2023-12-09 16:35:27 - info: init common service...
Service | 2023-12-09 16:35:27 - info: init window service...
Service | 2023-12-09 16:35:27 - info: init group service...
Service | 2023-12-09 16:35:27 - info: init proxy bridge...
Service | 2023-12-09 16:35:27 - info: init tag service...
Service | 2023-12-09 16:35:27 - info: init sync service...
Service | 2023-12-09 16:37:46 - info: init common service...
Service | 2023-12-09 16:37:46 - info: init window service...
Service | 2023-12-09 16:37:46 - info: init group service...
Service | 2023-12-09 16:37:46 - info: init proxy bridge...
Service | 2023-12-09 16:37:46 - info: init tag service...
Service | 2023-12-09 16:37:46 - info: init sync service...
Service | 2023-12-09 16:48:49 - info: init common service...
Service | 2023-12-09 16:48:49 - info: init window service...
Service | 2023-12-09 16:48:49 - info: init group service...
Service | 2023-12-09 16:48:49 - info: init proxy bridge...
Service | 2023-12-09 16:48:49 - info: init tag service...
Service | 2023-12-09 16:48:49 - info: init sync service...
Service | 2023-12-09 16:51:26 - info: init common service...
Service | 2023-12-09 16:51:26 - info: init window service...
Service | 2023-12-09 16:51:26 - info: init group service...
Service | 2023-12-09 16:51:26 - info: init proxy bridge...
Service | 2023-12-09 16:51:26 - info: init tag service...
Service | 2023-12-09 16:51:26 - info: init sync service...
Service | 2023-12-09 16:52:42 - info: init common service...
Service | 2023-12-09 16:52:42 - info: init window service...
Service | 2023-12-09 16:52:42 - info: init group service...
Service | 2023-12-09 16:52:42 - info: init proxy bridge...
Service | 2023-12-09 16:52:42 - info: init tag service...
Service | 2023-12-09 16:52:42 - info: init sync service...
Service | 2023-12-09 16:55:12 - info: init common service...
Service | 2023-12-09 16:55:12 - info: init window service...
Service | 2023-12-09 16:55:12 - info: init group service...
Service | 2023-12-09 16:55:12 - info: init proxy bridge...
Service | 2023-12-09 16:55:12 - info: init tag service...
Service | 2023-12-09 16:55:12 - info: init sync service...
Service | 2023-12-09 16:55:34 - info: init common service...
Service | 2023-12-09 16:55:34 - info: init window service...
Service | 2023-12-09 16:55:34 - info: init group service...
Service | 2023-12-09 16:55:34 - info: init proxy bridge...
Service | 2023-12-09 16:55:34 - info: init tag service...
Service | 2023-12-09 16:55:34 - info: init sync service...
Service | 2023-12-09 16:56:21 - info: init common service...
Service | 2023-12-09 16:56:21 - info: init window service...
Service | 2023-12-09 16:56:21 - info: init group service...
Service | 2023-12-09 16:56:21 - info: init proxy bridge...
Service | 2023-12-09 16:56:21 - info: init tag service...
Service | 2023-12-09 16:56:21 - info: init sync service...
Service | 2023-12-09 17:55:14 - info: init common service...
Service | 2023-12-09 17:55:14 - info: init window service...
Service | 2023-12-09 17:55:14 - info: init group service...
Service | 2023-12-09 17:55:14 - info: init proxy bridge...
Service | 2023-12-09 17:55:14 - info: init tag service...
Service | 2023-12-09 17:55:14 - info: init sync service...
Service | 2023-12-09 18:03:54 - info: init common service...
Service | 2023-12-09 18:03:54 - info: init window service...
Service | 2023-12-09 18:03:54 - info: init group service...
Service | 2023-12-09 18:03:54 - info: init proxy bridge...
Service | 2023-12-09 18:03:54 - info: init tag service...
Service | 2023-12-09 18:03:54 - info: init sync service...
Service | 2023-12-09 18:04:10 - info: init common service...
Service | 2023-12-09 18:04:10 - info: init window service...
Service | 2023-12-09 18:04:10 - info: init group service...
Service | 2023-12-09 18:04:10 - info: init proxy bridge...
Service | 2023-12-09 18:04:10 - info: init tag service...
Service | 2023-12-09 18:04:10 - info: init sync service...
Service | 2023-12-09 18:04:17 - info: init common service...
Service | 2023-12-09 18:04:17 - info: init window service...
Service | 2023-12-09 18:04:17 - info: init group service...
Service | 2023-12-09 18:04:17 - info: init proxy bridge...
Service | 2023-12-09 18:04:17 - info: init tag service...
Service | 2023-12-09 18:04:17 - info: init sync service...
Service | 2023-12-09 18:24:52 - info: init common service...
Service | 2023-12-09 18:24:52 - info: init window service...
Service | 2023-12-09 18:24:52 - info: init group service...
Service | 2023-12-09 18:24:52 - info: init proxy bridge...
Service | 2023-12-09 18:24:52 - info: init tag service...
Service | 2023-12-09 18:24:52 - info: init sync service...
Service | 2023-12-09 18:45:35 - info: init common service...
Service | 2023-12-09 18:45:35 - info: init window service...
Service | 2023-12-09 18:45:35 - info: init group service...
Service | 2023-12-09 18:45:35 - info: init proxy bridge...
Service | 2023-12-09 18:45:35 - info: init tag service...
Service | 2023-12-09 18:45:35 - info: init sync service...
Service | 2023-12-09 18:45:39 - info: init common service...
Service | 2023-12-09 18:45:39 - info: init window service...
Service | 2023-12-09 18:45:39 - info: init group service...
Service | 2023-12-09 18:45:39 - info: init proxy bridge...
Service | 2023-12-09 18:45:39 - info: init tag service...
Service | 2023-12-09 18:45:39 - info: init sync service...
Service | 2023-12-09 18:54:10 - info: init common service...
Service | 2023-12-09 18:54:10 - info: init window service...
Service | 2023-12-09 18:54:10 - info: init group service...
Service | 2023-12-09 18:54:10 - info: init proxy bridge...
Service | 2023-12-09 18:54:10 - info: init tag service...
Service | 2023-12-09 18:54:10 - info: init sync service...
Service | 2023-12-09 19:10:42 - info: init common service...
Service | 2023-12-09 19:10:42 - info: init window service...
Service | 2023-12-09 19:10:42 - info: init group service...
Service | 2023-12-09 19:10:42 - info: init proxy bridge...
Service | 2023-12-09 19:10:42 - info: init tag service...
Service | 2023-12-09 19:10:42 - info: init sync service...
Service | 2023-12-09 19:11:25 - info: init common service...
Service | 2023-12-09 19:11:25 - info: init window service...
Service | 2023-12-09 19:11:25 - info: init group service...
Service | 2023-12-09 19:11:25 - info: init proxy bridge...
Service | 2023-12-09 19:11:25 - info: init tag service...
Service | 2023-12-09 19:11:25 - info: init sync service...
Service | 2023-12-09 19:11:27 - info: init common service...
Service | 2023-12-09 19:11:27 - info: init window service...
Service | 2023-12-09 19:11:27 - info: init group service...
Service | 2023-12-09 19:11:27 - info: init proxy bridge...
Service | 2023-12-09 19:11:27 - info: init tag service...
Service | 2023-12-09 19:11:27 - info: init sync service...
1 change: 1 addition & 0 deletions logs/Window/2023-12-09.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Window | 2023-12-09 16:55:59 - info: fingerprint 182 "j4gapbh" {"ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.6045.123 Safari/537.36","platform":"Win32","pathStr":"o","webgl":0.12400250746218877,"audio":93}
22 changes: 6 additions & 16 deletions packages/main/src/fingerprint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ const HOST = '127.0.0.1';
// const HomePath = app.getPath('userData');
// console.log(HomePath);

const getPublicIP = async () => {
try {
const response = await fetch('https://api.ipify.org?format=json');
const data = await response.json();
return data.ip;
} catch (error) {
logger.error('Error fetching public IP:', error);
return null;
}
};

const attachFingerprintToPuppeteer = async (page: Page, ipInfo: IP) => {
page.on('framenavigated', async _msg => {
try {
Expand Down Expand Up @@ -120,22 +109,24 @@ export async function openFingerprintWindow(id: number) {
}
const win = BrowserWindow.getAllWindows()[0];
const windowDataDir = `${cachePath}\\${id}_${windowData.profile_id}`;

const chromePath = 'D:\\chromium-dev\\source\\src\\out\\Default\\chrome.exe';

let ipInfo = {timeZone: '', ip: '', ll: [], country: ''};
if (windowData.proxy_id && proxyData.ip) {
ipInfo = await getProxyInfo(proxyData.ip, proxyData.ip_checker || 'ip2location');
} else {
const localIp = await getPublicIP();
ipInfo = await getProxyInfo(localIp, 'ip2location');
let localIP = '';
if (import.meta.env.DEV) {
const {data} = await api.get('https://api64.ipify.org?format=json');
localIP = data.ip;
}
ipInfo = await getProxyInfo(localIP, 'ip2location');
}
if (!ipInfo?.ip) {
logger.error('ipInfo is empty');
return;
}
const fingerprint = await fetchWindowFingerprint(id, windowData.profile_id);
logger.info('fingerprint', id, windowData.profile_id, fingerprint);
if (chromePath) {
const chromePort = await portscanner.findAPortNotInUse(9222, 10222);
let finalProxy;
Expand All @@ -149,7 +140,6 @@ export async function openFingerprintWindow(id: number) {
finalProxy = proxyInstance.proxyUrl;
proxyServer = proxyInstance.proxyServer;
}
console.log(JSON.stringify(fingerprint));
const launchParamter = [
`--extended-parameters=${btoa(JSON.stringify(fingerprint))}`,
'--force-color-profile=srgb',
Expand Down
1 change: 0 additions & 1 deletion packages/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ app
* if you compile production app without publishing it to distribution server.
* Like `npm run compile` does. It's ok 😅
*/
logger.info(`env, is prod:, ${import.meta.env.PROD ? 'true' : 'false'}`);
if (import.meta.env.PROD) {
app
.whenReady()
Expand Down
45 changes: 42 additions & 3 deletions packages/main/src/services/commonService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {createLogger} from '../../../shared/utils/logger';
import {dataStore} from '../../../shared/utils/dataStore';
import {SERVICE_LOGGER_LABEL} from '../constants';
import {join} from 'path';
import {copyFileSync, writeFileSync} from 'fs';
import {copyFileSync, writeFileSync, readFileSync, readdir} from 'fs';
import type {DataStore, SettingOptions} from '../../../shared/types/common';
import {getSettings} from '../utils/get-settings';

Expand Down Expand Up @@ -39,6 +39,47 @@ export const initCommonService = () => {
return settings;
});

ipcMain.handle(
'common-fetch-logs',
async (_, module: 'Main' | 'Windows' | 'Proxy' | 'Services' | 'Api' = 'Main') => {
// read directory and get all folders
// read directory and get all files
const logFiles = await new Promise<string[]>((resolve, reject) => {
readdir(`logs/${module}`, (err, files) => {
if (err) {
reject(err);
} else {
resolve(files);
}
});
});
// read latest 10 files content
return logFiles.slice(-10).map(file => {
const logFile = `logs/${module}/${file}`;
const content = readFileSync(logFile, 'utf8');
const formatContent = content
.split('\n')
.map(line => {
const regex = /-\s*(info|warn|error):/;
let logLevel = 'info';
const match = line.match(regex);
if (match) {
logLevel = match[1];
}
return {
message: line,
level: logLevel,
};
})
.filter(line => line.message);
return {
name: file,
content: formatContent,
};
});
},
);

ipcMain.handle('common-save-settings', async (_, values: SettingOptions) => {
const userDataPath = app.getPath('userData');
const configFilePath = join(userDataPath, 'chrome-power-config.json');
Expand All @@ -50,8 +91,6 @@ export const initCommonService = () => {
}

return {};

return {};
});

ipcMain.handle('common-choose-path', async () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/preload/src/bridges/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ export const CommonBridge = {
const result = await ipcRenderer.invoke('common-save-settings', settings);
return result;
},
async getLogs(logModule: 'Main' | 'Windows' | 'Proxy' | 'Services' | 'Api') {
const result = await ipcRenderer.invoke('common-fetch-logs', logModule);
return result;
},
};
2 changes: 1 addition & 1 deletion packages/renderer/src/components/addable-select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const AddableSelect: React.FC<AddableSelectOptions> = ({
value={value}
filterOption={filterOption}
tagRender={tagRender}
placeholder={placeholder || 'Please select'}
placeholder={placeholder || ''}
// labelInValue={true}
onChange={onChange}
tokenSeparators={[',']}
Expand Down
5 changes: 2 additions & 3 deletions packages/renderer/src/components/navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {RootState} from '/@/store';
import {useSelector} from 'react-redux';
import {useEffect} from 'react';
import './index.css';
import Link from 'antd/es/typography/Link';
import React from 'react';
import { t } from 'i18next';

Expand Down Expand Up @@ -96,12 +95,12 @@ export default function Navigation() {
className="text-right "
span={9}
>
<Link
<a
className="text-xs underline underline-offset-4 text-orange-400 hover:text-orange-500"
href="https://www.chromepower.xyz/pricing"
>
{formattedMembership.expiredAt ? t('membership_renew') : t('membership_upgrade')}
</Link>
</a>
</Col>
</Row>
<Row className="mt-3 text-gray-500">
Expand Down
16 changes: 16 additions & 0 deletions packages/renderer/src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ i18n
window_edit_form_group: 'Group',
window_edit_form_proxy: 'Proxy',
window_edit_form_tags: 'Tags',
window_detail_create: 'Create',
window_detail_import: 'Import',
window_import_from_template: 'Import from template',
window_import_from_template_tip: 'Click to upload(Excel)',
window_import_from_template_download: 'Download template',
window_import_from_ads: 'Import AdsPower file',
window_import_from_ads_tip: 'Click to upload(Txt/Excel)',

proxy_check: 'Check',
proxy_new_proxy: 'New proxy',
Expand Down Expand Up @@ -90,6 +97,7 @@ i18n
menu_windows: 'Windows',
menu_proxy: 'Proxy',
menu_settings: 'Settings',
menu_logs: 'Running Logs',
menu_sync: 'Sync',

membership_renew: 'Renew',
Expand Down Expand Up @@ -140,6 +148,13 @@ i18n
window_edit_form_group: '分组',
window_edit_form_proxy: '代理',
window_edit_form_tags: '标签',
window_detail_create: '创建',
window_detail_import: '导入',
window_import_from_template: '从模板导入',
window_import_from_template_tip: '点击上传(Excel)',
window_import_from_template_download: '下载模板',
window_import_from_ads: '导入 AdsPower 文件',
window_import_from_ads_tip: '点击上传(Txt/Excel)',

proxy_check: '检查',
proxy_new_proxy: '新建代理',
Expand Down Expand Up @@ -183,6 +198,7 @@ i18n
menu_windows: '窗口管理',
menu_proxy: '代理设置',
menu_sync: '同步操作',
menu_logs: '运行日志',
menu_settings: '设置',

membership_renew: '续期',
Expand Down
4 changes: 4 additions & 0 deletions packages/renderer/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ body {
z-index: 1;
}

.h-full {
height: 100% !important;
}

/* 在CSS中 */
.draggable {
-webkit-app-region: drag;
Expand Down
4 changes: 4 additions & 0 deletions packages/renderer/src/pages/logs/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.log-container {
height: calc(100% - 64px);
overflow: auto;
}
Loading

0 comments on commit f56b2e0

Please sign in to comment.