-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centralize log file and refactor desktop logging
- Migrate to `electron-log` v5.X.X. - Save critical electron events to the log file. - Replaced remove `ElectronLog` type to `LogFunctions` type. - Remove `renderer.log` handling from desktop-runtime-error because since `electron-log` v5, it only writes to `main.log`. It's also best-practices to centralize logs for main and renderer process in Electron application for easier tracking and management. - Remove `I` prefix from related interfaces. - Move Logger interfaces to application layer as it's cross-cutting concern, keep the implementations in infrastructure layer. - Add all common log levels to Logger interface and implementations. This allows using this interface and reference to it in rest of Electron main/preloader processes, abstracting `electron-log` completely. - Add `useLogger` compositional hook to make it easier to consume logger in Vue components with unified and Vue idiomatic way. - Refactor `WindowVariables` to remove unnecessarily nullable properties. - Add documentation to clarify differences between the desktop and web versions, listing features available in each distribution to help in decision-making.
- Loading branch information
1 parent
8f5d7ed
commit 67ccd73
Showing
40 changed files
with
347 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Desktop vs. Web Features | ||
|
||
This table outlines the differences between the desktop and web versions of `privacy.sexy`. | ||
|
||
| Feature | Desktop | Web | | ||
| ------- |---------|-----| | ||
| [Usage without installation](#usage-without-installation) | 🔴 Not available | 🟢 Available | | ||
| [Offline usage](#offline-usage) | 🟢 Available | 🟡 Partially available | | ||
| [Auto-updates](#auto-updates) | 🟢 Available | 🟢 Available | | ||
| [Logging](#logging) | 🟢 Available | 🔴 Not available | | ||
| [Script execution](#script-execution) | 🟢 Available | 🔴 Not available | | ||
|
||
## Feature Descriptions | ||
|
||
### Usage without installation | ||
|
||
The web version can be used directly in a browser without any installation, whereas the desktop version requires downloading and installing the software. | ||
|
||
> **Note for Linux:** For Linux users, privacy.sexy is available as an AppImage, which is a portable format that does not require traditional installation. This means Linux users can use the desktop version without installation, similar to the web version. | ||
### Offline usage | ||
|
||
Once loaded, the web version can be used offline. The desktop version inherently supports offline usage. | ||
|
||
### Auto-updates | ||
|
||
Both versions automatically update to ensure you have the latest features and security enhancements. | ||
|
||
### Logging | ||
|
||
The desktop version supports logging of activities to aid in troubleshooting. This feature is not available in the web version. | ||
|
||
### Script execution | ||
|
||
Direct execution of scripts is possible in the desktop version, offering a more integrated experience. | ||
This functionality is not present in the web version due to browser limitations. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface Logger { | ||
info(...params: unknown[]): void; | ||
warn(...params: unknown[]): void; | ||
error(...params: unknown[]): void; | ||
debug(...params: unknown[]): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { Logger } from '@/application/Common/Log/Logger'; | ||
|
||
export interface LoggerFactory { | ||
readonly logger: Logger; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
import { ILogger } from './ILogger'; | ||
import { Logger } from '@/application/Common/Log/Logger'; | ||
|
||
export class ConsoleLogger implements ILogger { | ||
constructor(private readonly consoleProxy: Partial<Console> = console) { | ||
export class ConsoleLogger implements Logger { | ||
constructor(private readonly consoleProxy: ConsoleLogFunctions = globalThis.console) { | ||
if (!consoleProxy) { // do not trust strictNullChecks for global objects | ||
throw new Error('missing console'); | ||
} | ||
} | ||
|
||
public info(...params: unknown[]): void { | ||
const logFunction = this.consoleProxy?.info; | ||
if (!logFunction) { | ||
throw new Error('missing "info" function'); | ||
} | ||
logFunction.call(this.consoleProxy, ...params); | ||
this.consoleProxy.info(...params); | ||
} | ||
|
||
public warn(...params: unknown[]): void { | ||
this.consoleProxy.warn(...params); | ||
} | ||
|
||
public error(...params: unknown[]): void { | ||
this.consoleProxy.error(...params); | ||
} | ||
|
||
public debug(...params: unknown[]): void { | ||
this.consoleProxy.debug(...params); | ||
} | ||
} | ||
|
||
interface ConsoleLogFunctions extends Partial<Console> { | ||
readonly info: Console['info']; | ||
readonly warn: Console['warn']; | ||
readonly error: Console['error']; | ||
readonly debug: Console['debug']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
import { ElectronLog } from 'electron-log'; | ||
import { ILogger } from './ILogger'; | ||
import log from 'electron-log/main'; | ||
import { Logger } from '@/application/Common/Log/Logger'; | ||
import type { LogFunctions } from 'electron-log'; | ||
|
||
// Using plain-function rather than class so it can be used in Electron's context-bridging. | ||
export function createElectronLogger(logger: Partial<ElectronLog>): ILogger { | ||
if (!logger) { | ||
throw new Error('missing logger'); | ||
} | ||
export function createElectronLogger(logger: LogFunctions = log): Logger { | ||
return { | ||
info: (...params) => { | ||
if (!logger.info) { | ||
throw new Error('missing "info" function'); | ||
} | ||
logger.info(...params); | ||
}, | ||
info: (...params) => logger.info(...params), | ||
debug: (...params) => logger.debug(...params), | ||
warn: (...params) => logger.warn(...params), | ||
error: (...params) => logger.error(...params), | ||
}; | ||
} | ||
|
||
export const ElectronLogger = createElectronLogger(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import { ILogger } from './ILogger'; | ||
import { Logger } from '@/application/Common/Log/Logger'; | ||
|
||
export class NoopLogger implements ILogger { | ||
export class NoopLogger implements Logger { | ||
public info(): void { /* NOOP */ } | ||
|
||
public warn(): void { /* NOOP */ } | ||
|
||
public error(): void { /* NOOP */ } | ||
|
||
public debug(): void { /* NOOP */ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { OperatingSystem } from '@/domain/OperatingSystem'; | ||
import { ISystemOperations } from '@/infrastructure/SystemOperations/ISystemOperations'; | ||
import { ILogger } from '@/infrastructure/Log/ILogger'; | ||
import { Logger } from '@/application/Common/Log/Logger'; | ||
|
||
/* Primary entry point for platform-specific injections */ | ||
export interface WindowVariables { | ||
readonly isDesktop?: boolean; | ||
readonly isDesktop: boolean; | ||
readonly system?: ISystemOperations; | ||
readonly os?: OperatingSystem; | ||
readonly log?: ILogger; | ||
readonly log: Logger; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/presentation/bootstrapping/Modules/AppInitializationLogger.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { LoggerFactory } from '@/application/Common/Log/LoggerFactory'; | ||
import { ClientLoggerFactory } from '@/presentation/bootstrapping/ClientLoggerFactory'; | ||
|
||
export function useLogger(factory: LoggerFactory = ClientLoggerFactory.Current) { | ||
return { | ||
log: factory.logger, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.