diff --git a/build/exchanges/AscendEX.png b/build/exchanges/AscendEX.png new file mode 100644 index 0000000000..bd27f8b398 Binary files /dev/null and b/build/exchanges/AscendEX.png differ diff --git a/build/exchanges/binance.jpg b/build/exchanges/binance.jpg new file mode 100644 index 0000000000..7fc0910978 Binary files /dev/null and b/build/exchanges/binance.jpg differ diff --git a/build/exchanges/kraken.jpg b/build/exchanges/kraken.jpg new file mode 100644 index 0000000000..391a7567fa Binary files /dev/null and b/build/exchanges/kraken.jpg differ diff --git a/electron-wrapper.js b/electron-wrapper.js index d73af24518..611c0b6ab3 100644 --- a/electron-wrapper.js +++ b/electron-wrapper.js @@ -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()} }) } @@ -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, @@ -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()) { @@ -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 () { @@ -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', @@ -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', @@ -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') } }, { @@ -271,15 +342,6 @@ function createMainMenus() { } function createConsoleMenus () { - - function uiActive() { - if(mainWindow.isVisible()) { - return false - } else { - return true - } - } - const consoleTemplate = [ { label: 'File', @@ -319,10 +381,7 @@ function createConsoleMenus () { { label: 'Show UI', id: 'ui', - enabled: uiActive(), - click () { - mainWindow.show() - } + click () {mainWindow.isVisible() ? mainWindow.focus() : mainWindow.show()} } ] diff --git a/selection.html b/selection.html new file mode 100644 index 0000000000..eaa9b982bb --- /dev/null +++ b/selection.html @@ -0,0 +1,120 @@ + + + + + Select Workspace + + + + +
+

Select your onboarding experience.

+
+ +
+ + + \ No newline at end of file