Skip to content

Commit

Permalink
[Distribution] Add First run selection page
Browse files Browse the repository at this point in the history
  • Loading branch information
NAmorim committed Dec 28, 2021
1 parent fdb9e2e commit 66b7133
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 95 deletions.
63 changes: 37 additions & 26 deletions electron-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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, selectWindow, platform
Expand Down Expand Up @@ -39,6 +39,25 @@ function firstRun() {
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 = {
Expand All @@ -56,21 +75,16 @@ function selectionWindow() {
bw_options
)
selectWindow.loadFile('./selection.html')
selectWindow.on('focus', function () {
// Something
})
}

//run()

function run(workspace) {
const { fork } = require('child_process')
var options = ["noBrowser"]
if (workspace) {options.push(workspace)}
//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 @@ -84,13 +98,16 @@ ipcMain.on("toMain", (event, args) => {
consoleWindow.webContents.send("fromMain", data);
}
})
} else if (args.includes("workspace-")) {
var exchange = args.split('workspace-')[1]
run(exchange)
} 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 @@ -108,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 @@ -211,7 +234,6 @@ app.on('ready', function () {
} else {
run()
}
//createMainMenus()
})

app.on('window-all-closed', function () {
Expand All @@ -222,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 @@ -297,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 @@ -378,7 +390,6 @@ function createConsoleMenus () {
{
label: 'Show UI',
id: 'ui',
//enabled: uiActive(),
click () {mainWindow.isVisible() ? true : mainWindow.show()}
}
]
Expand Down
166 changes: 97 additions & 69 deletions selection.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,87 +6,115 @@

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

box-sizing: border-box;
min-height: 100vh;

background: whitesmoke;
font-family: var(--font-face);
font-size: 16px;
font-weight: 700;
line-height: 1;

justify-content: center;
align-items: center;

@media (min-width: 992px) {
border-width: 30px;
}
.wrapper {
padding: 30px;
}
h1 {
text-align: center;
transition: opacity 300ms linear;
color: var(--color-dark);
font-family: var(--font-face);
font-size: 32px;
font-weight: 700;

.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;
}
h1 span {
font-weight: 400;

footer {
display: flex;
flex-direction: row;
padding: 50px;
}
p {
max-width: 460px;
margin: 0 auto;
transition: color 300ms linear;
text-align: center;
color: var(--color-dark);
font-weight: 400;
line-height: 1.5;

footer div {
margin: 30px;
}
.container {
display: flex;
flex-direction: column;
width: 100%;
padding: 20px;

footer div {
width: 33%;
}

@media only screen and (min-width: 1560px) {
.workspace-container {
display: flex;
margin: 60px auto;
flex-wrap: wrap;
justify-content: center;
grid-template-columns: repeat(6, 14vw);
grid-auto-rows: 14vw;
}
}

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


</style>
</head>

<body>
<script>
function exchange(id) {
console.log('Selecting ' + id)
window.api.send("toMain", "workspace-" + id)
}
</script>
<div id="container">
<h1>
Select start workspace
</h1>
<p>
Select the workspace based on the exchange you want to use
</p>
<div class="workspace-container">
<div><img src="build/exchanges/AscendEX.png" height="150" size="150" alt="AscendEx" id="ascendex" onclick="exchange(this.id)"></div>
<div><img src="build/exchanges/binance.jpg" height="150" size="150" alt="Binance" id="binance" onclick="exchange(this.id)"></div>
<div><img src="build/exchanges/kraken.jpg" height="150" size="150" alt="Kraken" id="kraken" onclick="exchange(this.id)"></div>
</div>
</div>
<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>
</html>

0 comments on commit 66b7133

Please sign in to comment.