mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2025-12-06 02:30:47 -08:00
parent
babb7898fb
commit
164bae83bc
3 changed files with 28 additions and 36 deletions
31
src/main.ts
31
src/main.ts
|
|
@ -6,7 +6,6 @@ import 'reflect-metadata';
|
||||||
import './helpers/singleInstance';
|
import './helpers/singleInstance';
|
||||||
import './services/database/configSetting';
|
import './services/database/configSetting';
|
||||||
import { app, ipcMain, powerMonitor, protocol } from 'electron';
|
import { app, ipcMain, powerMonitor, protocol } from 'electron';
|
||||||
import settings from 'electron-settings';
|
|
||||||
import unhandled from 'electron-unhandled';
|
import unhandled from 'electron-unhandled';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import inspector from 'node:inspector';
|
import inspector from 'node:inspector';
|
||||||
|
|
@ -71,25 +70,17 @@ app.on('second-instance', async () => {
|
||||||
app.on('activate', async () => {
|
app.on('activate', async () => {
|
||||||
await windowService.open(WindowNames.main);
|
await windowService.open(WindowNames.main);
|
||||||
});
|
});
|
||||||
// make sure "Settings" file exists
|
void preferenceService.get('useHardwareAcceleration').then((useHardwareAcceleration) => {
|
||||||
// if not, ignore this chunk of code
|
if (!useHardwareAcceleration) {
|
||||||
// as using electron-settings before app.on('ready') and "Settings" is created
|
app.disableHardwareAcceleration();
|
||||||
// would return error
|
}
|
||||||
// https://github.com/nathanbuchar/electron-settings/issues/111
|
});
|
||||||
if (fs.existsSync(settings.file())) {
|
void preferenceService.get('ignoreCertificateErrors').then((ignoreCertificateErrors) => {
|
||||||
void preferenceService.get('useHardwareAcceleration').then((useHardwareAcceleration) => {
|
if (ignoreCertificateErrors) {
|
||||||
if (!useHardwareAcceleration) {
|
// https://www.electronjs.org/docs/api/command-line-switches
|
||||||
app.disableHardwareAcceleration();
|
app.commandLine.appendSwitch('ignore-certificate-errors');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
void preferenceService.get('ignoreCertificateErrors').then((ignoreCertificateErrors) => {
|
|
||||||
if (ignoreCertificateErrors) {
|
|
||||||
// https://www.electronjs.org/docs/api/command-line-switches
|
|
||||||
app.commandLine.appendSwitch('ignore-certificate-errors');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const commonInit = async (): Promise<void> => {
|
const commonInit = async (): Promise<void> => {
|
||||||
await app.whenReady();
|
await app.whenReady();
|
||||||
// if user want a menubar, we create a new window for that
|
// if user want a menubar, we create a new window for that
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,22 @@ import settings from 'electron-settings';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import { isWin } from '../../helpers/system';
|
import { isWin } from '../../helpers/system';
|
||||||
|
|
||||||
|
export function fixEmptyAndErrorSettingFileOnStartUp() {
|
||||||
|
// Fix sometimes JSON is malformed https://github.com/nathanbuchar/electron-settings/issues/160
|
||||||
|
if (fs.existsSync(settings.file())) {
|
||||||
|
try {
|
||||||
|
logger.info('Checking Setting file format.');
|
||||||
|
fs.readJsonSync(settings.file());
|
||||||
|
logger.info('Setting file format good.');
|
||||||
|
} catch (jsonError) {
|
||||||
|
fixSettingFileWhenError(jsonError as Error);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// create an empty JSON file if not exist, to prevent error when reading it. fixes https://github.com/tiddly-gittly/TidGi-Desktop/issues/507
|
||||||
|
fs.writeJSONSync(settings.file(), {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function fixSettingFileWhenError(jsonError: Error, providedJSONContent?: string): void {
|
export function fixSettingFileWhenError(jsonError: Error, providedJSONContent?: string): void {
|
||||||
logger.error('Setting file format bad: ' + jsonError.message);
|
logger.error('Setting file format bad: ' + jsonError.message);
|
||||||
// fix empty content or empty string
|
// fix empty content or empty string
|
||||||
|
|
@ -25,3 +41,4 @@ settings.configure({
|
||||||
dir: SETTINGS_FOLDER,
|
dir: SETTINGS_FOLDER,
|
||||||
atomicSave: !isWin,
|
atomicSave: !isWin,
|
||||||
});
|
});
|
||||||
|
fixEmptyAndErrorSettingFileOnStartUp();
|
||||||
|
|
|
||||||
|
|
@ -17,22 +17,6 @@ import { loadSqliteVss } from './sqlite-vss';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class DatabaseService implements IDatabaseService {
|
export class DatabaseService implements IDatabaseService {
|
||||||
constructor() {
|
|
||||||
// Fix sometimes JSON is malformed https://github.com/nathanbuchar/electron-settings/issues/160
|
|
||||||
if (fs.existsSync(settings.file())) {
|
|
||||||
try {
|
|
||||||
logger.info('Checking Setting file format.');
|
|
||||||
fs.readJsonSync(settings.file());
|
|
||||||
logger.info('Setting file format good.');
|
|
||||||
} catch (jsonError) {
|
|
||||||
fixSettingFileWhenError(jsonError as Error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// create an empty JSON file if not exist, to prevent error when reading it. fixes https://github.com/tiddly-gittly/TidGi-Desktop/issues/507
|
|
||||||
fs.writeJSONSync(settings.file(), {});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// tiddlywiki require methods to be sync, so direct run them in the main process. But later we can use worker_thread to run heavier search queries, as a readonly slave db, and do some data sync between them.
|
// tiddlywiki require methods to be sync, so direct run them in the main process. But later we can use worker_thread to run heavier search queries, as a readonly slave db, and do some data sync between them.
|
||||||
// many operations has to be done in wikiWorker, so can be accessed by nodejs wiki in a sync way.
|
// many operations has to be done in wikiWorker, so can be accessed by nodejs wiki in a sync way.
|
||||||
// private readonly dbWorker?: ModuleThread<GitWorker>;
|
// private readonly dbWorker?: ModuleThread<GitWorker>;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue