Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP-2079] Merge enums used in invoking methods between main and renderer #1492

Merged
merged 7 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions packages/app/src/__deprecated__/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ import registerCopyFileListener from "App/__deprecated__/main/functions/register
import registerWriteGzipListener from "App/__deprecated__/main/functions/register-write-gzip-listener"
import registerRmdirListener from "App/__deprecated__/main/functions/register-rmdir-listener"
import registerArchiveFilesListener from "App/__deprecated__/main/functions/register-archive-files-listener"
import registerReadFileListener from "App/file-system/listeners/read-file.listener"
import createDownloadListenerRegistrar from "App/__deprecated__/main/functions/create-download-listener-registrar"
import registerEncryptFileListener from "App/file-system/listeners/encrypt-file.listener"
import registerDecryptFileListener from "App/file-system/listeners/decrypt-file.listener"
import registerUnlinkFileListener from "App/file-system/listeners/unlink-file.listener"
import {
registerDownloadHelpHandler,
removeDownloadHelpHandler,
Expand Down Expand Up @@ -196,10 +192,6 @@ const createWindow = async () => {
registerRmdirListener()
registerWriteGzipListener()
registerArchiveFilesListener()
registerEncryptFileListener()
registerReadFileListener()
registerUnlinkFileListener()
registerDecryptFileListener()
registerMetadataAllGetValueListener()
registerMetadataGetValueListener()
registerMetadataSetValueListener()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,12 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

export const ControllerPrefix = "analytic-data-tracker"

export enum IpcAnalyticDataTrackerEvent {
Track = "track",
TrackUnique = "track-unique",
TrackWithoutDeviceCheck = "track-without-device-check",
TrackUniqueWithoutDeviceCheck = "track-unique-without-device-check",
ToggleTracking = "toggle-tracking",
SetExternalUsageDevice = "set-external-usage-device",
SetVisitorMetadata = "set-visitor-metadata",
}

export enum IpcAnalyticDataTrackerRequest {
Track = "analytic-data-tracker-track",
TrackUnique = "analytic-data-tracker-track-unique",
TrackWithoutDeviceCheck = "analytic-data-tracker-track-without-device-check",
TrackUniqueWithoutDeviceCheck = "analytic-data-tracker-track-unique-without-device-check",
ToggleTracking = "analytic-data-tracker-toggle-tracking",
SetExternalUsageDevice = "analytic-data-tracker-set-external-usage-device",
SetVisitorMetadata = "analytic-data-tracker-set-visitor-metadata",
Track = "analytic_track",
TrackUnique = "analytic_track-unique",
TrackWithoutDeviceCheck = "analytic_track-without-device-check",
TrackUniqueWithoutDeviceCheck = "analytic_track-unique-without-device-check",
ToggleTracking = "analytic_toggle-tracking",
SetExternalUsageDevice = "analytic_set-external-usage-device",
SetVisitorMetadata = "analytic_set-visitor-metadata",
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import { Controller, IpcEvent } from "App/core/decorators"
import {
ControllerPrefix,
IpcAnalyticDataTrackerEvent,
} from "App/analytic-data-tracker/constants"
import { IpcEvent } from "App/core/decorators"
import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants"
import {
AnalyticDataTrackerClass,
VisitorMetadata,
} from "App/analytic-data-tracker/services"
import { TrackEvent } from "App/analytic-data-tracker/types"

@Controller(ControllerPrefix)
export class AnalyticDataTrackerController {
constructor(private tracker: AnalyticDataTrackerClass) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
*/

import { ipcRenderer } from "electron-better-ipc"
import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants"
import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants"

export const setExternalUsageDeviceRequest = async (
flag: boolean
): Promise<void> => {
return ipcRenderer.callMain(
IpcAnalyticDataTrackerRequest.SetExternalUsageDevice,
IpcAnalyticDataTrackerEvent.SetExternalUsageDevice,
flag
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*/

import { ipcRenderer } from "electron-better-ipc"
import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants"
import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants"
import { VisitorMetadata } from "App/analytic-data-tracker/services"

export const setVisitorMetadataRequest = async (
visitorMetadata: VisitorMetadata
): Promise<void> => {
return ipcRenderer.callMain(
IpcAnalyticDataTrackerRequest.SetVisitorMetadata,
IpcAnalyticDataTrackerEvent.SetVisitorMetadata,
visitorMetadata
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

import { ipcRenderer } from "electron-better-ipc"
import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants"
import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants"

export const toggleTrackingRequest = async (flag: boolean): Promise<void> => {
return ipcRenderer.callMain(IpcAnalyticDataTrackerRequest.ToggleTracking, flag)
return ipcRenderer.callMain(IpcAnalyticDataTrackerEvent.ToggleTracking, flag)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*/

import { ipcRenderer } from "electron-better-ipc"
import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants"
import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants"
import { TrackEvent } from "App/analytic-data-tracker/types"

export const trackUniqueWithoutDeviceCheckRequest = async (
event: TrackEvent
): Promise<void> => {
return ipcRenderer.callMain(
IpcAnalyticDataTrackerRequest.TrackUniqueWithoutDeviceCheck,
IpcAnalyticDataTrackerEvent.TrackUniqueWithoutDeviceCheck,
event
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

import { ipcRenderer } from "electron-better-ipc"
import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants"
import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants"
import { TrackEvent } from "App/analytic-data-tracker/types"

export const trackUniqueRequest = async (event: TrackEvent): Promise<void> => {
return ipcRenderer.callMain(IpcAnalyticDataTrackerRequest.TrackUnique, event)
return ipcRenderer.callMain(IpcAnalyticDataTrackerEvent.TrackUnique, event)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*/

import { ipcRenderer } from "electron-better-ipc"
import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants"
import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants"
import { TrackEvent } from "App/analytic-data-tracker/types"

export const trackWithoutDeviceCheckRequest = async (
event: TrackEvent
): Promise<void> => {
return ipcRenderer.callMain(
IpcAnalyticDataTrackerRequest.TrackWithoutDeviceCheck,
IpcAnalyticDataTrackerEvent.TrackWithoutDeviceCheck,
event
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/

import { ipcRenderer } from "electron-better-ipc"
import { IpcAnalyticDataTrackerRequest } from "App/analytic-data-tracker/constants"
import { IpcAnalyticDataTrackerEvent } from "App/analytic-data-tracker/constants"
import { TrackEvent } from "App/analytic-data-tracker/types"

export const trackRequest = async (event: TrackEvent): Promise<void> => {
return ipcRenderer.callMain(IpcAnalyticDataTrackerRequest.Track, event)
return ipcRenderer.callMain(IpcAnalyticDataTrackerEvent.Track, event)
}
12 changes: 3 additions & 9 deletions packages/app/src/backup/constants/controller.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
export const ControllerPrefix = "backup"

export enum IpcBackupEvent {
LoadBackups = "load-backups",
CreateBackup = "create-backup",
RestoreBackup = "restore-backup",
}

export enum IpcBackupRequest {
LoadBackups = "backup-load-backups",
CreateBackup = "backup-create-backup",
RestoreBackup = "backup-restore-backup",
LoadBackups = "backup_load-backups",
CreateBackup = "backup_create-backup",
RestoreBackup = "backup_restore-backup",
}
9 changes: 2 additions & 7 deletions packages/app/src/backup/controllers/backup.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import { Controller, IpcEvent } from "App/core/decorators"
import { IpcEvent } from "App/core/decorators"

Check warning on line 6 in packages/app/src/backup/controllers/backup.controller.ts

View check run for this annotation

Codecov / codecov/patch

packages/app/src/backup/controllers/backup.controller.ts#L6

Added line #L6 was not covered by tests
import { ResultObject } from "App/core/builder"
import { Backup } from "App/backup/dto"
import {
BackupError,
ControllerPrefix,
IpcBackupEvent,
} from "App/backup/constants"
import { BackupError, IpcBackupEvent } from "App/backup/constants"

Check warning on line 9 in packages/app/src/backup/controllers/backup.controller.ts

View check run for this annotation

Codecov / codecov/patch

packages/app/src/backup/controllers/backup.controller.ts#L9

Added line #L9 was not covered by tests
import {
BackupCreateService,
BackupRestoreService,
LoadBackupService,
} from "App/backup/services"
import { CreateDeviceBackup, RestoreDeviceBackup } from "App/backup/types"

@Controller(ControllerPrefix)
export class BackupController {
constructor(
private backupCreateService: BackupCreateService,
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/backup/requests/create-backup.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import { ipcRenderer } from "electron-better-ipc"
import { ResultObject } from "App/core/builder"
import { IpcBackupRequest } from "App/backup/constants"
import { IpcBackupEvent } from "App/backup/constants"
import { CreateDeviceBackup } from "App/backup/types"

export const createBackupRequest = async (
options: CreateDeviceBackup
): Promise<ResultObject<string[]>> => {
return ipcRenderer.callMain(IpcBackupRequest.CreateBackup, options)
return ipcRenderer.callMain(IpcBackupEvent.CreateBackup, options)
}
4 changes: 2 additions & 2 deletions packages/app/src/backup/requests/load-backups.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import { ipcRenderer } from "electron-better-ipc"
import { ResultObject } from "App/core/builder"
import { IpcBackupRequest } from "App/backup/constants"
import { IpcBackupEvent } from "App/backup/constants"
import { Backup } from "App/backup/dto"

export const loadBackupsRequest = async (
options: string
): Promise<ResultObject<Backup[]>> => {
return ipcRenderer.callMain(IpcBackupRequest.LoadBackups, options)
return ipcRenderer.callMain(IpcBackupEvent.LoadBackups, options)
}
4 changes: 2 additions & 2 deletions packages/app/src/backup/requests/restore-backup.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import { ipcRenderer } from "electron-better-ipc"
import { ResultObject } from "App/core/builder"
import { BackupError, IpcBackupRequest } from "App/backup/constants"
import { BackupError, IpcBackupEvent } from "App/backup/constants"
import { RestoreDeviceBackup } from "App/backup/types"

export const restoreBackupRequest = async (
options: RestoreDeviceBackup
): Promise<ResultObject<boolean, BackupError>> => {
return ipcRenderer.callMain(IpcBackupRequest.RestoreBackup, options)
return ipcRenderer.callMain(IpcBackupEvent.RestoreBackup, options)
}
14 changes: 3 additions & 11 deletions packages/app/src/contacts/constants/controller.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

export const ControllerPrefix = "contact"

export enum IpcContactEvent {
CreateContact = "create-contact",
EditContact = "edit-contact",
DeleteContacts = "delete-contacts",
}

export enum IpcContactRequest {
CreateContact = "contact-create-contact",
EditContact = "contact-edit-contact",
DeleteContacts = "contact-delete-contacts",
CreateContact = "contact_create-contact",
EditContact = "contact_edit-contact",
DeleteContacts = "contact_delete-contacts",
}
5 changes: 2 additions & 3 deletions packages/app/src/contacts/controllers/contact.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md
*/

import { Controller, IpcEvent } from "App/core/decorators"
import { IpcEvent } from "App/core/decorators"

Check warning on line 6 in packages/app/src/contacts/controllers/contact.controller.ts

View check run for this annotation

Codecov / codecov/patch

packages/app/src/contacts/controllers/contact.controller.ts#L6

Added line #L6 was not covered by tests
import { ContactService } from "App/contacts/services"
import { RequestResponse } from "App/core/types/request-response.interface"
import { ControllerPrefix, IpcContactEvent } from "App/contacts/constants"
import { IpcContactEvent } from "App/contacts/constants"

Check warning on line 9 in packages/app/src/contacts/controllers/contact.controller.ts

View check run for this annotation

Codecov / codecov/patch

packages/app/src/contacts/controllers/contact.controller.ts#L9

Added line #L9 was not covered by tests
import { Contact, ContactID } from "App/contacts/reducers"

@Controller(ControllerPrefix)
export class ContactController {
constructor(private contactService: ContactService) {}

Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/contacts/requests/create-contact.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
*/

import { ipcRenderer } from "electron-better-ipc"
import { IpcContactRequest } from "App/contacts/constants"
import { IpcContactEvent } from "App/contacts/constants"
import { Contact, NewContact } from "App/contacts/reducers/contacts.interface"
import { RequestResponse } from "App/core/types/request-response.interface"

export const createContactRequest = async (
newContact: NewContact
): Promise<RequestResponse<Contact>> => {
return ipcRenderer.callMain(IpcContactRequest.CreateContact, newContact)
return ipcRenderer.callMain(IpcContactEvent.CreateContact, newContact)
}
7 changes: 2 additions & 5 deletions packages/app/src/contacts/requests/delete-contacts.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
*/

import { ipcRenderer } from "electron-better-ipc"
import { IpcContactRequest } from "App/contacts/constants"
import { IpcContactEvent } from "App/contacts/constants"
import { ContactID } from "App/contacts/reducers/contacts.interface"
import { RequestResponse } from "App/core/types/request-response.interface"

export const deleteContactsRequest = async (
contactIds: ContactID[]
): Promise<RequestResponse<ContactID[]>> => {
return await ipcRenderer.callMain(
IpcContactRequest.DeleteContacts,
contactIds
)
return await ipcRenderer.callMain(IpcContactEvent.DeleteContacts, contactIds)
}
8 changes: 5 additions & 3 deletions packages/app/src/contacts/requests/edit-contact.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
*/

import { ipcRenderer } from "electron-better-ipc"
import { IpcContactRequest } from "App/contacts/constants"
import { IpcContactEvent } from "App/contacts/constants"
import { Contact } from "App/contacts/reducers/contacts.interface"
import { RequestResponse } from "App/core/types/request-response.interface"

export const editContactRequest = (contact: Contact): Promise<RequestResponse<Contact>> => {
return ipcRenderer.callMain(IpcContactRequest.EditContact, contact)
export const editContactRequest = (
contact: Contact
): Promise<RequestResponse<Contact>> => {
return ipcRenderer.callMain(IpcContactEvent.EditContact, contact)
}
2 changes: 0 additions & 2 deletions packages/app/src/core/application.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
} from "App/core/initializers"
import { Module } from "App/core/types"
import { FileSystemService } from "App/file-system/services/file-system.service.refactored"
import { FileSystemModule } from "App/file-system/file-system.module"
import { IndexStorageModule } from "App/index-storage/index-storage.module"
import { DataSyncModule } from "App/data-sync/data-sync.module"
import { ContactModule } from "App/contacts/contact.module"
Expand All @@ -48,7 +47,6 @@ import {
export class ApplicationModule {
public modules: Module[] = [
DeviceInfoModule,
FileSystemModule,
IndexStorageModule,
OutboxModule,
AnalyticDataTrackerModule,
Expand Down
8 changes: 1 addition & 7 deletions packages/app/src/core/initializers/controller.initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import { EventDefinition, Controller } from "App/core/types"
export class ControllerInitializer {
public initialize(controllers: Controller[]): void {
controllers.forEach((controller) => {
// AUTO DISABLED - fix me if you like :)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const prefix = Reflect.getMetadata(
ReflectKey.Prefix,
controller.constructor
)
// AUTO DISABLED - fix me if you like :)
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const events: EventDefinition[] = Reflect.getMetadata(
Expand All @@ -26,7 +20,7 @@ export class ControllerInitializer {
events.forEach((event) => {
// AUTO DISABLED - fix me if you like :)
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions, @typescript-eslint/require-await
ipcMain.answerRenderer(`${prefix}-${event.name}`, async (data) => {
ipcMain.answerRenderer(event.name, (data) => {
// AUTO DISABLED - fix me if you like :)
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any
return (controller as Record<string, any>)[event.methodName](data)
Expand Down
Loading
Loading