Skip to content

Commit 063ad70

Browse files
committed
starter, pio-inst
1 parent 4a7e968 commit 063ad70

File tree

5 files changed

+302
-10
lines changed

5 files changed

+302
-10
lines changed

app/pio-inst.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const PIO_CORE_MIN_VERSION = '3.5.2-rc.3';
2+
const STORAGE_STATE_KEY = 'platformio-ide:installer-state';
3+
4+
const pioNodeHelpers = require('platformio-node-helpers');
5+
const StateStorage = require('./state-storage');
6+
7+
class PythonPrompt {
8+
constructor() {
9+
this.STATUS_TRY_AGAIN = 0;
10+
this.STATUS_ABORT = 1;
11+
this.STATUS_CUSTOMEXE = 2;
12+
}
13+
async prompt(){
14+
return { status: this.STATUS_ABORT };
15+
}
16+
}
17+
18+
function installer() {
19+
var obj = {};
20+
obj.stateStorage = new StateStorage(STORAGE_STATE_KEY);
21+
obj.onDidStatusChange = function () { console.log('onDidStatusChange', arguments)}
22+
23+
var i = new pioNodeHelpers.installer.PlatformIOCoreStage(obj.stateStorage, obj.onDidStatusChange, {
24+
pioCoreMinVersion: PIO_CORE_MIN_VERSION,
25+
useBuiltinPIOCore: true,
26+
setUseBuiltinPIOCore: (value) => console.log('platformio-ide.advanced.useBuiltinPIOCore', value),
27+
useDevelopmentPIOCore: false,
28+
pythonPrompt: new PythonPrompt()
29+
})
30+
if(process.platform.startsWith('win') && process.env.PATH.indexOf('.platformio') < 0)
31+
process.env.PATH+=";"+process.env.USERPROFILE+"\\.platformio\\penv\\Scripts;";
32+
return i;
33+
}
34+
module.exports=installer();
35+
//i.check().then(console.log).catch(console.error);
36+
//installer().install().then(console.log).catch(console.error);

app/state-storage.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
/** @babel */
3+
4+
/**
5+
* Copyright (c) 2017-present PlatformIO <[email protected]>
6+
* All rights reserved.
7+
*
8+
* This source code is licensed under the license found in the LICENSE file in
9+
* the root directory of this source tree.
10+
*/
11+
12+
module.exports = class StateStorage {
13+
14+
constructor(stateKey) {
15+
this.stateKey = stateKey;
16+
}
17+
18+
_loadState() {
19+
const value = localStorage.getItem(this.stateKey);
20+
if (!value) {
21+
return {};
22+
}
23+
try {
24+
return JSON.parse(value);
25+
} catch (err) {
26+
console.error(err);
27+
}
28+
return {};
29+
}
30+
31+
getValue(key) {
32+
const data = this._loadState();
33+
if (data && data.hasOwnProperty(key)) {
34+
return data[key];
35+
}
36+
return null;
37+
}
38+
39+
setValue(key, value) {
40+
const data = this._loadState();
41+
data[key] = value;
42+
localStorage.setItem(this.stateKey, JSON.stringify(data));
43+
}
44+
45+
}

index.js

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ var fs = require('fs');
1010
var promisify = require('./app/helpers').promisify;
1111
var git = require('./app/git-tool');
1212
var server = require('./app/server');
13+
const store = require('data-store')('marlin-config');
14+
const pio = require('./app/pio-inst');
15+
const gitExe = 'git';
1316

