Skip to content

Commit

Permalink
fix: log on prod
Browse files Browse the repository at this point in the history
  • Loading branch information
kiomarzsss committed May 2, 2024
1 parent 80a3954 commit b05c933
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 37 deletions.
6 changes: 2 additions & 4 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ as you may be familiar with electron already.
we need to use [IPC](https://www.electronjs.org/docs/latest/tutorial/ipc) in order to send and receive data between main and renderer.
checkout `src/main/ipc.ts` and `src/renderer/index.tsx` for an in action example.

## User Settings
## Notes

user settings is being handled by [electron-settings](https://github.com/nathanbuchar/electron-settings) but i did'nt enabled `enableRemoteModule` for security reasons. ([read more](https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31)).

so for `main` just use `electron-settings` directly. and for `renderer` use settings.ts module(`src/renderer/lib/settings.ts`)(asynchronously!)
- `wp` refers to `warp-plus` in source.
8 changes: 4 additions & 4 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
اپ متن‌باز #Oblivion به‌عنوان یکی‌از امن‌ترین و مطمئن‌ترین VPNها، در روزهای پراختلال اخیر نقش مهمی برای دسترسی آزاد
کاربران ایرانی به اینترنت ایفا کرده.

- اپ‌های Oblivion و Oblivion Deskop و همینطور هسته Warp-Plus متن‌باز هستن و سورسشون در گیت‌هاب قرار گرفته، ضمن اینکه
بیلد پروژه‌ها به‌صورت خودکار توسط گیت‌هاب اکشن انجام می‌شن.
- وارپ به‌وسیله رمزنگاری مقدار بیشتری از ترافیک خروجی از دستگاهتون، اجازه نمیده هیچ‌کس در کار شما سرک بکشه.
- اپ‌های Oblivion و Oblivion Deskop و همینطور هسته Warp-Plus متن‌باز هستن و سورسشون در گیت‌هاب قرار گرفته، ضمن اینکه
بیلد پروژه‌ها به‌صورت خودکار توسط گیت‌هاب اکشن انجام می‌شن.
- وارپ به‌وسیله رمزنگاری مقدار بیشتری از ترافیک خروجی از دستگاهتون، اجازه نمیده هیچ‌کس در کار شما سرک بکشه.

![virustotal.png](screenshot/virustotal.png)
![virustotal.png](screenshot/virustotal.png)
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions release/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/main/ipcListeners/log.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ipcMain } from 'electron';
import { doesFileExist } from '../lib/utils';
import { readLogFile } from '../lib/log';
import { readLogFile, wpLogPath } from '../lib/log';

ipcMain.on('log', async (event, arg) => {
const bool = await doesFileExist('log.txt');
const bool = await doesFileExist(wpLogPath);
if (bool) {
const data = await readLogFile();
event.reply('log', data);
Expand Down
4 changes: 2 additions & 2 deletions src/main/ipcListeners/wp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import treeKill from 'tree-kill';
import path from 'path';
import settings from 'electron-settings';
import { countries, defaultSettings } from '../../defaultSettings';
import { appendToLogFile, writeToLogFile } from '../lib/log';
import { appendToLogFile, wpLogPath, writeToLogFile } from '../lib/log';
import { doesFileExist, isDev } from '../lib/utils';
import { disableProxy, enableProxy } from '../lib/proxy';

Expand Down Expand Up @@ -122,7 +122,7 @@ ipcMain.on('wp-start', async (event, arg) => {
enableProxy();
}
// write to log file
const tmp = await doesFileExist('log.txt');
const tmp = await doesFileExist(wpLogPath);
if (!tmp) {
writeToLogFile(strData);
} else {
Expand Down
12 changes: 8 additions & 4 deletions src/main/lib/log.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const fs = require('fs');
import { app } from 'electron';
import path from 'path';
import fs from 'fs';

export const wpLogPath = path.join(app.getPath('logs'), 'warp-plus.log');

export function readLogFile() {
return new Promise((resolve, reject) => {
fs.readFile('log.txt', 'utf8', (err: any, data: any) => {
fs.readFile(wpLogPath, 'utf8', (err: any, data: any) => {
if (err) {
reject(err);
} else {
Expand All @@ -14,7 +18,7 @@ export function readLogFile() {

export function writeToLogFile(message: string) {
return new Promise((resolve, reject) => {
fs.writeFile('log.txt', message + '\n', (err: any) => {
fs.writeFile(wpLogPath, message + '\n', (err: any) => {
if (err) {
reject(err);
} else {
Expand All @@ -26,7 +30,7 @@ export function writeToLogFile(message: string) {

export function appendToLogFile(message: string) {
return new Promise((resolve, reject) => {
fs.appendFile('log.txt', message + '\n', (err: any) => {
fs.appendFile(wpLogPath, message + '\n', (err: any) => {
if (err) {
reject(err);
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import './ipc';
import { isDev, removeFileIfExists } from './lib/utils';
import { openDevToolsByDefault, useCustomWindowXY } from './dxConfig';
import { disableProxy } from './lib/proxy';
import { wpLogPath } from './lib/log';

let mainWindow: BrowserWindow | null = null;

Expand All @@ -25,9 +26,7 @@ if (process.env.NODE_ENV === 'production') {
sourceMapSupport.install();
}

(async () => {
await removeFileIfExists('log.txt');
})();
removeFileIfExists(wpLogPath);

const isDebug = process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true';

Expand Down
28 changes: 14 additions & 14 deletions src/renderer/pages/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function Index() {
ip: string;
}>({
countryCode: false,
ip: '127.0.0.1'
ip: '127.0.0.1',
});
const [shownIpData, setShownIpData] = useState(true);
const [online, setOnline] = useState(true);
Expand Down Expand Up @@ -85,9 +85,9 @@ export default function Index() {
style: {
borderRadius: '10px',
background: value === 'dark' ? '#535353' : '#242424',
color: '#F4F5FB'
}
}
color: '#F4F5FB',
},
},
);
connectedToIrIPOnceDisplayed = true;
});
Expand All @@ -107,7 +107,7 @@ export default function Index() {
const getLoc = locationLine ? locationLine.split('=')[1].toLowerCase() : false;
setIpInfo({
countryCode: getLoc,
ip: getIp
ip: getIp,
});
})
.catch((error) => {
Expand All @@ -128,8 +128,8 @@ export default function Index() {
style: {
borderRadius: '10px',
background: value === 'dark' ? '#535353' : '#242424',
color: '#F4F5FB'
}
color: '#F4F5FB',
},
});
});
};
Expand All @@ -138,7 +138,7 @@ export default function Index() {
settings.get('ipData').then((value) => {
if (typeof value === 'undefined' || value) {
getIpLocation();
setTimeout(function() {
setTimeout(function () {
if (ipInfo?.countryCode === 'ir') {
ipToast().then();
}
Expand Down Expand Up @@ -283,7 +283,7 @@ export default function Index() {
className={classNames(
'switch',
isConnected ? 'active' : '',
isLoading ? 'isLoading' : ''
isLoading ? 'isLoading' : '',
)}
onClick={onChange}
>
Expand All @@ -296,7 +296,7 @@ export default function Index() {
<div
className={classNames(
'status',
isConnected && ipInfo?.countryCode && !isLoading ? 'active' : ''
isConnected && ipInfo?.countryCode && !isLoading ? 'active' : '',
)}
>
{status}
Expand All @@ -306,14 +306,14 @@ export default function Index() {
'ip',
isConnected && ipInfo?.countryCode && !isLoading
? 'connected'
: ''
: '',
)}
onClick={() => {
setIpInfo({
countryCode: false,
ip: '127.0.0.1'
ip: '127.0.0.1',
});
setTimeout(function() {
setTimeout(function () {
getIpLocation();
}, 5000);
}}
Expand All @@ -331,7 +331,7 @@ export default function Index() {
svg
style={{
width: '17px',
height: '12px'
height: '12px',
}}
/>
</>
Expand Down

0 comments on commit b05c933

Please sign in to comment.