Skip to content

Commit

Permalink
chore: add more logging for #7735
Browse files Browse the repository at this point in the history
  • Loading branch information
evereq committed Apr 7, 2024
1 parent 35ed485 commit 4f6ef68
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ PLATFORM_WEBSITE_URL=https://gauzy.co
PLATFORM_WEBSITE_DOWNLOAD_URL=https://gauzy.co/downloads

# DB_ORM: typeorm | mikro-orm
DB_ORM=typeorm
DB_ORM=mikro-orm

# DB_TYPE: sqlite | postgres | better-sqlite3 | mysql
DB_TYPE=better-sqlite3
DB_TYPE=postgres
DB_SYNCHRONIZE=false

# DB Connection Parameters
DB_HOST=localhost
## DB Port. The default for PostgreSQL - 5432, for MySQL - 3306
DB_PORT=5432
DB_NAME=gauzy
DB_NAME=gauzy_prod
## DB Username. The default for PostgreSQL is 'postgres', for MySQL it's 'root'
DB_USER=postgres
DB_PASS=root
Expand Down
38 changes: 30 additions & 8 deletions apps/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,32 @@ const updater = new DesktopUpdater({
typeRelease: 'releases'
});

console.log('App is packaged', app.isPackaged);

const gauzyUIPath = app.isPackaged
? path.join(__dirname, '../data/ui/index.html')
: path.join(__dirname, './data/ui/index.html');
console.log('Gauzy UI path', gauzyUIPath);

const uiPath = path.join(__dirname, 'index.html');
console.log('UI path', uiPath);

const dirPath = app.isPackaged ? path.join(__dirname, '../data/ui') : path.join(__dirname, './data/ui');
console.log('Dir path', dirPath);

const timeTrackerUIPath = path.join(__dirname, 'index.html');

const pathWindow: IPathWindow = {
gauzyUi: app.isPackaged
? path.join(__dirname, '../data/ui/index.html')
: path.join(__dirname, './data/ui/index.html'),
ui: path.join(__dirname, 'index.html'),
dir: app.isPackaged ? path.join(__dirname, '../data/ui') : path.join(__dirname, './data/ui'),
timeTrackerUi: path.join(__dirname, 'index.html')
gauzyUi: gauzyUIPath,
ui: uiPath,
dir: dirPath,
timeTrackerUi: timeTrackerUIPath
};

const serverConfig: IServerConfig = new ServerConfig(new ReadWriteFile(pathWindow));
const readWriteFile = new ReadWriteFile(pathWindow);

const serverConfig: IServerConfig = new ServerConfig(readWriteFile);

const reverseProxy: ILocalServer = new ReverseProxy(serverConfig);
const reverseUiProxy: ILocalServer = new ReverseUiProxy(serverConfig);

Expand Down Expand Up @@ -259,9 +275,15 @@ const initializeConfig = async (val) => {
try {
serverConfig.setting = val;
serverConfig.update();
} catch (error) {
console.error('Error in initializeConfig for Server Config', error);
throw new AppError('MAINWININIT', error);
}

try {
await runMainWindow();
} catch (error) {
console.error('Error in initializeConfig', error);
console.error('Error in initializeConfig for running Main Window', error);
throw new AppError('MAINWININIT', error);
}
};
Expand Down
5 changes: 5 additions & 0 deletions packages/desktop-libs/src/lib/config/read-write-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ export class ReadWriteFile implements IReadWriteFile {
return;
}
try {
console.log(`Reading file ${this._path.gauzyUi}`);
return readFileSync(this._path.gauzyUi, 'utf8');
} catch (e) {
console.error('Cannot read file');
}
}

public get hasDirectoryAccess(): boolean {
try {
accessSync(this._path.dir, constants.W_OK);
Expand All @@ -27,11 +29,14 @@ export class ReadWriteFile implements IReadWriteFile {
return false;
}
}

public write(fileContent: string): void {
if (!this.hasDirectoryAccess) {
return;
}

try {
console.log(`Writing file ${this._path.gauzyUi}`);
writeFileSync(this._path.gauzyUi, fileContent);
} catch (error) {
console.log('Cannot change html file', error);
Expand Down
25 changes: 17 additions & 8 deletions packages/desktop-libs/src/lib/config/server-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,23 @@ export class ServerConfig implements IServerConfig {

public update(): void {
if (!this._readWriteFile) return;
// read original file
let fileContent = this._readWriteFile.read();
// replace all url in the file to normalize url file.
fileContent = this._replaceUrl(fileContent, this.apiUrl);
// remove duplicated content
fileContent = this._removeDuplicates(fileContent);
// override the original file
this._readWriteFile.write(fileContent);

try {
// read original file
let fileContent = this._readWriteFile.read();

// replace all url in the file to normalize url file.
fileContent = this._replaceUrl(fileContent, this.apiUrl);

// remove duplicated content
fileContent = this._removeDuplicates(fileContent);

// override the original file
this._readWriteFile.write(fileContent);
} catch (error) {
console.error('Cannot update initial Server file', error);
throw new Error(error);
}
}

private _replaceUrl(fileContent: string, newUrl: string): string {
Expand Down

0 comments on commit 4f6ef68

Please sign in to comment.