Skip to content
This repository has been archived by the owner on Jan 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #170 from ZbayApp/ZbayLite
Browse files Browse the repository at this point in the history
merge ZbayLite into master
  • Loading branch information
vinkabuki authored Feb 4, 2021
2 parents 372b9dc + edbba0b commit 16783f8
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 19 deletions.
22 changes: 14 additions & 8 deletions src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,17 @@ app.on('ready', async () => {
mainWindow.webContents.on('did-finish-load', async () => {
mainWindow.webContents.send('ping')
try {
// Spawn and kill tor to generate onionAddress
console.log('spawning tor for onion address')
torProcess = await spawnTor()
createServer(mainWindow)
mainWindow.webContents.send('onionAddress', getOnionAddress())
torProcess.kill()
torProcess = null
console.log('killed tor process')
if (!torProcess) {

// Spawn and kill tor to generate onionAddress
console.log('spawning tor for onion address')
torProcess = await spawnTor()
createServer(mainWindow)
mainWindow.webContents.send('onionAddress', getOnionAddress())
// torProcess.kill()
// torProcess = null
// console.log('killed tor process')
}
} catch (error) {
console.log(error)
}
Expand All @@ -284,10 +287,13 @@ app.on('ready', async () => {
console.log('spawning tor for application')
torProcess = await spawnTor()
electronStore.set('isTorActive', true)
mainWindow.webContents.send('connectWsContacts')
}
})
ipcMain.on('killTor', async (event, arg) => {
console.log('starting killing tor')
if (torProcess !== null) {
console.log('tor killing proccessing')
torProcess.kill()
torProcess = null
electronStore.set('isTorActive', false)
Expand Down
2 changes: 1 addition & 1 deletion src/main/websockets/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ new Promise((resolve, reject) => {
const id = setTimeout(() => {
// eslint-disable-next-line
reject('timeout')
}, 20000)
}, 35000)
socket.on('unexpected-response', err => {
console.log(err)
})
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import messagesHandlers from './store/handlers/messages'
import nodeSelectors from './store/selectors/node'
import coordinatorSelectors from './store/selectors/coordinator'
import identityHandlers from './store/handlers/identity'
import { errorNotification, successNotification } from './store/handlers/utils'
import contactsHandlers from './store/handlers/contacts'

import { errorNotification, successNotification } from './store/handlers/utils'
import notificationsHandlers from './store/handlers/notifications'
import appSelectors from './store/selectors/app'

Expand Down Expand Up @@ -66,6 +67,11 @@ ipcRenderer.on('wsMessage', (_, data) => {
store.dispatch(messagesHandlers.epics.handleWebsocketMessage(data))
})

ipcRenderer.on('connectWsContacts', (event, msg) => {
console.log('connecting ws contacts')
store.dispatch(contactsHandlers.epics.connectWsContacts())
})

ipcRenderer.on('askForUsingDefaultBlockchainLocation', event => {
store.dispatch(appHandlers.epics.askForBlockchainLocation())
})
Expand Down
1 change: 1 addition & 0 deletions src/renderer/store/handlers/contacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export const connectWsContacts = (key?: string) => async (dispatch, getState) =>
const user = users[contact.key]
if (user?.onionAddress) {
console.log("trying to connect inside contacts loop")
console.log(user?.onionAddress)
contactsToConnect.push({ key: contact.key, onionAddress: user?.onionAddress })
}
}
Expand Down
13 changes: 7 additions & 6 deletions src/renderer/store/handlers/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createAction, handleActions } from 'redux-actions'
import secp256k1 from 'secp256k1'
import { randomBytes } from 'crypto'
import { DateTime } from 'luxon'
import { remote } from 'electron'
import { ipcRenderer, remote } from 'electron'

import client from '../../zcash'
import channels from '../../zcash/channels'
Expand Down Expand Up @@ -408,8 +408,11 @@ export const setIdentityEpic = identityToSet => async (dispatch, getState) => {
await dispatch(fetchBalance())
await dispatch(fetchFreeUtxos())
await dispatch(messagesHandlers.epics.fetchMessages())
await dispatch(appHandlers.epics.initializeUseTor())
const usernameStatus = electronStore.get('registrationStatus.status')
if (!useTor) {
ipcRenderer.send('killTor')
// await dispatch(appHandlers.epics.initializeUseTor())
}
const usernameStatus = electronStore.get('registrationStatus.status')
const nickname = electronStore.get('registrationStatus.nickname')
console.log(usernameStatus)
if (nickname && usernameStatus !== 'SUCCESS') {
Expand All @@ -429,10 +432,8 @@ export const setIdentityEpic = identityToSet => async (dispatch, getState) => {
}
dispatch(setLoadingMessage(''))
dispatch(setLoading(false))
setTimeout(() => {
dispatch(contactsHandlers.epics.connectWsContacts())
}, 5000)
if (electronStore.get('isMigrating')) {
if (electronStore.get('isMigrating')) {
dispatch(modalsHandlers.actionCreators.openModal('migrationModal')())
}
}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/store/handlers/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ export const handleWebsocketMessage = data => async (dispatch, getState) => {
console.log('Contact exist')
if (!contact.connected) {
console.log('Contact is not connected, initializing connection')
console.log(publicKey)
//dispatch(contactsHandlers.actions.setContactConnected({ connected: true, key: publicKey }))
dispatch(contactsHandlers.epics.connectWsContacts(publicKey))
}
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/store/handlers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ export const createOrUpdateUser = payload => async (dispatch, getState) => {
status: 'IN_PROGRESS'
})

ipcRenderer.send('spawnTor')
electronStore.set('useTor', true)
dispatch(appHandlers.actions.setUseTor(true))
// ipcRenderer.send('spawnTor')
// electronStore.set('useTor', true)
// dispatch(appHandlers.actions.setUseTor(true))
dispatch(checkRegistrationConfirmations({ firstRun: true }))
dispatch(
notificationsHandlers.actions.enqueueSnackbar(
Expand Down

0 comments on commit 16783f8

Please sign in to comment.