4
4
var fs = require ( 'fs' ) ;
5
5
const Configstore = require ( 'configstore' ) ;
6
6
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 ;
8
9
var os ;
9
10
10
11
var unix_paths = [
@@ -13,43 +14,49 @@ var unix_paths = [
13
14
"/etc/php" ,
14
15
"/usr/lib/php" ,
15
16
"/usr/share/php"
16
- ]
17
+ ] ;
17
18
18
19
var win_paths = [
19
20
"C:\\php\\php.exe" ,
20
21
"C:\\xampp\\php\\php.exe"
21
- ]
22
+ ] ;
22
23
23
24
var locale = window . navigator . userLanguage || window . navigator . language ;
24
25
25
26
$ ( 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 ( ) ; } ) ;
26
32
33
+ // Startup routines
27
34
// Save locale
28
35
if ( locale )
29
36
conf . set ( "general.locale" , locale ) ;
30
37
else
31
38
conf . set ( "general.locale" , "en" ) ;
32
39
33
40
// Check OS
34
- checkWrite ( "Detecting system... " , 0 ) ;
41
+ console . log ( "Detecting system... " ) ;
35
42
36
43
if ( process . platform == "win32" ) {
37
44
os = "win" ;
38
- checkWrite ( "Windows" , 1 ) ;
45
+ console . log ( "Windows" ) ;
39
46
}
40
47
else if ( process . platform == 'darwin' ) {
41
48
os = "osx" ;
42
- checkWrite ( "Mac OSX" , 1 ) ;
49
+ console . log ( "Mac OSX" ) ;
43
50
}
44
51
else {
45
52
os = "linux" ;
46
- checkWrite ( "Linux" , 1 ) ;
53
+ console . log ( "Linux" ) ;
47
54
}
48
55
49
56
conf . set ( "system.os" , os ) ;
50
57
51
58
// Searching for PHP binary
52
- checkWrite ( "Trying to find PHP binary... " , 0 ) ;
59
+ console . log ( "Trying to find PHP binary... " ) ;
53
60
switch ( os ) {
54
61
case "osx" :
55
62
case "linux" :
@@ -77,23 +84,58 @@ function checkPhpPath(list, index) {
77
84
}
78
85
79
86
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..." ) ;
82
90
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 ) ;
87
97
}
88
98
89
99
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." ) ;
92
134
}
93
135
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 ") ;
97
139
else
98
- $ ( "body " ) . append ( text ) ;
140
+ $ ( "#find-or-quit " ) . css ( "visibility" , "hidden" ) ;
99
141
}
0 commit comments