Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(electron-updater): decouple Electron API to support Proton and o…
…ther frameworks
- Loading branch information
Showing
13 changed files
with
286 additions
and
192 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,45 @@ | ||
import * as path from "path" | ||
|
||
export interface AppAdapter { | ||
readonly version: string | ||
readonly name: string | ||
|
||
readonly isPackaged: boolean | ||
|
||
/** | ||
* Path to update metadata file. | ||
*/ | ||
readonly appUpdateConfigPath: string | ||
|
||
/** | ||
* Path to user data directory. | ||
*/ | ||
readonly userDataPath: string | ||
|
||
/** | ||
* Path to cache directory. | ||
*/ | ||
readonly baseCachePath: string | ||
|
||
whenReady(): Promise<void> | ||
|
||
quit(): void | ||
|
||
onQuit(handler: (exitCode: number) => void): void | ||
} | ||
|
||
export function getAppCacheDir() { | ||
const homedir = require("os").homedir() | ||
// https://github.com/electron/electron/issues/1404#issuecomment-194391247 | ||
let result: string | ||
if (process.platform === "win32") { | ||
result = process.env.LOCALAPPDATA || path.join(homedir, "AppData", "Local") | ||
} | ||
else if (process.platform === "darwin") { | ||
result = path.join(homedir, "Library", "Application Support", "Caches") | ||
} | ||
else { | ||
result = process.env.XDG_CACHE_HOME || path.join(homedir, ".cache") | ||
} | ||
return result | ||
} |
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
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,43 @@ | ||
import * as path from "path" | ||
import { AppAdapter, getAppCacheDir } from "./AppAdapter" | ||
|
||
export class ElectronAppAdapter implements AppAdapter { | ||
constructor(private readonly app = require("electron").app) { | ||
} | ||
|
||
whenReady(): Promise<void> { | ||
return this.app.whenReady() | ||
} | ||
|
||
get version(): string { | ||
return this.app.getVersion() | ||
} | ||
|
||
get name(): string { | ||
return this.app.getName() | ||
} | ||
|
||
get isPackaged(): boolean { | ||
return this.app.isPackaged === true | ||
} | ||
|
||
get appUpdateConfigPath(): string { | ||
return this.isPackaged ? path.join(process.resourcesPath!!, "app-update.yml") : path.join(this.app.getAppPath(), "dev-app-update.yml") | ||
} | ||
|
||
get userDataPath(): string { | ||
return this.app.getPath("userData") | ||
} | ||
|
||
get baseCachePath(): string { | ||
return getAppCacheDir() | ||
} | ||
|
||
quit(): void { | ||
this.app.quit() | ||
} | ||
|
||
onQuit(handler: (exitCode: number) => void): void { | ||
this.app.once("quit", (event, exitCode) => handler(exitCode)) | ||
} | ||
} |
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.