Skip to content

Commit b40904b

Browse files
committed
Implementing #1
1 parent 6baeead commit b40904b

File tree

5 files changed

+114
-30
lines changed

5 files changed

+114
-30
lines changed

check.html

+27-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,37 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>PHP Assistant: First run check...</title>
6+
<link href="css/bootstrap.min.css" type="text/css" rel="stylesheet">
67
<link href="css/check.css" type="text/css" rel="stylesheet">
78
<script>window.$ = window.jQuery = require('./js/jquery.js');</script>
89
<script src="js/check.js" type="text/javascript" charset="utf-8"></script>
910
</head>
1011
<body>
11-
First run...
12-
<br>
12+
<div>
13+
<p class="text-center"><img src="./gfx/app-icon.png" height="160"></p>
14+
</div>
15+
<div id="output" class="alert alert-danger">
16+
Preparing to start app for the first time...
17+
</div>
18+
<div id="find-or-quit">
19+
<!-- Browse button-->
20+
<div><button id="browse" class="btn btn-lg btn-primary"><i class="glyphicon glyphicon-folder-open" aria-hidden="true"></i> &nbsp;Browse to PHP binary</button></div>
21+
22+
<!-- Type button -->
23+
<div><button id="type" class="btn btn-lg btn-info"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i> &nbsp;Type PHP binary location</button></div>
24+
<div class="row" id="type-input">
25+
<div class="col-lg-6">
26+
<form><div class="input-group input-group-lg">
27+
<input id="path" type="text" placeholder="Type PHP binary location" class="form-control">
28+
<span class="input-group-btn">
29+
<button class="btn btn-success" id="type-done">Done</button>
30+
</span>
31+
</div></form>
32+
</div>
33+
</div>
34+
35+
<!-- Quit button -->
36+
<div><button id="quit" class="btn btn-lg btn-default"><i class="glyphicon glyphicon-log-out" aria-hidden="true"></i> Quit</button></div>
37+
</div>
1338
</body>
1439
</html>

css/check.css

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
body{
2-
background: #000;
3-
color: #fff;
4-
font-family: monospace;
5-
font-size: 14px;
2+
background: #fff;
3+
margin-top: 50px;
4+
}
5+
#output{
6+
margin-top: 30px;
7+
font-size: 40px;
8+
text-align: center;
9+
border-radius: 0;
10+
border-left: none;
11+
}
12+
#find-or-quit{
13+
margin-top:40px;
14+
text-align: center;
15+
visibility: hidden;
16+
}
17+
#find-or-quit div{
18+
margin-bottom: 10px;
19+
}
20+
#type-input{
21+
width: 500px;
22+
margin: 0 auto;
23+
display: none;
624
}

js/check.js

+62-20
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
var fs = require('fs');
55
const Configstore = require('configstore');
66
const pkg = require('./package.json');
7-
const conf = new Configstore(pkg.name)
7+
const conf = new Configstore(pkg.name);
8+
const dialog = require("remote").dialog;
89
var os;
910

1011
var unix_paths = [
@@ -13,43 +14,49 @@ var unix_paths = [
1314
"/etc/php",
1415
"/usr/lib/php",
1516
"/usr/share/php"
16-
]
17+
];
1718

1819
var win_paths = [
1920
"C:\\php\\php.exe",
2021
"C:\\xampp\\php\\php.exe"
21-
]
22+
];
2223

2324
var locale = window.navigator.userLanguage || window.navigator.language;
2425

