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
17
src/main.ts
17
src/main.ts
|
|
@ -6,7 +6,6 @@ import 'reflect-metadata';
|
|||
import './helpers/singleInstance';
|
||||
import './services/database/configSetting';
|
||||
import { app, ipcMain, powerMonitor, protocol } from 'electron';
|
||||
import settings from 'electron-settings';
|
||||
import unhandled from 'electron-unhandled';
|
||||
import fs from 'fs-extra';
|
||||
import inspector from 'node:inspector';
|
||||
|
|
@ -71,25 +70,17 @@ app.on('second-instance', async () => {
|
|||
app.on('activate', async () => {
|
||||
await windowService.open(WindowNames.main);
|
||||
});
|
||||
// make sure "Settings" file exists
|
||||
// if not, ignore this chunk of code
|
||||
// as using electron-settings before app.on('ready') and "Settings" is created
|
||||
// would return error
|
||||
// https://github.com/nathanbuchar/electron-settings/issues/111
|
||||
if (fs.existsSync(settings.file())) {
|
||||
void preferenceService.get('useHardwareAcceleration').then((useHardwareAcceleration) => {
|
||||
void preferenceService.get('useHardwareAcceleration').then((useHardwareAcceleration) => {
|
||||
if (!useHardwareAcceleration) {
|
||||
app.disableHardwareAcceleration();
|
||||
}
|
||||
});
|
||||
void preferenceService.get('ignoreCertificateErrors').then((ignoreCertificateErrors) => {
|
||||
});
|
||||
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> => {
|
||||
await app.whenReady();
|
||||
// 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 { 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 {
|
||||
logger.error('Setting file format bad: ' + jsonError.message);
|
||||
// fix empty content or empty string
|
||||
|
|
@ -25,3 +41,4 @@ settings.configure({
|
|||
dir: SETTINGS_FOLDER,
|
||||
atomicSave: !isWin,
|
||||
});
|
||||
fixEmptyAndErrorSettingFileOnStartUp();
|
||||
|
|
|
|||
|
|
@ -17,22 +17,6 @@ import { loadSqliteVss } from './sqlite-vss';
|
|||
|
||||
@injectable()
|
||||
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.
|
||||
// many operations has to be done in wikiWorker, so can be accessed by nodejs wiki in a sync way.
|
||||
// private readonly dbWorker?: ModuleThread<GitWorker>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue