Skip to content

Commit

Permalink
chore: Clean electron debris (#7962)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Feb 6, 2024
1 parent 4d9f093 commit 31fcc89
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 71 deletions.
46 changes: 0 additions & 46 deletions packages/desktop/electron/electronApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,12 @@ const NotificationManager = require('./lib/notificationManager')
const { menuState } = require('./lib/menuState')
const features = require('../features/features').default

let activeProfileId = null
const eventListeners = {}

const ElectronApi = {
updateAppSettings(settings) {
return ipcRenderer.invoke('update-app-settings', settings)
},
getActiveProfile() {
return activeProfileId
},
updateActiveProfile(id) {
activeProfileId = id
},
async renameProfileFolder(oldPath, newPath) {
return ipcRenderer.invoke('get-path', 'userData').then((userDataPath) => {
if (oldPath.startsWith(userDataPath)) {
try {
fs.renameSync(oldPath, newPath)
} catch (err) {
console.error(err)
}
}
})
},
async removeProfileFolder(profilePath) {
return ipcRenderer.invoke('get-path', 'userData').then((userDataPath) => {
// Check that the removing profile path matches the user data path
Expand Down Expand Up @@ -82,28 +64,6 @@ const ElectronApi = {
return result.filePath
})
},
saveStrongholdBackup: ({ allowAccess }) => null,
async exportTransactionHistory(defaultPath, contents) {
return ipcRenderer
.invoke('show-save-dialog', {
properties: ['createDirectory', 'showOverwriteConfirmation'],
defaultPath,
filters: [{ name: 'CSV Files', extensions: ['csv'] }],
})
.then((result) => {
if (result.canceled) {
return null
}
return new Promise((resolve, reject) => {
try {
fs.writeFileSync(result.filePath, contents)
resolve(result.filePath)
} catch (err) {
reject(err)
}
})
})
},
/**
* Gets directory for app's configuration files
*
Expand Down Expand Up @@ -337,12 +297,6 @@ const ElectronApi = {
updateTheme(theme) {
return ipcRenderer.invoke('update-theme', theme)
},
startLedgerProcess() {
return ipcRenderer.send('start-ledger-process')
},
killLedgerProcess() {
return ipcRenderer.send('kill-ledger-process')
},
}

module.exports = ElectronApi
7 changes: 0 additions & 7 deletions packages/shared/lib/core/app/interfaces/platform.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ import { AppTheme } from '../enums'

export interface IPlatform {
getStrongholdBackupDestination(defaultPath: string): Promise<string | null>
saveStrongholdBackup({ allowAccess }: { allowAccess: boolean }): Promise<void>
exportTransactionHistory(defaultPath: string, contents: string): Promise<string | null>
getUserDataPath(): Promise<string>
getDiagnostics(): Promise<{ label: string; value: string }[]>
getOS(): Promise<string>
getMachineId(): Promise<string>
updateAppSettings(settings: Partial<IAppSettings>): Promise<void>
getActiveProfile(): string
updateActiveProfile(id: string): void
removeProfileFolder(profilePath: string): Promise<void>
renameProfileFolder(oldPath: string, newPath: string): Promise<void>
listProfileFolders(profileStoragePath: string): Promise<string[]>
updateMenu(attribute: string, value: unknown): void
popupMenu(): void
Expand Down Expand Up @@ -55,7 +51,4 @@ export interface IPlatform {

getLanguageCode(): Promise<string>
updateTheme(theme: AppTheme): void

startLedgerProcess(): Promise<void>
killLedgerProcess(): Promise<void>
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export async function login(loginOptions?: ILoginOptions): Promise<void> {
setTimeStrongholdLastUnlocked()
}
} else {
Platform.startLedgerProcess()
incrementLoginProgress(2)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { IProfileManager } from '@core/profile-manager/interfaces'
import { profileManager } from '@core/profile-manager/stores'
import { routerManager } from '@core/router/stores'
import { clearFilters } from '@core/utils/clearFilters'
import { Platform } from '@core/app'

/**
* Logout from active profile
Expand All @@ -28,7 +27,6 @@ export async function logout(clearActiveProfile = true, _lockStronghold = true):
if (get(isSoftwareProfile)) {
_lockStronghold && lockStronghold()
} else if (isLedgerProfile(get(activeProfile).type)) {
Platform.killLedgerProcess()
get(isPollingLedgerDeviceStatus) && stopPollingLedgerNanoStatus()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { activeProfile, activeProfileId, INITIAL_ACTIVE_PROFILE, IProfile } from '@core/profile'
import { Platform } from '@core/app'
import { get } from 'svelte/store'

export function resetActiveProfile(): void {
const { lastUsedAccountIndex } = get(activeProfile)
activeProfile.set(<IProfile>{ ...INITIAL_ACTIVE_PROFILE, lastUsedAccountIndex })
activeProfileId.set(null)
Platform.updateActiveProfile(null)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { activeProfile, INITIAL_ACTIVE_PROFILE, IPersistedProfile, IProfile } from '@core/profile'
import { activeProfileId } from '@core/profile/stores'
import { Platform } from '@core/app'

export function setActiveProfile(persistedProfile: IPersistedProfile): void {
activeProfile?.set(<IProfile>{ ...INITIAL_ACTIVE_PROFILE, ...persistedProfile })
activeProfileId?.set(persistedProfile.id)
Platform.updateActiveProfile(persistedProfile.id)
}
11 changes: 0 additions & 11 deletions packages/shared/lib/tests/__mocks__/platform.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ const Platform: IPlatform = {
NotificationManager: undefined,
PincodeManager: undefined,
close(): void {},
exportTransactionHistory(defaultPath: string, contents: string): Promise<string | null> {
return Promise.resolve(null)
},
getActiveProfile(): string {
return ''
},
getDiagnostics(): Promise<{ label: string; value: string }[]> {
return Promise.resolve([])
},
Expand Down Expand Up @@ -47,16 +41,12 @@ const Platform: IPlatform = {
removeProfileFolder(profilePath: string): Promise<void> {
return Promise.resolve(undefined)
},
renameProfileFolder(oldPath: string, newPath: string): Promise<void> {
return Promise.resolve(undefined)
},
saveRecoveryKit(kitData: ArrayBuffer): Promise<void> {
return Promise.resolve(undefined)
},
unhandledException(title: string, err: IError | unknown): Promise<void> {
return Promise.resolve(undefined)
},
updateActiveProfile(id: string): void {},
updateAppSettings(settings: Partial<IAppSettings>): Promise<void> {
return Promise.resolve(undefined)
},
Expand Down Expand Up @@ -97,5 +87,4 @@ const Platform: IPlatform = {
updateTheme(): void {},
}

window['__CAPACITOR__'] = Platform
window['__ELECTRON__'] = Platform

0 comments on commit 31fcc89

Please sign in to comment.