Skip to content

Commit

Permalink
optimize injecting package name into the code
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimiry committed Jun 27, 2018
1 parent 72ab34c commit c6637e2
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
13 changes: 13 additions & 0 deletions src/electron-main/constants.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {test} from "ava";

import {KEYTAR_MASTER_PASSWORD_ACCOUNT, KEYTAR_SERVICE_NAME} from "./constants";

// tslint:disable-next-line:no-var-requires
const {name: packageName} = require("../../package.json");

test(`"keytar" constants`, async (t) => {
t.truthy(KEYTAR_MASTER_PASSWORD_ACCOUNT);
t.truthy(KEYTAR_SERVICE_NAME);
t.truthy(packageName);
t.is(packageName, KEYTAR_SERVICE_NAME);
});
4 changes: 1 addition & 3 deletions src/electron-main/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {Options as EncryptionAdapterOptions} from "fs-json-store-encryption-adapter";

// tslint:disable-next-line:no-var-requires
const {name} = require("../../package.json");
const encryptionPreset: EncryptionAdapterOptions = {
keyDerivation: {type: "sodium.crypto_pwhash", preset: "mode:interactive|algorithm:default"},
encryption: {type: "sodium.crypto_secretbox_easy", preset: "algorithm:default"},
Expand All @@ -22,5 +20,5 @@ export const INITIAL_STORES = Object.freeze({
settings: {accounts: []},
});

export const KEYTAR_SERVICE_NAME = name;
export const KEYTAR_SERVICE_NAME = "protonmail-desktop-app";
export const KEYTAR_MASTER_PASSWORD_ACCOUNT = "master-password";
6 changes: 4 additions & 2 deletions src/electron-main/ipc-main-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ export const initEndpoints = (ctx: Context): Endpoints => {
aboutWindow({
icon_path: ctx.locations.icon,
package_json_dir: "development" === (process.env.NODE_ENV as BuildEnvironment) ? process.cwd() : ctx.locations.app,
// TODO electron-builder strips "bugs" property out form the package.json preparing a build
bug_report_url: "https://github.com/vladimiry/protonmail-desktop-app/issues",
// TODO figure why ""about-window" doesn't automatically resolve properties like "bugs" or "description" from package.json
// properties are fulled in package.json, both original and modified by "electron-builder"
description: String(process.env.APP_ENV_PACKAGE_DESCRIPTION),
bug_report_url: String(process.env.APP_ENV_PACKAGE_BUGS_URL),
});
return EMPTY;
},
Expand Down
3 changes: 1 addition & 2 deletions src/shared/api/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ export interface Endpoints {
updateOverlayIcon: ApiMethod<{ count: number; dataURL?: string; }, never>;
}

// TODO pick "channel" from "package.json => name"
export const IPC_MAIN_API = new IpcMainApiService<Endpoints>({channel: "protonmail-desktop-app:ipcMain-api"});
export const IPC_MAIN_API = new IpcMainApiService<Endpoints>({channel: `${process.env.APP_ENV_PACKAGE_NAME}:ipcMain-api`});
3 changes: 1 addition & 2 deletions src/shared/api/webview/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ export interface Endpoints {
unlock: ApiMethod<MailPasswordFieldContainer, { message: string }>;
}

// TODO pick "channel" from "package.json => name"
export const IPC_WEBVIEW_API = new WebViewApiService<Endpoints>({channel: "protonmail-desktop-app:webview-api"});
export const IPC_WEBVIEW_API = new WebViewApiService<Endpoints>({channel: `${process.env.APP_ENV_PACKAGE_NAME}:webview-api`});
6 changes: 4 additions & 2 deletions src/webpack/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const srcPath = (...value: string[]) => rootPath("./src", ...value);
const outputPath = (...value: string[]) => rootPath(environmentSate.development ? "./app-dev" : "./app", ...value);

// tslint:disable:no-var-requires
const {name: packageName} = require(rootPath("./package.json"));
const packageJson = require(rootPath("./package.json"));

const buildConfig: BuildConfig = (config, options = {}) => {
const {tsConfigFile} = {tsConfigFile: rootPath("./tsconfig.json"), ...options};
Expand All @@ -35,7 +35,9 @@ const buildConfig: BuildConfig = (config, options = {}) => {
plugins: [
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(environment),
"process.env.APP_ENV_PACKAGE_NAME": JSON.stringify(packageName),
"process.env.APP_ENV_PACKAGE_NAME": JSON.stringify(packageJson.name),
"process.env.APP_ENV_PACKAGE_DESCRIPTION": JSON.stringify(packageJson.description),
"process.env.APP_ENV_PACKAGE_BUGS_URL": JSON.stringify(packageJson.bugs.url),
}),
],
resolve: {
Expand Down
11 changes: 2 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5273,12 +5273,6 @@ is-observable@^1.1.0:
dependencies:
symbol-observable "^1.1.0"

is-odd@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/is-odd/-/is-odd-2.0.0.tgz#7646624671fd7ea558ccd9a2795182f2958f1b24"
dependencies:
is-number "^4.0.0"

is-path-cwd@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-path-cwd/-/is-path-cwd-1.0.0.tgz#d225ec23132e89edd38fda767472e62e65f1106d"
Expand Down Expand Up @@ -6609,15 +6603,14 @@ nan@^2.10.0, nan@^2.4.0, nan@^2.9.2:
resolved "https://registry.yarnpkg.com/nan/-/nan-2.10.0.tgz#96d0cd610ebd58d4b4de9cc0c6828cda99c7548f"

nanomatch@^1.2.9:
version "1.2.9"
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.9.tgz#879f7150cb2dab7a471259066c104eee6e0fa7c2"
version "1.2.13"
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
dependencies:
arr-diff "^4.0.0"
array-unique "^0.3.2"
define-property "^2.0.2"
extend-shallow "^3.0.2"
fragment-cache "^0.2.1"
is-odd "^2.0.0"
is-windows "^1.0.2"
kind-of "^6.0.2"
object.pick "^1.3.0"
Expand Down

0 comments on commit c6637e2

Please sign in to comment.