1 package com.jsql;
2
3 import com.jsql.model.InjectionModel;
4 import com.jsql.util.GitUtil.ShowOnConsole;
5 import com.jsql.util.I18nUtil;
6 import com.jsql.util.LogLevelUtil;
7 import com.jsql.view.swing.JFrameView;
8 import com.jsql.view.swing.util.MediatorHelper;
9 import org.apache.logging.log4j.Level;
10 import org.apache.logging.log4j.LogManager;
11 import org.apache.logging.log4j.Logger;
12
13 import java.awt.*;
14
15
16
17
18
19 public class MainApplication {
20
21 private static final Logger LOGGER = LogManager.getRootLogger();
22
23 private static final InjectionModel injectionModel;
24
25 static {
26
27 System.setProperty("jdk.httpclient.allowRestrictedHeaders", "connection,content-length,expect,host,upgrade");
28
29 if (GraphicsEnvironment.isHeadless()) {
30 LOGGER.log(
31 Level.ERROR,
32 "Headless runtime detected, please install or use default Java runtime instead of headless runtime"
33 );
34 System.exit(1);
35 }
36
37 injectionModel = new InjectionModel();
38 injectionModel.getMediatorUtils().getPreferencesUtil().loadSavedPreferences();
39
40 MainApplication.apply4K();
41 }
42
43 private MainApplication() {
44
45 }
46
47
48
49
50
51 public static void main(String[] args) {
52
53
54 MediatorHelper.register(injectionModel);
55
56
57 injectionModel.getMediatorUtils().getExceptionUtil().setUncaughtExceptionHandler();
58 injectionModel.getMediatorUtils().getProxyUtil().initializeProxy();
59 injectionModel.getMediatorUtils().getAuthenticationUtil().setKerberosCifs();
60
61 try {
62 var view = new JFrameView();
63 MediatorHelper.register(view);
64
65 injectionModel.subscribe(view.getSubscriber());
66
67 } catch (HeadlessException e) {
68
69 LOGGER.log(
70 LogLevelUtil.CONSOLE_JAVA,
71 String.format(
72 "HeadlessException, command line execution in jSQL not supported yet: %s",
73 e.getMessage()
74 ),
75 e
76 );
77 return;
78
79 } catch (AWTError e) {
80
81
82 LOGGER.log(
83 LogLevelUtil.CONSOLE_JAVA,
84 String.format(
85 "Java Access Bridge missing or corrupt, check your access bridge definition in JDK_HOME/jre/lib/accessibility.properties: %s",
86 e.getMessage()
87 ),
88 e
89 );
90 return;
91 }
92
93 injectionModel.displayVersion();
94
95 if (injectionModel.getMediatorUtils().getProxyUtil().isNotLive(ShowOnConsole.YES)) {
96 return;
97 }
98
99 if (injectionModel.getMediatorUtils().getPreferencesUtil().isCheckingUpdate()) {
100 injectionModel.getMediatorUtils().getGitUtil().checkUpdate(ShowOnConsole.NO);
101 }
102
103 I18nUtil.checkCurrentLanguage();
104 injectionModel.getMediatorUtils().getGitUtil().showNews();
105
106 MainApplication.check4K();
107 }
108
109 private static void apply4K() {
110
111 if (injectionModel.getMediatorUtils().getPreferencesUtil().is4K()) {
112
113
114 System.setProperty("sun.java2d.uiScale", "2.5");
115 }
116 }
117
118 private static void check4K() {
119
120 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
121 int width = (int) screenSize.getWidth();
122
123 if (width >= 3840 && !injectionModel.getMediatorUtils().getPreferencesUtil().is4K()) {
124
125 LOGGER.log(LogLevelUtil.CONSOLE_ERROR, "Your screen seems compatible with 4K resolution, enable high-definition mode in Preferences");
126 }
127 }
128 }