Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
refactor: move electron files to src folder and apply some tweaks (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
brenopolanski authored and faustbrian committed Jun 7, 2020
1 parent 2179b91 commit e0d7abf
Show file tree
Hide file tree
Showing 12 changed files with 322 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ indent_size = 4
end_of_line = lf
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true
trim_trailing_whitespace = true
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
src/pwa/*
public/
src/tailwind.config.js
src/resources/*
src/i18n
dist/
build/
coverage/
src/i18n
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
env: {
browser: true,
node: true,
es6: true,
},
plugins: ["@typescript-eslint", "prettier", "testing-library"],
extends: [
Expand Down
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) Ark Ecosystem <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
76 changes: 38 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,22 @@
"url": "https://github.com/ArkEcosystem/desktop-wallet/issues"
},
"homepage": "./",
"main": "public/electron.js",
"main": "src/electron/index.js",
"scripts": {
"dev": "concurrently \"BROWSER=none yarn start\" \"wait-on http://localhost:3000 && electron .\"",
"build": "react-app-rewired build",
"format": "yarn lint && yarn prettier",
"lint": "eslint '*/**/*.{js,ts,tsx}' --quiet --fix",
"prettier": "prettier --write \"./*.{ts,js,json,md,vue}\" \"./**/*.{ts,js,json,md,vue}\"",
"storybook": "start-storybook -p 5000",
"start": "react-app-rewired start",
"test": "react-app-rewired test",
"test:coverage": "react-app-rewired test --coverage --watchAll=false",
"eject": "react-app-rewired eject",
"build:mac": "yarn build && electron-builder --mac --publish never",
"build:linux": "yarn build && electron-builder --linux --publish never",
"build:win": "yarn build && electron-builder --win --x64 --ia32 --publish never"
},
"dependencies": {
"@testing-library/jest-dom": "^5.9.0",
"@testing-library/react": "^9.3.2",
Expand Down Expand Up @@ -53,43 +68,6 @@
"twin.macro": "^1.3.0",
"typescript": "~3.7.2"
},
"scripts": {
"dev": "concurrently \"BROWSER=none yarn start\" \"wait-on http://localhost:3000 && electron .\"",
"build": "react-app-rewired build",
"format": "yarn lint && yarn prettier",
"lint": "eslint '*/**/*.{js,ts,tsx}' --quiet --fix",
"prettier": "prettier --write \"./*.{ts,js,json,md,vue}\" \"./**/*.{ts,js,json,md,vue}\"",
"storybook": "start-storybook -p 5000",
"start": "react-app-rewired start",
"test": "react-app-rewired test",
"test:coverage": "react-app-rewired test --coverage --watchAll=false",
"eject": "react-app-rewired eject",
"build:mac": "yarn build && electron-builder --mac --publish never",
"build:linux": "yarn build && electron-builder --linux --publish never",
"build:win": "yarn build && electron-builder --win --x64 --ia32 --publish never"
},
"babelMacros": {
"twin": {
"preset": "styled-components",
"config": "src/tailwind.config.js",
"autoCssProp": true
}
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@storybook/addon-actions": "^5.3.19",
"@storybook/addon-knobs": "^5.3.19",
Expand Down Expand Up @@ -125,6 +103,28 @@
"tailwindcss": "^1.4.6",
"wait-on": "^5.0.0"
},
"babelMacros": {
"twin": {
"preset": "styled-components",
"config": "src/tailwind.config.js",
"autoCssProp": true
}
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
Expand Down
Binary file removed public/favicon.ico
Binary file not shown.
5 changes: 0 additions & 5 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>ARK Desktop Wallet</title>
</head>
<body>
Expand Down
25 changes: 0 additions & 25 deletions public/manifest.json

This file was deleted.

3 changes: 0 additions & 3 deletions public/robots.txt

This file was deleted.

124 changes: 124 additions & 0 deletions src/electron/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const electron = require("electron");
const path = require("path");
const isDev = require("electron-is-dev");
const winState = require("electron-window-state");
const assignMenu = require("./menu");

const { BrowserWindow, app, screen, ipcMain } = electron;

const windows = {};
let mainWindow;
let windowState = null;
let deeplinkingUrl = null;

const winURL = isDev ? "http://localhost:3000" : `file://${path.join(__dirname, "../../build/index.html")}`;

const installExtensions = async () => {
const installer = require("electron-devtools-installer");
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
const extensions = ["REACT_DEVELOPER_TOOLS"];

return Promise.all(extensions.map((name) => installer.default(installer[name], forceDownload))).catch(console.log);
};

function broadcastURL(url) {
if (!url || typeof url !== "string") {
return;
}

if (mainWindow && mainWindow.webContents) {
mainWindow.webContents.send("process-url", url);
deeplinkingUrl = null;
}
}

ipcMain.on("disable-iframe-protection", function (_event, urls) {
const filter = { urls };
windows.main.webContents.session.webRequest.onHeadersReceived(filter, (details, done) => {
const headers = details.responseHeaders;

const xFrameOrigin = Object.keys(headers).find((header) => header.toString().match(/^x-frame-options$/i));
if (xFrameOrigin) {
delete headers[xFrameOrigin];
}

done({
cancel: false,
responseHeaders: headers,
statusLine: details.statusLine,
});
});
});

function createWindow() {
const { width, height } = screen.getPrimaryDisplay().workAreaSize;

windowState = winState({
defaultWidth: width,
defaultHeight: height,
fullScreen: false,
});

mainWindow = new BrowserWindow({
width: windowState.width,
height: windowState.height,
x: windowState.x,
y: windowState.y,
backgroundColor: "#f7fafb",
center: true,
show: true,
webPreferences: {
nodeIntegration: true,
webviewTag: true,
},
});

mainWindow.isMain = true;

windowState.manage(mainWindow);
mainWindow.loadURL(winURL);
mainWindow.setBackgroundColor("#f7fafb");

mainWindow.on("close", () => (mainWindow = null));
mainWindow.on("closed", () => (mainWindow = null));

mainWindow.webContents.on("did-finish-load", () => {
const version = app.getVersion();
const windowTitle = `ARK Desktop Wallet ${version}`;
mainWindow.setTitle(windowTitle);

broadcastURL(deeplinkingUrl);
});

if (isDev) {
installExtensions()
.then(() => mainWindow.webContents.openDevTools())
.catch((error) => console.error(error));
}
}

assignMenu({ createWindow });

app.on("ready", createWindow);

app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});

app.on("activate", () => {
if (mainWindow === null) {
createWindow();
}
});

app.on("open-url", (event, url) => {
// Protocol handler for osx
event.preventDefault();
deeplinkingUrl = url;
broadcastURL(deeplinkingUrl);
});

app.setAsDefaultProtocolClient("ark", process.execPath, ["--"]);
Loading

0 comments on commit e0d7abf

Please sign in to comment.