Skip to content

Commit

Permalink
refactor(ipc): adapted IPC work to new project structure
Browse files Browse the repository at this point in the history
Adapted IPC work to project layout defined in witnet#126

witnet#27
  • Loading branch information
mmartinbar committed Jun 15, 2018
1 parent 3958083 commit e51bc94
Show file tree
Hide file tree
Showing 20 changed files with 38 additions and 302 deletions.
File renamed without changes.
4 changes: 3 additions & 1 deletion app/lib/api/ipc/common/methods.ts → app/common/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ export function getMethodDescs(rawMethods: { [id: string]: any }, type: MethodTy
const filterFunc = (type === MethodType.Sync) ? isValidSyncMethodDesc : isValidAsyncMethodDesc

// Reduce map of maps to map
return Object
const methods = Object
.keys(rawMethods)
.map(key => rawMethods[key])
.filter(filterFunc)
.reduce((acc: { [id: string]: Handler },
desc: MethodDesc) => {
return {...acc, [desc.id]: desc.handler}
}, {})

return methods
}

/**
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as IPCMethods from "../../ipc/common/methods"
import * as IPCMethods from "../../../../app/common/methods"

/**
* Handler of no response handler function
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as IPCMethods from "../../ipc/common/methods"
import * as IPCMethods from "../../../../app/common/methods"

/**
* Handler of ping method
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as ImportedMethods from "../../handlers/backend/index"
import * as IPCMessages from "../common/messages"
import * as IPCMethods from "../common/methods"
import GenericIpcMain from "./genericIpcMain"
import {electronIpcMain} from "./electronIpcMain"
import * as ImportedMethods from "../handlers/index"
import * as IPCMessages from "../../../../app/common/messages"
import * as IPCMethods from "../../../../app/common/methods"
import GenericIpcMain from "./genericMain"
import {electronIpcMain} from "./electronMain"

/**
* Raw imported methods from handlers directory
Expand Down
File renamed without changes.
File renamed without changes.
272 changes: 0 additions & 272 deletions app/main/index.js

This file was deleted.

20 changes: 13 additions & 7 deletions app/main.electron.ts → app/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
const { app, BrowserWindow, Menu, shell } = require("electron")

import * as IPCBackend from "./lib/api/ipc/backend/ipcBackend"
import * as IPCBackend from "./api/ipc/backend"

let menu: any
let template: any
let mainWindow: any

if (process.env.NODE_ENV === "production") {
const sourceMapSupport = require("source-map-support") // eslint-disable-line
// eslint-disable-line
const sourceMapSupport = require("source-map-support")
sourceMapSupport.install()
}

if (process.env.NODE_ENV === "development") {
require("electron-debug")() // eslint-disable-line global-require
const path = require("path") // eslint-disable-line
const p = path.join(__dirname, "..", "app", "node_modules") // eslint-disable-line
require("module").globalPaths.push(p) // eslint-disable-line
// eslint-disable-line global-require
require("electron-debug")()
// eslint-disable-line
const path = require("path")
// eslint-disable-line
const p = path.join(__dirname, "..", "app", "node_modules")
// eslint-disable-line
require("module").globalPaths.push(p)
}

app.on("window-all-closed", () => {
Expand All @@ -24,7 +29,8 @@ app.on("window-all-closed", () => {

const installExtensions = async () => {
if (process.env.NODE_ENV === "development") {
const installer = require("electron-devtools-installer") // eslint-disable-line global-require
// eslint-disable-line global-require
const installer = require("electron-devtools-installer")

const extensions = [
"REACT_DEVELOPER_TOOLS",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as IPCMessages from "../common/messages"
import * as IPCMethods from "../common/methods"
import GenericIpcRenderer from "./genericIpcRenderer"
import {electronIpcRenderer} from "./electronIpcRenderer"
import * as IPCMessages from "../../../../app/common/messages"
import * as IPCMethods from "../../../../app/common/methods"
import GenericIpcRenderer from "./genericRenderer"
import {electronIpcRenderer} from "./electronRenderer"

/** Holds promises and timers for each pending request */
const pendingRequests: {[method: string]: any} = {}
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion config/webpack.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const baseConfig = {
devtool: "source-map",
target: "electron-main",

entry: [path.resolve(__dirname, "../app/main/index.js")],
entry: [path.resolve(__dirname, "../app/main/index.ts")],

resolve: {
extensions: [".js", ".ts", ".json"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as IPCMessages from "app/lib/api/ipc/common/messages"
import * as IPCMessages from "appCommon/messages"
import * as fixtures from "./messagesFixtures"

describe(`IPCMessages lib: validate valid channel messages" +
Expand Down
Loading

0 comments on commit e51bc94

Please sign in to comment.