Skip to content

Commit ba8bd6a

Browse files
committed
# Version 1.0.1
* Generic cookie story class created. * The main window controller is moved to a separate class. * An application configuration management class has been created. * Created a class for managing the list of local servers. * Fixed errors with cookies when working on the same host with different ports. * Made saving the position of the main window.
1 parent 0732a25 commit ba8bd6a

File tree

11 files changed

+523
-296
lines changed

11 files changed

+523
-296
lines changed

build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
//file:noinspection GrUnresolvedAccess
44
*/
55

6+
import org.apache.tools.ant.filters.ReplaceTokens
7+
8+
import java.text.DateFormat
9+
import java.text.SimpleDateFormat
10+
611
plugins {
712
id 'groovy'
813
id 'java-library'
@@ -31,3 +36,10 @@ dependencies {
3136
implementation("net.sourceforge.getl:getl:$getl_version")
3237
testImplementation 'junit:junit:4.13.2'
3338
}
39+
40+
processResources {
41+
println 'Generate version resources ...'
42+
filesMatching('webfx.properties') {
43+
filter(ReplaceTokens, tokens: [version: version.toString(), builddate: new SimpleDateFormat('yyyy-MM-dd').format(new Date())])
44+
}
45+
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
webfx_version=1.0.0
1+
webfx_version=1.0.1
22
getl_version=4.14.2
Lines changed: 28 additions & 201 deletions
Original file line numberDiff line numberDiff line change
@@ -1,245 +1,72 @@
11
//file:noinspection unused
22
package ru.easydata.webfx.app
33

4-
import getl.config.ConfigSlurper
5-
import getl.utils.BoolUtils
64
import getl.utils.FileUtils
7-
import getl.utils.Logs
85
import getl.utils.MapUtils
96
import javafx.application.Application
107
import javafx.fxml.FXMLLoader
118
import javafx.scene.Parent
129
import javafx.scene.Scene
1310
import javafx.scene.image.Image
11+
import javafx.stage.Screen
1412
import javafx.stage.Stage
13+
import ru.easydata.webfx.config.ConfigManager
1514
import ru.easydata.webfx.controllers.MainController
16-
import ru.easydata.webfx.exception.LocalServerAlreadyRegister
17-
import ru.easydata.webfx.exception.LocalServerUnknown
18-
import ru.easydata.webfx.servers.LocalServer
19-
import ru.easydata.webfx.utils.Functions
2015

2116
class WebFxApplication extends Application {
22-
@SuppressWarnings('SpellCheckingInspection')
2317
static void main(String[] args) {
24-
Logs.Init()
25-
18+
Map<String, Object> mainArguments = null
2619
if (args != null && args.length > 0)
27-
mainArguments.putAll(MapUtils.ProcessArguments(args))
20+
mainArguments = MapUtils.ProcessArguments(args)
2821

29-
titleMainWindow = System.getProperty('APP_TITLE')?:'EasyData WebFx Browser'
30-
userDirPath = FileUtils.ConvertToUnixPath((System.getProperty('USER_DIR') != null)?
22+
def titleMainWindow = System.getProperty('APP_TITLE')?:'EasyData WebFx Browser'
23+
def userDirPath = FileUtils.ConvertToUnixPath((System.getProperty('USER_DIR') != null)?
3124
System.getProperty('USER_DIR'):System.getProperty("user.home") + "/easydata/webfxapplication")
3225

33-
FileUtils.ValidFilePath(userDirPath)
34-
FileUtils.ValidFilePath("$userDirPath/userdata")
35-
36-
Logs.global.logFileName = userDirPath + '/log/easyworkspace-{date}.log'
37-
Logs.Info "*** Start $titleMainWindow"
38-
Logs.Info "User data directory: $userDirPath"
39-
40-
launch(this, args)
41-
}
42-
43-
static public final Map<String, Object> mainArguments = [:] as Map<String, Object>
44-
45-
static public String titleMainWindow
46-
static public final Image mainIcon
47-
static public String userDirPath
48-
49-
static {
26+
Image mainIcon
5027
try (def iconStream = this.getResourceAsStream("/icons/icon.png")) {
5128
mainIcon = new Image(iconStream)
5229
}
53-
}
54-
55-
public Stage mainWindow
56-
public final File userDir = new File(userDirPath)
57-
public final File engineConfigFile = new File(userDir.path + '/engine.conf')
58-
59-
public final File favoritesConfigFile = new File(userDir.path + '/favorites.conf')
60-
private final MainController controller = new MainController(this)
61-
62-
private Boolean autoStartServers
63-
Boolean getAutoStartServers() { autoStartServers }
64-
65-
private Boolean autoStopServers
66-
Boolean getAutoStopServers() { autoStopServers }
67-
68-
private Boolean sslVerification
69-
Boolean getSslVerification() { sslVerification }
70-
71-
public final Map<String, Map<String, Map<String, Object>>> favorites = [:] as Map<String, Map<String, Map<String, Object>>>
72-
73-
Map<String, Map<String, Map<String, Object>>> loadConfigFavorites() {
74-
if (!favoritesConfigFile.exists())
75-
return [:] as Map<String, Map<String, Map<String, Object>>>
76-
77-
return ConfigSlurper.LoadConfigFile(file: favoritesConfigFile) as Map<String, Map<String, Map<String, Object>>>
78-
}
79-
80-
void saveConfigFavorites() {
81-
if (favoritesConfigFile.exists()) {
82-
FileUtils.CopyToFile(favoritesConfigFile, new File(FileUtils.ExcludeFileExtension(favoritesConfigFile.path) + '.bak'))
83-
}
84-
ConfigSlurper.SaveConfigFile(data: favorites, file: favoritesConfigFile)
85-
}
86-
87-
static private final Map<String, Object> defaultEngineOptions = [
88-
engine: [
89-
ssl_verification: false,
90-
https: [
91-
protocols: 'TLSv1,TLSv1.1,TLSv1.2'
92-
]
93-
]
94-
]
95-
96-
public final List<LocalServer> localServers = new LinkedList<LocalServer>()
97-
98-
LocalServer findServerByName(String name) {
99-
if (name == null)
100-
throw new NullPointerException("Null name!")
101-
102-
name = name.trim().toLowerCase()
103-
localServers.find { it.name.toLowerCase() == name }
104-
}
105-
106-
LocalServer findServerByUri(URI uri) {
107-
if (uri == null)
108-
throw new NullPointerException("Null uri!")
109-
110-
localServers.find { (it.uri == uri) }
111-
}
112-
113-
LocalServer findServerByUrl(String url) {
114-
if (url == null)
115-
throw new NullPointerException("Null url!")
116-
117-
return findServerByUri(Functions.Url2UriWithRoot(url))
118-
}
119-
120-
121-
void registerLocalServer(String name, String url, String directory, String command, Integer commandTimeout,
122-
String shutdownService, Integer shutdownTimeout, String encode) {
123-
if (name == null || name.length() == 0)
124-
throw new NullPointerException("Null name!")
125-
126-
if (url == null || url.length() == 0)
127-
throw new NullPointerException("Null url!")
128-
129-
if (command == null || command.length() == 0)
130-
throw new NullPointerException("Null command!")
131-
132-
if (findServerByName(name) != null || findServerByUrl(url) != null)
133-
throw new LocalServerAlreadyRegister(name, url)
134-
135-
localServers.add(new LocalServer(this, name, url, directory, command, commandTimeout, shutdownService, shutdownTimeout, encode))
136-
Logs.Info "Registered local server $name with url $url"
137-
}
138-
139-
void unregisterLocalServer(String name) {
140-
if (name == null || name.length() == 0)
141-
throw new NullPointerException("Null name!")
142-
143-
def server = findServerByName(name)
144-
if (server == null)
145-
throw new LocalServerUnknown(name)
146-
147-
if (!server.isStop) {
148-
server.stop()
149-
}
150-
151-
localServers.remove(server)
152-
Logs.Info "Unregistered local server $name with ${server.uri.toString()}"
153-
}
154-
155-
void stopLocalServer(String name) {
156-
if (name == null || name.length() == 0)
157-
throw new NullPointerException("Null name!")
158-
159-
def server = findServerByUrl(name)
160-
if (server == null)
161-
throw new LocalServerUnknown(name)
162-
163-
if (!server.isStop)
164-
server.stop()
165-
}
166-
167-
void initEngine() {
168-
def fileData = (engineConfigFile.exists())?ConfigSlurper.LoadConfigFile(file: engineConfigFile):defaultEngineOptions
169-
def engConfig = (fileData.engine as Map<String, Object>)?:[:] as Map<String, Object>
170-
171-
sslVerification = BoolUtils.IsValue(engConfig.ssl_verification)
172-
Logs.Info "SSL verification: $sslVerification"
173-
174-
autoStartServers = BoolUtils.IsValue(engConfig.autostart_servers)
175-
Logs.Info "Auto start local servers: $autoStartServers"
176-
177-
autoStopServers = BoolUtils.IsValue(engConfig.autostop_servers)
178-
Logs.Info "Auto stop local servers: $autoStopServers"
179-
180-
def httpsConfig = (engConfig.https as Map<String, Object>)?:[:] as Map<String, Object>
181-
httpsConfig.each { key, value ->
182-
Logs.Info "https.${key} = $value"
183-
System.setProperty("https.$key".toString(), value.toString())
184-
}
185-
186-
def httpConfig = (engConfig.http as Map<String, Object>)?:[:] as Map<String, Object>
187-
httpConfig.each { key, value ->
188-
Logs.Info "http.${key} = $value"
189-
System.setProperty("http.$key".toString(), value.toString())
190-
}
19130

192-
if (!sslVerification)
193-
Functions.DisableSslVerification()
194-
195-
def serversConfig = (fileData.servers as Map<String, Map<String, Object>>)?:[:] as Map<String, Map<String, Object>>
196-
serversConfig.each { name, data ->
197-
registerLocalServer(name, data.url as String, data.directory as String, data.command as String, data.command_timeout as Integer,
198-
data.shutdown as String, data.shutdown_timeout as Integer, data.encode as String)
199-
}
200-
Logs.Info ">>> Application started"
201-
}
202-
203-
void unregisterLocalServers() {
204-
synchronized (localServers) {
205-
localServers.each { server ->
206-
unregisterLocalServer(server.name)
207-
}
208-
}
31+
ConfigManager.config.init(userDirPath, titleMainWindow, mainIcon, mainArguments)
32+
launch(this, args)
20933
}
21034

21135
@Override
21236
void start(Stage stage) {
213-
initEngine()
214-
favorites.putAll(loadConfigFavorites())
37+
def controller = new MainController(stage)
21538

21639
def loader = new FXMLLoader()
21740
def url = getClass().getResource('/fxml/main.fxml')
21841
loader.setLocation(url)
21942
loader.controller = controller
22043
def root = loader.load() as Parent
221-
22244
controller.initFavorites()
22345

22446
stage.tap {
225-
addShutdownHook {
226-
unregisterLocalServers()
227-
}
228-
229-
setTitle(titleMainWindow)
230-
icons.add(mainIcon)
47+
setTitle(ConfigManager.config.titleMainWindow)
48+
icons.add(ConfigManager.config.mainIcon)
23149

23250
scene = new Scene(root)
233-
stage.maximized = true
234-
stage.width = 600
235-
stage.height = 400
236-
stage.show()
237-
}
23851

239-
mainWindow = stage
52+
minWidth = 620
53+
minHeight = 460
54+
55+
def screenBounds = Screen.getPrimary().getBounds()
56+
57+
width = screenBounds.width - 10
58+
height = screenBounds.height - 100
59+
centerOnScreen()
60+
61+
//maximized = true
62+
63+
ConfigManager.config.monitorWindow('MainWindow', stage)
64+
65+
show()
66+
}
24067
}
24168

24269
void stop() {
243-
unregisterLocalServers()
70+
ConfigManager.config.doneEngine()
24471
}
24572
}

0 commit comments

Comments
 (0)