mirror of
https://github.com/desktop/desktop
synced 2024-08-24 18:57:33 +00:00
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:
commit
b442b0a314
|
@ -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': (
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue