Skip to content

Commit

Permalink
Merge pull request #3270 from NAmorim/develop
Browse files Browse the repository at this point in the history
[Distribution] Fix - Console menu was not appearing in MacOS
  • Loading branch information
Luis-Fernando-Molina authored Dec 28, 2021
2 parents af12c2a + ca60447 commit 930b5dd
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 41 deletions.
Binary file added build/exchanges/AscendEX.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/exchanges/binance.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/exchanges/kraken.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
141 changes: 100 additions & 41 deletions electron-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,83 @@ process.env.SA_MODE = 'gitDisable'
process.env.PACKAGED_PATH = app.getAppPath()
process.env.DATA_PATH = app.getPath('documents')

const WINDOW_WIDTH = 1280
const WINDOW_WIDTH = 1580
const WINDOW_HEIGHT = 768

let mainWindow, consoleWindow, platform
let mainWindow, consoleWindow, selectWindow, platform

const port = 34248 // Default HTTP port

run()
// Check if it's the first time you run this app
function firstRun() {
const configPath = path.join(process.env.DATA_PATH, '/Superalgos_Data/FirstRun');

function run() {
if (fs.existsSync(configPath)) {
return false;
}

try {
fs.writeFileSync(configPath, '');
} catch (error) {
if (error.code === 'ENOENT') {
makeDir.sync(path.join(process.env.DATA_PATH, '/Superalgos_Data/FirstRun'));
return firstRun();
}

throw error;
}

return true;
};

// iterate in the workspaces folder and get all *Onboarding ones to present in the selection page
function getWorkspaces() {
const workspacePath = path.join(process.env.PACKAGED_PATH, 'Projects/Foundations/Plugins/Workspaces')
const workspaces = []
try {
const files = fs.readdirSync(workspacePath)
for(const file of files) {
if (file.includes('-Onboarding-')) {
workspaces.push(file)
}
}
} catch (error) {
if (error) {
console.log(error)
}
}
return workspaces
}

// Create a selection window for first run
function selectionWindow() {
let bw_options = {
width: WINDOW_WIDTH,
height: WINDOW_HEIGHT,
resizable: true,
webPreferences: {
nodeIntegration: false, // is default value after Electron v5
contextIsolation: true, // protect against prototype pollution
enableRemoteModule: false, // turn off remote
preload: path.join(__dirname, "preload.js") // use a preload script
}
}
selectWindow = new BrowserWindow(
bw_options
)
selectWindow.loadFile('./selection.html')
}

function run(workspace) {
const { fork } = require('child_process')
platform = fork(path.join(__dirname, '/PlatformRoot.js'), ["noBrowser"], {stdio: ['pipe', 'pipe', 'pipe', 'ipc'], env: process.env})
var options = ["noBrowser"]
//if (workspace) {options.push('Foundations ' + workspace)}
platform = fork(path.join(__dirname, '/PlatformRoot.js'), options, {stdio: ['pipe', 'pipe', 'pipe', 'ipc'], env: process.env})

platform.on('message', _ => {
openMain()
openMain(workspace)
openConsoleWindow()
if (selectWindow) {selectWindow.close()}
})
}

Expand All @@ -37,10 +98,16 @@ ipcMain.on("toMain", (event, args) => {
consoleWindow.webContents.send("fromMain", data);
}
})
} else if (args === "getExchanges") {
const workspaces = getWorkspaces()
selectWindow.webContents.send("fromMain", workspaces); //send to the renderer
} else if (args.includes(".json")) {
var workspace = args.split('.')[0]
run(workspace)
}
})

function openMain () {
function openMain(workspace) {
let bw_options = {
width: WINDOW_WIDTH,
height: WINDOW_HEIGHT,
Expand All @@ -58,8 +125,14 @@ function openMain () {
)

createMainMenus()

if (workspace) {
var queryString = '/?initialWorkspaceName=' + workspace + '&initialWorkspaceProject=Foundations&initialWorkspaceType=Plugin'
mainWindow.loadURL("http://localhost:" + port + queryString)
} else {
mainWindow.loadURL("http://localhost:" + port)
}

mainWindow.loadURL("http://localhost:" + port)

mainWindow.on('close', function (e) {
if (consoleWindow.isVisible()) {
Expand Down Expand Up @@ -154,7 +227,13 @@ function openConsoleWindow() {

app.on('ready', function () {
autoUpdater.checkForUpdatesAndNotify()
createMainMenus()
// Check for first run and present selection if true
const isFirstRun = firstRun()
if (isFirstRun) {
selectionWindow()
} else {
run()
}
})

app.on('window-all-closed', function () {
Expand All @@ -165,15 +244,7 @@ app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})

function createMainMenus() {
function logsActive() {
if(consoleWindow) {
return true
} else {
return false
}
}

function createMainMenus() {
const mainTemplate = [
{
label: 'File',
Expand Down Expand Up @@ -220,15 +291,17 @@ function createMainMenus() {
]
},
{
label: 'Logs',
enabled: logsActive(),
click () {
if(consoleWindow) {
consoleWindow.show()
} else {
openConsoleWindow()
label: 'Console',
submenu: [
{
label: 'Show logs',
click () {consoleWindow ? consoleWindow.show() : openConsoleWindow()}
},
{
label: 'Hide logs',
click () {consoleWindow.hide()}
}
}
]
},
{
label: 'Profile',
Expand All @@ -238,8 +311,6 @@ function createMainMenus() {
click: async() => {
data = {newUser: ["Governance", "Plugin → Token-Distribution-Superalgos"]}
mainWindow.webContents.send("fromMaster", data)
data
//mainWindow.loadURL('http://localhost:34248/LoadPlugin/Governance/Workspaces/Token-Distribution-Superalgos.json')
}
},
{
Expand Down Expand Up @@ -271,15 +342,6 @@ function createMainMenus() {
}

function createConsoleMenus () {

function uiActive() {
if(mainWindow.isVisible()) {
return false
} else {
return true
}
}

const consoleTemplate = [
{
label: 'File',
Expand Down Expand Up @@ -319,10 +381,7 @@ function createConsoleMenus () {
{
label: 'Show UI',
id: 'ui',
enabled: uiActive(),
click () {
mainWindow.show()
}
click () {mainWindow.isVisible() ? mainWindow.focus() : mainWindow.show()}
}
]

Expand Down
120 changes: 120 additions & 0 deletions selection.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<!doctype html>
<html lang="en-US">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" charset="utf-8">
<title>Select Workspace</title>

<style>
:root {
--font-face: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
body {
background-color: black;
color: white;
font-family: var(--font-face);
}
h2 {
text-align: center;
font-size: 45px;
padding: 60px 0;
}

.wrapper {
padding: 30px;
}

.workspace-container {
margin: 0 30px;
display: grid;
gap: 1.5rem;
grid-template-columns: repeat(4, 20vw);
grid-auto-rows: 20vw;
justify-content: center;
}

.workspace-container div {
border: 1px white solid;
}

footer {
display: flex;
flex-direction: row;
padding: 50px;
}

footer div {
margin: 30px;
}

footer div {
width: 33%;
}

@media only screen and (min-width: 1560px) {
.workspace-container {
grid-template-columns: repeat(6, 14vw);
grid-auto-rows: 14vw;
}
}

img {
width: 100%;
height: 100%
}


</style>
</head>
<body>
<div class="wrapper">
<h2>Select your onboarding experience.</h2>
<div class="workspace-container" id="container"></div>
<footer>
<div>
<h3>ONBOARDING WORKSPACE</h3>
<p>The onboarding workspace is the one you will use to learn the basic operation of the platform. Superalgos can trade with all major exchanges, and your selection will not affect which exchanges you may trade with in the future.</p>
</div>
<div>
<h3>PARTNER EXCHANGES WORKSPACES</h3>
<p>Partner exchanges have custom workspaces and offer preferential trading fees for Superalgos users. If your favorite exchange is on the list, then go for it! If you're not a customer yet, find the referral link in the corresponding Telegram group.</p>
</div>
<div>
<h3>FALLBACK WORKSPACE</h3>
<p>The fallback workspace uses Binance or Binance US as the active exchange. Use this workspace if you're not interested in trading with one of the Partner Exchanges to benefit from discounted trading fees. Later on, you may switch to any other exchange.</p>
</div>
</footer>
</div>
<script>
// Here we receive the array with all the available workspaces to create the list
window.onload = () => {
window.api.send("toMain", "getExchanges")
window.api.receive('fromMain', (data) => {
var exchanges = data
for (x = 0; x < exchanges.length; x++) {
var item = exchanges[x]
var img = document.createElement("img")
img.id = item
item = item.split('-')[2].split('.')[0]
img.src = "Projects/Foundations/Icons/Crypto-Exchanges/" + item.toLowerCase() + '.png' // get the exchange image
img.setAttribute('onclick', "exchange(this.id)")
var newElement = document.createElement("div")
newElement.appendChild(img)
document.getElementById('container').appendChild(newElement)
}
var fallback = document.createElement("img")
fallback.id = "Getting-Started-Tutorials.json"
fallback.src = "Projects/Foundations/Icons/Crypto-Exchanges/fallback-workspace.png"
fallback.setAttribute('onclick', "exchange(this.id)")
var newElem = document.createElement("div")
newElem.appendChild(fallback)
document.getElementById('container').appendChild(newElem)
})
}

// Send the workspace to start the platform
function exchange(id) {
window.api.send("toMain", id)
}
</script>
</body>
</html>

0 comments on commit 930b5dd

Please sign in to comment.