mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-06 02:30:47 -08:00
feat: move logger folder to app userData folder, so it always gets write
This commit is contained in:
parent
94c0c32259
commit
d68f9f8de5
8 changed files with 10 additions and 29 deletions
|
|
@ -1,10 +1,13 @@
|
||||||
|
import { app } from 'electron';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { isDevelopmentOrTest } from './environment';
|
import { isDevelopmentOrTest } from './environment';
|
||||||
import { developmentSettingFolderName } from './fileNames';
|
import { developmentSettingFolderName } from './fileNames';
|
||||||
import { sourcePath } from './paths';
|
import { sourcePath } from './paths';
|
||||||
|
|
||||||
|
export const USER_DATA_FOLDER = app.getPath('userData');
|
||||||
export const SETTINGS_FOLDER = isDevelopmentOrTest
|
export const SETTINGS_FOLDER = isDevelopmentOrTest
|
||||||
? path.resolve(sourcePath, '..', developmentSettingFolderName)
|
? path.resolve(sourcePath, '..', developmentSettingFolderName)
|
||||||
: // eslint-disable-next-line @typescript-eslint/no-var-requires
|
: // eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
path.resolve(require('electron').app.getPath('userData'), 'settings');
|
path.resolve(USER_DATA_FOLDER, 'settings');
|
||||||
export const LOCAL_GIT_DIRECTORY = path.resolve(isDevelopmentOrTest ? path.join(sourcePath, '..') : process.resourcesPath, 'node_modules', 'dugite', 'git');
|
export const LOCAL_GIT_DIRECTORY = path.resolve(isDevelopmentOrTest ? path.join(sourcePath, '..') : process.resourcesPath, 'node_modules', 'dugite', 'git');
|
||||||
|
export const LOG_FOLDER = isDevelopmentOrTest ? path.resolve(sourcePath, '..', 'logs') : path.resolve(USER_DATA_FOLDER, 'logs');
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@ import os from 'os';
|
||||||
import { isDevelopmentOrTest } from './environment';
|
import { isDevelopmentOrTest } from './environment';
|
||||||
import { developmentWikiFolderName, localizationFolderName } from './fileNames';
|
import { developmentWikiFolderName, localizationFolderName } from './fileNames';
|
||||||
|
|
||||||
const isMac = process.platform === 'darwin';
|
|
||||||
|
|
||||||
/** src folder */
|
/** src folder */
|
||||||
export const sourcePath = path.resolve(__dirname, '..');
|
export const sourcePath = path.resolve(__dirname, '..');
|
||||||
export const buildResourcePath = path.resolve(sourcePath, '..', 'build-resources');
|
export const buildResourcePath = path.resolve(sourcePath, '..', 'build-resources');
|
||||||
|
|
@ -22,11 +20,6 @@ export const MENUBAR_ICON_PATH = path.resolve(isDevelopmentOrTest ? buildResourc
|
||||||
export const CHROME_ERROR_PATH = 'chrome-error://chromewebdata/';
|
export const CHROME_ERROR_PATH = 'chrome-error://chromewebdata/';
|
||||||
export const LOGIN_REDIRECT_PATH = 'http://localhost:3000/?code=';
|
export const LOGIN_REDIRECT_PATH = 'http://localhost:3000/?code=';
|
||||||
export const DESKTOP_PATH = path.join(os.homedir(), 'Desktop');
|
export const DESKTOP_PATH = path.join(os.homedir(), 'Desktop');
|
||||||
export const LOG_FOLDER = isDevelopmentOrTest
|
|
||||||
? path.resolve(sourcePath, '..', 'logs')
|
|
||||||
: isMac
|
|
||||||
? path.resolve(process.resourcesPath, '..', 'logs')
|
|
||||||
: path.resolve(os.homedir(), '.tg-note', 'logs');
|
|
||||||
export const ZX_FOLDER = isDevelopmentOrTest
|
export const ZX_FOLDER = isDevelopmentOrTest
|
||||||
? path.resolve(__dirname, '..', '..', 'node_modules', 'zx', 'zx.mjs')
|
? path.resolve(__dirname, '..', '..', 'node_modules', 'zx', 'zx.mjs')
|
||||||
: path.resolve(process.resourcesPath, 'node_modules', 'zx', 'zx.mjs');
|
: path.resolve(process.resourcesPath, 'node_modules', 'zx', 'zx.mjs');
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
|
/* eslint-disable @typescript-eslint/strict-boolean-expressions */
|
||||||
import { platform, type, networkInterfaces } from 'os';
|
import { platform, type, networkInterfaces } from 'os';
|
||||||
import ip from 'ipaddr.js';
|
import ip from 'ipaddr.js';
|
||||||
import { logger } from '@services/libs/log';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy from https://github.com/sindresorhus/internal-ip, to fi xsilverwind/default-gateway 's bug
|
* Copy from https://github.com/sindresorhus/internal-ip, to fi xsilverwind/default-gateway 's bug
|
||||||
|
|
@ -30,14 +29,10 @@ function findIp(gateway: string): string | undefined {
|
||||||
export async function internalIpV4(): Promise<string | undefined> {
|
export async function internalIpV4(): Promise<string | undefined> {
|
||||||
try {
|
try {
|
||||||
const defaultGatewayResult = await defaultGatewayV4();
|
const defaultGatewayResult = await defaultGatewayV4();
|
||||||
try {
|
|
||||||
logger.debug(`in internalIpV4() defaultGatewayResult is ${defaultGatewayResult ? JSON.stringify(defaultGatewayResult) : 'undefined'}`);
|
|
||||||
} catch {}
|
|
||||||
if (defaultGatewayResult?.gateway) {
|
if (defaultGatewayResult?.gateway) {
|
||||||
return findIp(defaultGatewayResult.gateway);
|
return findIp(defaultGatewayResult.gateway);
|
||||||
}
|
}
|
||||||
} catch {}
|
} catch {}
|
||||||
logger.warn('In internalIpV4() using fallback');
|
|
||||||
return 'localhost';
|
return 'localhost';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,8 +51,6 @@ async function defaultGatewayV4(): Promise<IDefaultGatewayInfo | undefined> {
|
||||||
gatewayQueryFileName = type() === 'OS400' ? 'ibmi' : 'sunos'; // AIX `netstat` output is compatible with Solaris
|
gatewayQueryFileName = type() === 'OS400' ? 'ibmi' : 'sunos'; // AIX `netstat` output is compatible with Solaris
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(`in defaultGatewayV4() plat is ${plat} , so gatewayQueryFileName is ${gatewayQueryFileName}`, { stack: new Error().stack });
|
|
||||||
|
|
||||||
switch (gatewayQueryFileName) {
|
switch (gatewayQueryFileName) {
|
||||||
case 'ibmi': {
|
case 'ibmi': {
|
||||||
const defaultGateway = await import('default-gateway/ibmi');
|
const defaultGateway = await import('default-gateway/ibmi');
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,10 @@ export function DeveloperTools(props: ISectionProps): JSX.Element {
|
||||||
async () =>
|
async () =>
|
||||||
await Promise.all([window.service.context.get('LOG_FOLDER'), window.service.context.get('SETTINGS_FOLDER')]).catch((error) => {
|
await Promise.all([window.service.context.get('LOG_FOLDER'), window.service.context.get('SETTINGS_FOLDER')]).catch((error) => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return [];
|
return [undefined, undefined];
|
||||||
}),
|
}),
|
||||||
[],
|
[undefined, undefined],
|
||||||
);
|
) as [string | undefined, string | undefined];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import winston, { format } from 'winston';
|
import winston, { format } from 'winston';
|
||||||
import { LOG_FOLDER } from '@/constants/paths';
|
import { LOG_FOLDER } from '@/constants/appPaths';
|
||||||
import RendererTransport from './rendererTransport';
|
import RendererTransport from './rendererTransport';
|
||||||
import 'winston-daily-rotate-file';
|
import 'winston-daily-rotate-file';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
|
|
||||||
import { LOG_FOLDER } from '@/constants/paths';
|
import { LOG_FOLDER } from '@/constants/appPaths';
|
||||||
|
|
||||||
export function getWikiLogFilePath(wikiName: string): string {
|
export function getWikiLogFilePath(wikiName: string): string {
|
||||||
const logFileName = wikiName.replace(/["*/:<>?\\|]/g, '_');
|
const logFileName = wikiName.replace(/["*/:<>?\\|]/g, '_');
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { defaultServerIP } from '@/constants/urls';
|
import { defaultServerIP } from '@/constants/urls';
|
||||||
import { internalIpV4 } from '@/helpers/ip';
|
import { internalIpV4 } from '@/helpers/ip';
|
||||||
import { logger } from './log';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get wiki address with local machine ip, so QR code will be correct, instead of get `0.0.0.0`
|
* get wiki address with local machine ip, so QR code will be correct, instead of get `0.0.0.0`
|
||||||
|
|
@ -10,13 +9,6 @@ import { logger } from './log';
|
||||||
export async function getLocalHostUrlWithActualIP(originalUrl: string): Promise<string> {
|
export async function getLocalHostUrlWithActualIP(originalUrl: string): Promise<string> {
|
||||||
const internalIp = await internalIpV4();
|
const internalIp = await internalIpV4();
|
||||||
const localHostUrlWithActualIP = originalUrl.replace(/((?:\d{1,3}\.){3}\d{1,3}|localhost)/, internalIp ?? defaultServerIP);
|
const localHostUrlWithActualIP = originalUrl.replace(/((?:\d{1,3}\.){3}\d{1,3}|localhost)/, internalIp ?? defaultServerIP);
|
||||||
logger.debug(
|
|
||||||
`Current available address: address() returns ${internalIp ?? 'undefined'}
|
|
||||||
originalUrl: ${originalUrl} , localHostUrlWithActualIP ${localHostUrlWithActualIP}`,
|
|
||||||
);
|
|
||||||
if (internalIp === undefined) {
|
|
||||||
logger.warn('internalIp is undefined');
|
|
||||||
}
|
|
||||||
return localHostUrlWithActualIP;
|
return localHostUrlWithActualIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { LOG_FOLDER } from '@/constants/paths';
|
import { LOG_FOLDER } from '@/constants/appPaths';
|
||||||
import serviceIdentifier from '@services/serviceIdentifier';
|
import serviceIdentifier from '@services/serviceIdentifier';
|
||||||
import { openNewGitHubIssue, debugInfo } from 'electron-util';
|
import { openNewGitHubIssue, debugInfo } from 'electron-util';
|
||||||
import { INativeService } from './interface';
|
import { INativeService } from './interface';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue