Stop using @electron/remote to obtain app.getPath() (#4078)

* Stop using remote to obtain app.getPath()

- Initialize entire map in bootstrap()

- Updated unit tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Resolve PR comments

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix test

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix build

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Ensure that init can only be called once and catch errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Replace basically all uses of app.getPath() with AppPaths.get()

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix unit tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-10-27 21:07:41 -04:00
1 parent 65b6908bf1
commit f297407156
45 files changed
+521 -200

No files matched your search

@@ -46,6 +46,11 @@ export function getClusterFrameUrl(clusterId: ClusterId) {
* Get the result of `getClusterIdFromHost` from the current `location.host`
*/
export function getHostedClusterId(): ClusterId | undefined {
// catch being called in main
if (typeof location === "undefined") {
return undefined;
}
return getClusterIdFromHost(location.host);
}
+4 -4
View File
@@ -32,19 +32,21 @@ export * from "./base64";
export * from "./camelCase";
export * from "./cloneJson";
export * from "./cluster-id-url-parsing";
export * from "./convertCpu";
export * from "./convertMemory";
export * from "./debouncePromise";
export * from "./defineGlobal";
export * from "./delay";
export * from "./disposer";
export * from "./downloadFile";
export * from "./formatDuration";
export * from "./escapeRegExp";
export * from "./extended-map";
export * from "./getPath";
export * from "./formatDuration";
export * from "./getRandId";
export * from "./hash-set";
export * from "./local-kubeconfig";
export * from "./n-fircate";
export * from "./objects";
export * from "./openExternal";
export * from "./paths";
export * from "./reject-promise";
@@ -56,8 +58,6 @@ export * from "./toggle-set";
export * from "./toJS";
export * from "./type-narrowing";
export * from "./types";
export * from "./convertMemory";
export * from "./convertCpu";
import * as iter from "./iter";
import * as array from "./array";
+2 -2
View File
@@ -21,11 +21,11 @@
import path from "path";
import * as uuid from "uuid";
import { AppPaths } from "../app-paths";
import type { ClusterId } from "../cluster-types";
import { getPath } from "./getPath";
export function storedKubeConfigFolder(): string {
return path.resolve(getPath("userData"), "kubeconfigs");
return path.resolve(AppPaths.get("userData"), "kubeconfigs");
}
export function getCustomKubeConfigPath(clusterId: ClusterId = uuid.v4()): string {
@@ -19,19 +19,10 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { app, ipcMain } from "electron";
const remote = ipcMain ? null : require("@electron/remote");
/**
* calls getPath either on app or on the remote's app
*
* @deprecated Use a different method for accessing the getPath function
* A better typed version of `Object.fromEntries` where the keys are known to
* be a specific subset
*/
export function getPath(name: Parameters<typeof app["getPath"]>[0]): string {
if (app) {
return app.getPath(name);
}
return remote.app.getPath(name);
export function fromEntries<T, Key extends string>(entries: Iterable<readonly [Key, T]>): { [k in Key]: T } {
return Object.fromEntries(entries) as { [k in Key]: T };
}