1417
var mainWindow = null;
1518
var getFolder=()=>new Promise((done,fail)=>
@@ -24,6 +27,7 @@ var getFolder=()=>new Promise((done,fail)=>
2427
})
2528
)
2629
app.on('window-all-closed', () => {
30+
console.log('window-all-closed');
2731
app.quit()
2832
})
2933
function showNotify(text){
@@ -39,18 +43,49 @@ ipcMain.on('search-text', (event, arg) => {
3943
var wc = mainWindow && mainWindow.webContents;
4044
arg.length && wc.findInPage(arg) || wc.stopFindInPage('clearSelection');
4145
})
46+
ipcMain.on('starter-pio', function(ev) {
47+
pio.install()
48+
.then(result => ev.sender.send('starter-pio', result))
49+
.catch(e => dialog.showErrorBox('Error', e))
50+
})
4251

4352
app.on('ready', function() {
44-
promisify(which)('git')
45-
.then(function(){
46-
var is={'-G':0}
47-
.filter((v,key,o,p,i)=>(p=process.argv,i=p.indexOf(key),!v&&i>=0&&i+1<p.length&&(o[key]=p[i+1]),i>=0));
48-
var chain = () => getFolder().then(dir =>
53+
var status = new BrowserWindow({width: 400, height: 400, maximizable: false})
54+
status.setMenu(null);
55+
var folders = store.get('folders') || [];
56+
var opts = {'-G': 0};
57+
Object.keys(opts).reduce((v, key) => (v.i = v.p.indexOf(key), v.i >= 0 && (opts[key] = v.p[v.i + 1]), v), {p: process.argv});
58+
59+
Promise.all([
60+
promisify(which)(gitExe).then(a => 1).catch(a => 0),
61+
promisify(which)('pio').then(a => 1).catch(a => 0),
62+
promisify(fs.readFile)(path.join(__dirname, 'views', 'start.html')),
63+
])
64+
.then(p => {
65+
var statusFile = 'data:text/html;charset=UTF-8,' + encodeURIComponent(p[2].toString());
66+
status.loadURL(statusFile);
67+
status.show()
68+
ipcMain.on('starter-init', ev => {
69+
ev.sender.send('starter-init', {
70+
git: p[0],
71+
pio: p[1],
72+
folders: folders,
73+
})
74+
})
75+
return (new Promise(function(resolve, reject) {
76+
ipcMain.on('starter-folder', function(ev, num) {
77+
resolve(num == 'new' ? '' : folders[num]);
78+
})
79+
}))
80+
})
81+
.then(folder => promisify(which)(gitExe).then(a => folder))
82+
.then(function(folder) {
83+
const check = dir =>
4984
promisify(fs.access)(dir, fs.constants.W_OK)
5085
.then(a => dir)
5186
.catch(e => (dialog.showErrorBox('Access','The application hasn\'t access to this folder,\nselect a folder from my Documents or Desktop'),chain()))
52-
);
53-
return is['-G'] || chain();
87+
const chain = () => getFolder().then(check);
88+
return folder && check(folder) || opts['-G'] || chain();
5489
})
5590
.then(dir => git.root(dir)
5691
.catch(e => {
@@ -63,6 +98,13 @@ app.on('ready', function() {
6398
.catch(e => git.root(dir));
6499
})
65100
)
101+
.then(folder => {
102+
var i = folders.indexOf(folder);
103+
i >= 0 && folders.splice(i, 1);
104+
folders.unshift(folder);
105+
store.set('folders', folders);
106+
return folder;
107+
})
66108
.then(()=>server.main(1))
67109
.then(function(url){
68110
mainWindow = new BrowserWindow({
@@ -74,12 +116,17 @@ app.on('ready', function() {
74116
},
75117
});
76118
mainWindow.loadURL(url);
119+
status.close();
77120
mainWindow.webContents.on('found-in-page', function (event, result) {
78121
var count = 0;
79122
if (result && result.finalUpdate)
80123
count = result.matches;
81124
event.sender.send('search-found', count);
82125
});
126+
mainWindow.on('close', function() {
127+
console.log('quit()')
128+
app.quit();
129+
})
83130
})
84131
.catch(e => {
85132
console.error(e.message);

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "marlin-conf",
3-
"version": "2.8.2",
3+
"version": "2.9.0",
44
"description": "configuration tool for Marlin project",
55
"main": "./index.js",
66
"scripts": {
77
"start": "electron . -G ~/TEST",
88
"build": "build --dir",
9-
"build-dev": "build -m --x64",
9+
"build-dev": "build -w --x64",
1010
"dist": "GH_TOKEN=`./node_modules/.bin/json -f ~/.github.json -c 'console.log(this.OAuth)'` build -mwl --x64 --ia32 -p always",
1111
"test": "echo \"Error: no test specified\" && exit 1",
1212
"lint": "eslint .",
@@ -59,6 +59,7 @@
5959
"body-parser": "^1.17.2",
6060
"bootstrap": "4.0.0-alpha.6",
6161
"cropper": "^3.1.5",
62+
"data-store": "^1.0.0",
6263
"express": "^4.16.2",
6364
"fix-path": "^2.1.0",
6465
"font-awesome": "^4.7.0",
@@ -76,6 +77,7 @@
7677
"node-machine-id": "^1.1.10",
7778
"node-notifier": "^5.2.1",
7879
"opn": "^5.2.0",
80+
"platformio-node-helpers": "^0.4.3",
7981
"qr-image": "^3.2.0",
8082
"rtcmulticonnection-v3": "^3.4.4",
8183
"serialport": "^6.1.0",
@@ -92,7 +94,7 @@
9294
},
9395
"devDependencies": {
9496
"devtron": "^1.4.0",
95-
"electron": "^1.8.2",
97+
"electron": "1.7.x",
9698
"electron-builder": "^20.2.0",
9799
"electron-debug": "^1.5.0",
98100
"eslint": "^4.18.1",

views/start.html

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
2+
<style type="text/css">
3+
body {
4+
display: flex;
5+
text-align:center;
6+
}
7+
.starter {
8+
width: 400px;
9+
margin: auto;
10+
}
11+
.component {
12+
width: 150px;
13+
height: 150px;
14+
border-radius: 5px;
15+
display: inline-block;
16+
border: 1px solid red;
17+
background-color: pink;
18+
margin: 5px;
19+
text-align: center;
20+
vertical-align: top;
21+
}
22+
.component>div {
23+
height: 50%;
24+
padding:10px;
25+
box-sizing: border-box;
26+
}
27+
.component .state {
28+
margin:5px;
29+
*padding:5px;
30+
}
31+
.component img {
32+
max-height: 100%;
33+
max-width:100%;
34+
}
35+
.component.installed {
36+
border: 1px solid green;
37+
background-color: lightgreen;
38+
}
39+
.site {
40+
border: 1px solid black;
41+
background-color: lightyellow;
42+
}
43+
.folder {
44+
border: 1px solid black;
45+
background-color: lightblue;
46+
}
47+
button {
48+
margin: auto;
49+
display: block;
50+
background-color: greenyellow;
51+
box-shadow: 2px 2px gray;
52+
border-radius: 3px;
53+
border: solid gray 1px;
54+
transition: opacity .15s ease-in-out;
55+
cursor: pointer;
56+
user-select: none;
57+
padding: 5px 20px;
58+
vertical-align: middle;
59+
outline: none;
60+
margin-bottom: 10px;
61+
}
62+
.installed button {
63+
background-color: lightgray;
64+
}
65+
button:active {
66+
opacity: .3;
67+
box-shadow: 0 0;
68+
}
69+
ul {
70+
list-style: none;
71+
margin: 5px;
72+
padding:0;
73+
}
74+
li {
75+
white-space: nowrap;
76+
overflow: hidden;
77+
text-overflow: ellipsis;
78+
direction: rtl;
79+
text-align: left;
80+
}
81+
li:first-child {
82+
text-align:center;
83+
}
84+
li.active {
85+
background-color: gray;
86+
}
87+
li:hover {
88+
opacity: .5;
89+
}
90+
91+
</style>
92+
<script>
93+
typeof $ == 'undefined' && ($ = require('jquery'));
94+
$(function() {
95+
var shell = require('electron').shell;
96+
window.opener = shell.openExternal;
97+
98+
$('a, button[href]').on('click', function (ev) {
99+
ev.preventDefault();
100+
window.opener($(this).attr('href'), '_blank')
101+
})
102+
$('ul').on('click', 'li', function() {
103+
$(this).addClass('active').siblings().removeClass('active');
104+
})
105+
$('.pio button').on('click', function () {
106+
$(this).attr('disabled', '').siblings('.state').text('wait a minute...');
107+
ipc.send('starter-pio');
108+
})
109+
$('.folder button').on('click', function () {
110+
ipc.send('starter-folder', [$('li.active').attr('n')]);
111+
})
112+
var ipc = require('electron').ipcRenderer;
113+
ipc.send('starter-init');
114+
ipc.on('starter-pio', function(ev, data) {
115+
$('.component.pio .state').text(data ? 'instaled' : 'error');
116+
data && $('.component.pio').addClass('installed');
117+
});
118+
ipc.on('starter-init', function(ev, data) {
119+
['git','pio'].map(function(i) {
120+
var c = $('.component.' + i)
121+
data[i] && c.addClass('installed');
122+
c.find('.state').text(data[i] ? 'Installed' : 'NOT Installed');
123+
});
124+
data.pio && $('.component.pio button').text('reinstall')
125+
+(data.folders || []).slice(0,4).map(function(f, n) {
126+
$('ul').append($('<li>').text(f).attr('n', n).attr('title', f))
127+
});
128+
})
129+
})
130+
</script>
131+
<div class="starter">
132+
<div class="component git">
133+
<div><img src="https://git-scm.com/images/[email protected]" alt="git" title="git">
134+
</div><div>
135+
<div class="state">not found</div>
136+
<button href="https://git-scm.com/downloads">install</button></div>
137+
</div>
138+
<div class="component pio">
139+
<div><img src="https://platformio.org/images/platformio-logo.17fdc3bc.png" alt="PlatformIO" title="PlatformIO">
140+
</div><div title="it can take up to 5 minutes">
141+
<div class="state">not found</div>
142+
<button>auto install</button>
143+
</div>
144+
</div>
145+
146+
<div class="component site">
147+
<div><a href="https://github.com/akaJes/marlin-config"><img src="https://raw.githubusercontent.com/akaJes/marlin-config/master/build/icons/icon_128x128.png"></a></div>
148+
<div>
149+
<button href="http://lt.rv.ua/mc">configurations</button>
150+
<a href="https://www.paypal.me/AKruk508">
151+
<img src="https://img.shields.io/badge/Donate-PayPal-green.svg"></a>
152+
</div></div>
153+
154+
<div class="component folder">
155+
<br>
156+
<button>open folder</button>
157+
<ul>
158+
<li n="new" class="active">new</li>
159+
</ul>
160+
</div>
161+
162+
</div>

0 commit comments

Comments
 (0)