Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
Merge pull request #52 from Or3stis/setting-window
Browse files Browse the repository at this point in the history
Settings window
  • Loading branch information
Or3stis committed Mar 24, 2018
2 parents 95fd7ea + 6f7bf3a commit eaaf7f8
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
3 changes: 1 addition & 2 deletions app/settings/userSettings.js
@@ -1,5 +1,4 @@
// settings of ASTo
// settings of ASTo

const settings = {
darkText: '#abb2bf',
Expand Down Expand Up @@ -62,7 +61,7 @@ const settings = {
// default color theme
colorTheme: 'dark',
// number of maximum bubbles in the message area
maxNumberOfBubbles: 16,
maxNumberOfBubbles: 15,
// url for the ASTo wiki
docsURL: 'https://or3stis.github.io/apparatus/docs',
// url for searching vulnerabilities
Expand Down
13 changes: 11 additions & 2 deletions app/src/helpers/settingsMenu/createSettingsWindow.js
Expand Up @@ -6,7 +6,12 @@ module.exports = function settingsWindow () {
const settingsURL = `file://${__dirname}/settings.html`
// create window
const createWindow = url => {
let win = new BrowserWindow({ width: 570, height: 700, show: false })
let win = new BrowserWindow({
backgroundColor: '#282c34',
width: 570,
height: 700,
show: false
})
win.loadURL(url)
win.on('ready-to-show', win.show)

Expand All @@ -15,7 +20,11 @@ module.exports = function settingsWindow () {
})
}

// if an window is open
/**
* check if the settings window is open
*
* @param {string} url
*/
const windowIsOpen = url => {
let isWindowActive = false
const activeWins = BrowserWindow.getAllWindows()
Expand Down
4 changes: 4 additions & 0 deletions app/src/helpers/settingsMenu/loadSettingsWindow.js
@@ -1,5 +1,6 @@
// allows modification of the settings by the user
const remote = require('electron').remote
const ipc = require('electron').ipcRenderer
const fs = require('fs')

const settings = require('../../../settings/userSettings.js')
Expand Down Expand Up @@ -151,6 +152,7 @@ module.exports = settings

// close the window
const win = remote.getCurrentWindow()
ipc.send('window-settings', 'save')
win.close()
})

Expand All @@ -159,6 +161,7 @@ const cancelBtn = document.getElementById('settings-cancel')

cancelBtn.addEventListener('click', () => {
const win = remote.getCurrentWindow()
ipc.send('window-settings', 'cancel')
win.close()
})

Expand All @@ -176,5 +179,6 @@ restoreBtn.addEventListener('click', () => {

// close window
const win = remote.getCurrentWindow()
ipc.send('window-settings', 'restore')
win.close()
})
36 changes: 26 additions & 10 deletions app/src/initialize.js
@@ -1,4 +1,5 @@
// initializes the application and links it with the GUI
const ipc = require('electron').ipcRenderer

// require core modules
const printTotalNodes = require('./core/printTotalNodes.js')
Expand All @@ -8,6 +9,7 @@ const editEdge = require('./core/editEdge.js')

// require helper functions
const rmElement = require('./helpers/rmElement.js')
const bubbleTxt = require('./helpers/bubbleTxt.js')

// require buttons and keybindings
const buttons = require('./buttons.js')
Expand All @@ -24,17 +26,22 @@ module.exports = function initialize (cy, phase) {
cy.edges().addClass('label-edges')

// global variables, used in cy.on
let selectedNode = {}
let oldSelectedNode = {}
let selectedEdge = {}
let srcNode = {}
let trgNode = {}
// initialize export variables to prevent undefined errors
selectedNode.out = {}
oldSelectedNode.out = {}
selectedEdge.out = {}
srcNode.out = {}
trgNode.out = {}
let selectedNode = {
out: {}
}
let oldSelectedNode = {
out: {}
}
let selectedEdge = {
out: {}
}
let srcNode = {
out: {}
}
let trgNode = {
out: {}
}

// stores the initial state of the nodes in the graph
const graphNodes = cy.nodes()
Expand Down Expand Up @@ -181,4 +188,13 @@ module.exports = function initialize (cy, phase) {

// initial node count
printTotalNodes(cy)

// listening for changes in the app settings
ipc.on('change-settings', (event, message) => {
if (message === 'restore' || message === 'save') {
bubbleTxt(
'You will need to refresh the app for the color changes to be applied'
)
}
})
}
9 changes: 7 additions & 2 deletions app/src/main.js
@@ -1,10 +1,11 @@
const electron = require('electron')
const ipc = require('electron').ipcMain
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow

const settings = require('../settings/userSettings.js')
// const settings = require('../settings/userSettings.js')
const appMenu = require('./appMenu.js')

// Keep a global reference of the window object, if you don't, the window will
Expand All @@ -16,7 +17,7 @@ let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({
backgroundColor: settings.background,
backgroundColor: '#282c34',
width: 1200,
height: 745,
minWidth: 800,
Expand All @@ -40,6 +41,10 @@ function createWindow () {
mainWindow.show()
})

// capture events from the open windows
ipc.on('window-settings', (event, message) => {
mainWindow.send('change-settings', message)
})
// create the application's menu
appMenu()
}
Expand Down

0 comments on commit eaaf7f8

Please sign in to comment.