2526
$(function() {
27+
// Buttons actions
28+
$("#browse").click(browse); // Invoke browse();
29+
$("#type").click(type); // Invoke type();
30+
$("#type-done").click(typeDone); // Invoke typeDone();
31+
$("#quit").click(function(){ require("remote").app.quit(); });
2632

33+
// Startup routines
2734
// Save locale
2835
if (locale)
2936
conf.set("general.locale", locale);
3037
else
3138
conf.set("general.locale", "en");
3239

3340
// Check OS
34-
checkWrite("Detecting system... ",0);
41+
console.log("Detecting system... ");
3542

3643
if (process.platform == "win32") {
3744
os = "win";
38-
checkWrite("Windows",1);
45+
console.log("Windows");
3946
}
4047
else if (process.platform == 'darwin') {
4148
os = "osx";
42-
checkWrite("Mac OSX",1);
49+
console.log("Mac OSX");
4350
}
4451
else {
4552
os = "linux";
46-
checkWrite("Linux",1);
53+
console.log("Linux");
4754
}
4855

4956
conf.set("system.os", os);
5057

5158
// Searching for PHP binary
52-
checkWrite("Trying to find PHP binary... ",0);
59+
console.log("Trying to find PHP binary... ");
5360
switch (os) {
5461
case "osx":
5562
case "linux":
@@ -77,23 +84,58 @@ function checkPhpPath(list, index) {
7784
}
7885

7986
function phpFound(path) {
80-
checkWrite("Found! ("+path+")", 1);
81-
checkWrite("Storing data...", 0);
87+
$("#output").toggleClass("alert-danger alert-success");
88+
console.log("Found! ("+path+")");
89+
console.log("Storing data...");
8290
conf.set("php.path", path);
83-
checkWrite("Done!",1);
84-
checkWrite("Starting app...");
85-
// Wait for 1.5 second, just in the first run
86-
setTimeout('window.location = "index.html"', 1500);
91+
console.log("Done!");
92+
console.log("Starting app...");
93+
94+
checkWrite("PHP binary found! ("+path+")<br>Starting app...");
95+
// Wait for 2 seconds, just in the first run
96+
setTimeout('window.location = "index.html"', 2000);
8797
}
8898

8999
function phpNotFound() {
90-
// @TODO Implement instructions and possibility to search for PHP binary
91-
checkWrite("Not found. Install PHP and try again.");
100+
console.log("Not found. Install PHP and try again.");
101+
102+
checkWrite("Could not find PHP binary!");
103+
phpSearchOptions(true);
104+
}
105+
106+
function checkWrite(text) {
107+
$("#output").html(text);
108+
}
109+
110+
function browse() {
111+
var file = dialog.showOpenDialog({
112+
"title": "Find PHP binary"
113+
});
114+
115+
if (file) {
116+
phpSearchOptions(false);
117+
phpFound(file);
118+
}
119+
}
120+
121+
function type() {
122+
$("#type").css("display", "none");
123+
$("#type-input").css("display", "block");
124+
$("form").on("submit", function() { return false; }); // Prevents form default
125+
$("#path").focus();
126+
}
127+
128+
function typeDone() {
129+
var tPath = $("#path").val();
130+
if (fs.lstatSync(tPath).isFile())
131+
phpFound(tPath);
132+
else
133+
$("#output").html("Oops! Invalid binary or the file doesn't exists.");
92134
}
93135

94-
function checkWrite(text, br) {
95-
if (br)
96-
$("body").append(text + "<br>");
136+
function phpSearchOptions(show) {
137+
if (show)
138+
$("#find-or-quit").css("visibility", "visible");
97139
else
98-
$("body").append(text);
140+
$("#find-or-quit").css("visibility", "hidden");
99141
}

js/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function renderApp(refresh) {
8989
$("#sidebar-clear").click(clear); // Invoke clear()
9090

9191
// "Import from file" button click
92-
$("#sidebar-import").click(importFromFile); // Invoke toggleMode()
92+
$("#sidebar-import").click(importFromFile); // Invoke importFromFile()
9393

9494
// "Quit" butotn click
9595
$("#sidebar-quit").click(quit); // Invoke quit();

main.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ function startApp() {
3838

3939
// Set tray icon
4040
var trayIcon = Path.join(__dirname, 'gfx');
41-
if (process.platform !== 'darwin') {
41+
if (process.platform !== 'darwin')
4242
trayIcon = Path.join(trayIcon, 'tray.png');
43-
} else {
43+
else
4444
trayIcon = Path.join(trayIcon, 'tray-black.png');
45-
}
4645

4746
appIcon = new Tray(trayIcon);
4847
// var contextMenu = Menu.buildFromTemplate([

0 commit comments

Comments
 (0)