27
27
@ SuppressWarnings ("serial" )
28
28
public class CoursesPlusInstaller extends JFrame implements ActionListener {
29
29
public static final String VERSION = "0.1" ;
30
-
30
+
31
31
public static Logger logger ;
32
-
32
+
33
33
public static Dimension screenSize ;
34
34
35
35
public static Font font ;
36
36
public static Font bigFont ;
37
37
public static Font titleFont ;
38
38
39
- public static final String BASE_PATH = "/Users/student/ Library/Application Support/Google/Chrome/" ;
39
+ public static final String BASE_PATH = "/Users" + System . getProperty ( "user.name" ) + " Library/Application Support/Google/Chrome/" ;
40
40
public static final String FOLDER_NAME = "External Extensions" ;
41
41
public static final String EXT_ID = "pieincmodljnbihihjnapcmhdddhbpgi" ;
42
42
public static final String EXT_FILE = "{\" external_update_url\" : \" https://clients2.google.com/service/update2/crx\" }" ;
43
-
43
+
44
44
public static final String LOAD_PAGE = "data:text/html,<h1>Loading, please wait...</h1><h2>Do not navigate away from this page while installation is in progress.</h2>" ;
45
-
45
+
46
46
public CoursesPlusInstaller () {
47
47
super ("CoursesPlus Installer v" + VERSION );
48
-
48
+
49
49
logger = Logger .getLogger (CoursesPlusInstaller .class .getName ());
50
-
50
+
51
51
screenSize = java .awt .Toolkit .getDefaultToolkit ().getScreenSize ();
52
-
52
+
53
53
try {
54
54
// try and load Lato
55
55
font = Font .createFont (Font .TRUETYPE_FONT , new File ("Lato-Regular.ttf" ));
56
-
56
+
57
57
font = font .deriveFont (14f );
58
58
bigFont = font .deriveFont (32f );
59
59
titleFont = font .deriveFont (64f );
@@ -65,7 +65,7 @@ public CoursesPlusInstaller() {
65
65
bigFont = new Font ("SansSerif" , Font .PLAIN , 32 );
66
66
titleFont = new Font ("SansSerif" , Font .PLAIN , 64 );
67
67
}
68
-
68
+
69
69
setLayout (new GridLayout (3 , 1 ));
70
70
71
71
JLabel title = new JLabel ("CoursesPlus" , JLabel .CENTER );
@@ -83,10 +83,10 @@ public CoursesPlusInstaller() {
83
83
84
84
setBounds ((screenSize .width - 600 ) / 2 , (screenSize .height - 400 ) / 2 , 600 , 400 );
85
85
setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
86
-
86
+
87
87
setVisible (true );
88
88
}
89
-
89
+
90
90
public static void main (String [] args ) {
91
91
new CoursesPlusInstaller ();
92
92
}
@@ -98,14 +98,14 @@ public void actionPerformed(ActionEvent e) {
98
98
switch (text ) {
99
99
case "Install" :
100
100
JOptionPane .showMessageDialog (null , "Make sure you've closed open Chrome windows. Any windows remaining open will automatically be closed after pressing OK." , "Close Chrome windows" , JOptionPane .WARNING_MESSAGE );
101
-
101
+
102
102
try {
103
103
Runtime .getRuntime ().exec (new String []{"killall" , "Google Chrome" });
104
104
} catch (IOException e4 ) {
105
105
// TODO Auto-generated catch block
106
106
e4 .printStackTrace ();
107
107
}
108
-
108
+
109
109
File destDir = new File (BASE_PATH + FOLDER_NAME );
110
110
if (!destDir .exists ()) {
111
111
destDir .mkdir ();
@@ -132,8 +132,8 @@ public void actionPerformed(ActionEvent e) {
132
132
// TODO Auto-generated catch block
133
133
e3 .printStackTrace ();
134
134
}
135
-
136
- Path extensionDir = Paths .get ("/Users/student /Library/Application Support/Google/Chrome/Default/Extensions" );
135
+
136
+ Path extensionDir = Paths .get ("/Users/" + System . getProperty ( "user.name" ) + " /Library/Application Support/Google/Chrome/Default/Extensions" );
137
137
Set <PosixFilePermission > orig = null ;
138
138
try {
139
139
// save original Extensions dir permissions
@@ -143,15 +143,15 @@ public void actionPerformed(ActionEvent e) {
143
143
Set <PosixFilePermission > perms = Files .getPosixFilePermissions (extensionDir );
144
144
perms .add (PosixFilePermission .OWNER_WRITE );
145
145
Files .setPosixFilePermissions (extensionDir , perms );
146
-
146
+
147
147
// open Chrome
148
148
String [] cmd = {"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" , LOAD_PAGE };
149
149
Process chrome = Runtime .getRuntime ().exec (cmd );
150
150
Thread .sleep (7500 );
151
151
Runtime .getRuntime ().exec (new String []{"killall" , "Google Chrome" });
152
152
Thread .sleep (100 );
153
153
Runtime .getRuntime ().exec (new String []{"killall" , "Google Chrome" });
154
-
154
+
155
155
// restore Extensions dir permissions
156
156
Files .setPosixFilePermissions (extensionDir , orig );
157
157
} catch (IOException e1 ) {
@@ -168,17 +168,17 @@ public void actionPerformed(ActionEvent e) {
168
168
e2 .printStackTrace ();
169
169
}
170
170
}
171
-
171
+
172
172
e1 .printStackTrace ();
173
173
}
174
-
174
+
175
175
JOptionPane .showMessageDialog (null , "Done" );
176
-
176
+
177
177
break ;
178
-
178
+
179
179
default :
180
180
logger .warning ("Unknown button pressed - " + text );
181
181
break ;
182
182
}
183
183
}
184
- }
184
+ }
0 commit comments