Skip to content

Commit 6b9be3f

Browse files
committed
Merge branch 'develop' into feature/#6warning_transparency
2 parents 4d3da90 + eb74428 commit 6b9be3f

File tree

13 files changed

+148
-70
lines changed

13 files changed

+148
-70
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@
2828
logs/
2929
*.jar
3030

31-
config.xml
31+
config.xml
32+
db/

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
# KeepTime
2-
Readme is WIP\
3-
Project is Beta\
4-
You will most probably have to reconfigure the application with your details if a newer version will appear.\
5-
6-
# Use
72
Application to track your time spent on different projects each day. Aim was to create an easy and fast way to track the doings over the day. In the end you get a summary for the day.
83

94
Create projects and choose if they are counted as 'work time'. Select the project you work on. Before you switch the project, write a comment on what u did. Change the project. Repeat.
@@ -22,11 +17,13 @@ Main view (when you hover over the app):\
2217
**You need to close the application manualy before you shutdown your PC. Otherwise the last running project is not saved to database.**
2318

2419
# Install
25-
Download and execute .jar file (see releases). You should put the .jar in an extra folder as a *logs* folder will be created next to it.\
20+
Download and execute .jar file (see [releases](https://github.com/doubleSlashde/KeepTime/releases)). You should put the .jar in an extra folder as a *logs* and a *db* folder will be created next to it.\
2621
It is recommended to run the application at windows start.
27-
* Copy the keeptime.bat file from this repo next to the *.jar*. Adapt the path inside the *keeptime.bat* to the name of the *.jar* file (if needed). Try starting the application by executing the *keeptime.bat* file. Close the app.
28-
* Open the autostart folder: Press *Windows+R*, execute *shell:startup*.
22+
* Copy the keeptime.bat file from this repo next to the *.jar*. Adapt the path inside the *keeptime.bat* to the name of the *.jar* file (if needed). Try starting the application by executing the *keeptime.bat* file. Close the app
23+
* Open the autostart folder: Press *Windows+R*, execute *shell:startup*
2924
* Create a shortcut to the *.bat* in the autostart folder
3025

26+
**migrate from old version**
27+
If you used this application before with a *config.xml* you can import your old projects in the settings dialog. Place your config.xml next to the jar and press "parse config.xml". Otherwise no steps are needed.
3128
## Requirements
3229
Only works correct for windows currently. Tested on 7 and 10.

pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
<artifactId>spring-boot-starter-test</artifactId>
4141
<scope>test</scope>
4242
</dependency>
43+
<!-- https://mvnrepository.com/artifact/org.flywaydb/flyway-maven-plugin -->
44+
<dependency>
45+
<groupId>org.flywaydb</groupId>
46+
<artifactId>flyway-maven-plugin</artifactId>
47+
<version>5.1.4</version>
48+
</dependency>
49+
50+
4351
<dependency>
4452
<groupId>com.1stleg</groupId>
4553
<artifactId>jnativehook</artifactId>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package de.doubleslash.keeptime;
2+
3+
import java.lang.Thread.UncaughtExceptionHandler;
4+
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
/**
9+
* Handler logging uncaught exceptions. Gotta Catch 'Em All
10+
*
11+
* @author nmutter
12+
*/
13+
public class DefaultExceptionHandler implements UncaughtExceptionHandler {
14+
15+
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
16+
17+
@Override
18+
public void uncaughtException(final Thread t, final Throwable e) {
19+
LOG.error("Uncaught exception on thread '{}'.", t, e);
20+
}
21+
22+
/**
23+
* Registers this class as default uncaught exception handler
24+
*/
25+
public void register() {
26+
LOG.debug("Registering uncaught exception handler");
27+
final UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
28+
if (defaultUncaughtExceptionHandler != null) {
29+
LOG.warn("Uncaught exception handler was already set ('{}'). Overwritting.", defaultUncaughtExceptionHandler);
30+
}
31+
Thread.setDefaultUncaughtExceptionHandler(this);
32+
}
33+
34+
}

src/main/java/de/doubleslash/keeptime/Main.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,23 @@
3636
@SpringBootApplication
3737
public class Main extends Application {
3838

39-
private ConfigurableApplicationContext springContext;
39+
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
4040

41-
public static Stage stage;
42-
Stage popupViewStage;
41+
public static final String VERSION = "v0.0.2";
4342

44-
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
43+
private ConfigurableApplicationContext springContext;
44+
45+
private Stage popupViewStage;
4546

4647
private Model model;
4748
private Controller controller;
4849

4950
@Override
5051
public void init() throws Exception {
52+
LOG.info("Starting KeepTime {}", VERSION);
53+
final DefaultExceptionHandler defaultExceptionHandler = new DefaultExceptionHandler();
54+
defaultExceptionHandler.register();
55+
5156
springContext = SpringApplication.run(Main.class);
5257
// TODO test if everywhere is used the same model
5358
model = springContext.getBean(Model.class);
@@ -57,8 +62,6 @@ public void init() throws Exception {
5762
@Override
5863
public void start(final Stage primaryStage) throws Exception {
5964

60-
stage = primaryStage;
61-
6265
LOG.debug("Reading configuration");
6366

6467
// TODO there should just be one instance of settings in the repo
@@ -92,8 +95,6 @@ public void start(final Stage primaryStage) throws Exception {
9295
LOG.info("Found {} past work items", todaysWorkItems.size());
9396
model.pastWorkItems.addAll(todaysWorkItems);
9497

95-
// createProjects();
96-
9798
final List<Project> projects = model.projectRepository.findAll();
9899

99100
LOG.debug("Found '{}' projects", projects.size());

src/main/java/de/doubleslash/keeptime/common/ConfigParser.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
import javax.xml.parsers.DocumentBuilder;
66
import javax.xml.parsers.DocumentBuilderFactory;
77

8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
810
import org.w3c.dom.Document;
911
import org.w3c.dom.Element;
1012
import org.w3c.dom.Node;
1113
import org.w3c.dom.NodeList;
1214

1315
import de.doubleslash.keeptime.controller.Controller;
14-
import de.doubleslash.keeptime.model.Model;
1516
import de.doubleslash.keeptime.model.Project;
1617
import javafx.scene.paint.Color;
1718

1819
public class ConfigParser {
20+
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
1921

20-
Controller controller;
21-
Model model;
22+
private final Controller controller;
2223

23-
public ConfigParser(final Model model, final Controller controller) {
24-
this.model = model;
24+
public ConfigParser(final Controller controller) {
2525
this.controller = controller;
2626
}
2727

@@ -30,15 +30,15 @@ public static boolean hasConfigFile(final String fileName) {
3030
return f.exists();
3131
}
3232

33-
public void parserConfig(final File inputFile) {
33+
public void parseConfig(final File inputFile) {
34+
LOG.info("Starting import of projects in file '{}'.", inputFile);
3435
try {
3536
final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
3637
final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
3738
final Document doc = dBuilder.parse(inputFile);
3839
doc.getDocumentElement().normalize();
39-
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
40+
LOG.debug("Root element '{}'.", doc.getDocumentElement().getNodeName());
4041
final NodeList nList = doc.getElementsByTagName("project");
41-
System.out.println("----------------------------");
4242

4343
// index makes sure to add new projects at the end
4444
int index = controller.getAvailableProjects().size();
@@ -51,26 +51,29 @@ public void parserConfig(final File inputFile) {
5151
final String isWork = eElement.getElementsByTagName("isWork").item(0).getTextContent();
5252
final String color = eElement.getElementsByTagName("color").item(0).getTextContent();
5353

54-
System.out.println("checking for: " + name);
54+
LOG.debug("Testing if project with name '{}' already exists.", name);
5555
boolean exists = false;
5656

5757
for (final Project p : controller.getAvailableProjects()) {
5858
if (name.equals(p.getName())) {
59-
System.out.println(name + " " + Boolean.toString(exists));
6059
exists = true;
60+
break;
6161
}
6262
}
6363
if (!exists) {
64+
LOG.info("Adding project '{}'.", name);
6465
final Color colorTemp = Color.valueOf(color);
6566
controller.addNewProject(name, Boolean.parseBoolean(isWork), colorTemp, index);
6667
index++;
68+
} else {
69+
LOG.debug("Project '{}' already exists", name);
6770
}
6871

6972
}
7073
}
71-
74+
LOG.info("Import of '{}' finished.", inputFile);
7275
} catch (final Exception e) {
73-
e.printStackTrace();
76+
LOG.error("There was an error while importing projects from config.xml", e);
7477
}
7578
}
7679
}

src/main/java/de/doubleslash/keeptime/view/SettingsController.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
77

8+
import de.doubleslash.keeptime.Main;
89
import de.doubleslash.keeptime.common.ConfigParser;
910
import de.doubleslash.keeptime.controller.Controller;
1011
import de.doubleslash.keeptime.model.Model;
12+
import javafx.event.ActionEvent;
13+
import javafx.event.EventHandler;
1114
import javafx.fxml.FXML;
1215
import javafx.scene.control.Alert;
1316
import javafx.scene.control.Alert.AlertType;
1417
import javafx.scene.control.Button;
1518
import javafx.scene.control.CheckBox;
1619
import javafx.scene.control.ColorPicker;
20+
import javafx.scene.control.Label;
1721
import javafx.scene.layout.Region;
1822
import javafx.scene.paint.Color;
1923
import javafx.stage.Stage;
@@ -54,18 +58,22 @@ public class SettingsController {
5458
@FXML
5559
private Button cancelButton;
5660

57-
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
58-
5961
@FXML
6062
private Button parseConfigButton;
6163

64+
@FXML
65+
private Label versionLabel;
66+
67+
private final Logger LOG = LoggerFactory.getLogger(this.getClass());
68+
6269
private Model model;
6370
private Controller controller;
6471
private Stage thisStage;
6572
private static final String INPUT_FILE = "config.xml";
6673

6774
@FXML
6875
private void initialize() {
76+
versionLabel.setText(Main.VERSION);
6977
saveButton.setOnAction(ae -> {
7078
LOG.info("Save clicked");
7179

@@ -133,10 +141,13 @@ private void initialize() {
133141
taskBarColor.setValue(Model.originalTaskBarFontColor);
134142
});
135143

136-
parseConfigButton.setOnAction(ae -> {
137-
if (ConfigParser.hasConfigFile(INPUT_FILE)) {
138-
final ConfigParser parser = new ConfigParser(model, controller);
139-
parser.parserConfig(new File(INPUT_FILE));
144+
parseConfigButton.setOnAction(new EventHandler<ActionEvent>() {
145+
@Override
146+
public void handle(final ActionEvent actionEvent) {
147+
if (ConfigParser.hasConfigFile(INPUT_FILE)) {
148+
final ConfigParser parser = new ConfigParser(controller);
149+
parser.parseConfig(new File(INPUT_FILE));
150+
}
140151
}
141152
});
142153

src/main/java/de/doubleslash/keeptime/view/ViewController.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.slf4j.LoggerFactory;
1515
import org.springframework.stereotype.Component;
1616

17-
import de.doubleslash.keeptime.Main;
1817
import de.doubleslash.keeptime.common.ColorHelper;
1918
import de.doubleslash.keeptime.common.DateFormatter;
2019
import de.doubleslash.keeptime.common.Resources;
@@ -130,6 +129,7 @@ class Delta {
130129

131130
private final Delta dragDelta = new Delta();
132131

132+
private Stage mainStage;
133133
private Controller controller;
134134
private Model model;
135135

@@ -185,23 +185,23 @@ private void initialize() throws IOException {
185185
mouseHoveringProperty.addListener((a, b, c) -> {
186186
// TODO fix the not so nice jumping..
187187
projectsVBox.setManaged(c);
188-
final double beforeWidth = Main.stage.getWidth();
189-
Main.stage.sizeToScene();
190-
final double afterWidth = Main.stage.getWidth();
188+
final double beforeWidth = mainStage.getWidth();
189+
mainStage.sizeToScene();
190+
final double afterWidth = mainStage.getWidth();
191191
projectsVBox.setVisible(c);
192192
final double offset = afterWidth - beforeWidth;
193193
if (!model.displayProjectsRight.get()) {
194194
// we only need to move the stage if the node on the left is hidden
195-
Main.stage.setX(Main.stage.getX() - offset);
195+
mainStage.setX(mainStage.getX() - offset);
196196
}
197197
});
198198

199199
minimizeButton.setOnAction((ae) -> {
200-
Main.stage.setIconified(true);
200+
mainStage.setIconified(true);
201201
});
202202
minimizeButton.textFillProperty().bind(fontColorProperty);
203203
closeButton.setOnAction((ae) -> {
204-
Main.stage.close();
204+
mainStage.close();
205205
});
206206
closeButton.textFillProperty().bind(fontColorProperty);
207207

@@ -792,7 +792,7 @@ private void updateTaskbarIcon(final long currentWorkSeconds) {
792792
final BufferedImage bi = SwingFXUtils.fromFXImage(image, null);
793793
final Image icon = SwingFXUtils.toFXImage(bi, null);
794794

795-
final ObservableList<Image> icons = Main.stage.getIcons();
795+
final ObservableList<Image> icons = mainStage.getIcons();
796796
icons.addAll(icon);
797797
if (icons.size() > 1) {
798798
icons.remove(0);
@@ -820,8 +820,6 @@ public static String changeStyleAttribute(final String style, final String attri
820820
return newStyle;
821821
}
822822

823-
Stage mainStage;
824-
825823
public void setStage(final Stage primaryStage) {
826824
this.mainStage = primaryStage;
827825
}

src/main/resources/application.properties

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ spring.h2.console.enabled=true
33
spring.h2.console.path=/h2
44

55
# Datasource
6-
spring.datasource.url=jdbc:h2:file:~/keeptime/db/keeptime-h2-db;DB_CLOSE_ON_EXIT=FALSE
6+
spring.datasource.url=jdbc:h2:file:./db/keeptime-h2-db;DB_CLOSE_ON_EXIT=FALSE
77
spring.datasource.username=sa
88
spring.datasource.password=
99
spring.datasource.driver-class-name=org.h2.Driver
10-
spring.jpa.hibernate.ddl-auto=update
10+
11+
spring.flyway.baselineOnMigrate=true
12+
spring.flyway.baselineVersion=0.0.0
13+
14+
spring.jpa.hibernate.ddl-auto=validate
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
CREATE TABLE IF NOT EXISTS project
2+
(
3+
id BIGINT GENERATED BY DEFAULT AS IDENTITY,
4+
color VARCHAR(255),
5+
index INTEGER NOT NULL,
6+
is_default BOOLEAN NOT NULL,
7+
is_enabled BOOLEAN NOT NULL,
8+
is_work BOOLEAN NOT NULL,
9+
name VARCHAR(255),
10+
PRIMARY KEY (id)
11+
);
12+
13+
CREATE TABLE IF NOT EXISTS settings
14+
(
15+
id BIGINT GENERATED BY DEFAULT AS IDENTITY,
16+
default_background_color VARCHAR(255),
17+
default_font_color VARCHAR(255),
18+
display_projects_right BOOLEAN NOT NULL,
19+
hover_background_color VARCHAR(255),
20+
hover_font_color VARCHAR(255),
21+
task_bar_color VARCHAR(255),
22+
use_hotkey BOOLEAN NOT NULL,
23+
PRIMARY KEY (id)
24+
);
25+
26+
CREATE TABLE IF NOT EXISTS work
27+
(
28+
id BIGINT GENERATED BY DEFAULT AS IDENTITY,
29+
creation_date DATE,
30+
end_time TIMESTAMP,
31+
notes CLOB,
32+
start_time TIMESTAMP,
33+
project_id BIGINT,
34+
PRIMARY KEY (id)
35+
);
36+
37+
ALTER TABLE work
38+
ADD CONSTRAINT IF NOT EXISTS fkf4jf1abybj7fc5w1nt686svxt FOREIGN KEY (project_id) REFERENCES
39+
project;

0 commit comments

Comments
 (0)