Merge pull request #13803 from desktop/refactor-remote-get-app-path-to-main-process

Refactor `remote.app.getAppPath()` to main process
This commit is contained in:
tidy-dev 2022-02-03 12:00:26 -05:00 committed by GitHub
commit b442b0a314
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 20 deletions

View file

@ -83,6 +83,7 @@ export type RequestChannels = {
*/
export type RequestResponseChannels = {
'get-app-architecture': () => Promise<Architecture>
'get-app-path': () => Promise<string>
'is-running-under-rosetta-translation': () => Promise<boolean>
'move-to-trash': (path: string) => Promise<void>
'show-contextual-menu': (

View file

@ -739,8 +739,8 @@ export class AppStore extends TypedBaseStore<IAppState> {
}
/** Load the emoji from disk. */
public loadEmoji() {
const rootDir = getAppPath()
public async loadEmoji() {
const rootDir = await getAppPath()
readEmoji(rootDir)
.then(emoji => {
this.emoji = emoji

View file

@ -552,6 +552,11 @@ app.on('ready', () => {
*/
ipcMain.handle('get-app-architecture', async () => getArchitecture(app))
/**
* An event sent by the renderer asking for the app's path
*/
ipcMain.handle('get-app-path', async () => app.getAppPath())
/**
* An event sent by the renderer asking for whether the app is running under
* rosetta translation

View file

@ -42,8 +42,8 @@ export class Acknowledgements extends React.Component<
this.state = { licenses: null }
}
public componentDidMount() {
const path = Path.join(getAppPath(), 'static', 'licenses.json')
public async componentDidMount() {
const path = Path.join(await getAppPath(), 'static', 'licenses.json')
Fs.readFile(path, 'utf8', (err, data) => {
if (err) {
log.error('Error loading licenses', err)

View file

@ -1,8 +1,8 @@
import * as remote from '@electron/remote'
import { getAppPathProxy } from '../main-process-proxy'
let app: Electron.App | null = null
let path: string | null = null
let userDataPath: string | null = null
let documentsPath: string | null = null
function getApp(): Electron.App {
@ -34,27 +34,14 @@ export function getName(): string {
*
* This is preferable to using `remote` directly because we cache the result.
*/
export function getAppPath(): string {
export async function getAppPath(): Promise<string> {
if (!path) {
path = getApp().getAppPath()
path = await getAppPathProxy()
}
return path
}
/**
* Get the path to the user's data.
*
* This is preferable to using `remote` directly because we cache the result.
*/
export function getUserDataPath(): string {
if (!userDataPath) {
userDataPath = getApp().getPath('userData')
}
return userDataPath
}
/**
* Get the path to the user's documents path.
*

View file

@ -177,6 +177,11 @@ export const showCertificateTrustDialog = sendProxy(
*/
export const getAppArchitecture = invokeProxy('get-app-architecture', 0)
/**
* Tell the main process to obtain the application's app path
*/
export const getAppPathProxy = invokeProxy('get-app-path', 0)
/**
* Tell the main process to obtain whether the app is running under a rosetta
* translation