Skip to content

Commit

Permalink
Merge pull request #216 from itsallcode/adapt-to-macos
Browse files Browse the repository at this point in the history
Adapt to macOS
  • Loading branch information
kaklakariada authored Sep 26, 2021
2 parents 2f0d1a9 + 76d21ea commit c28a1c3
Show file tree
Hide file tree
Showing 32 changed files with 586 additions and 64 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [11, 17]
java: [17]
env:
DEFAULT_JAVA: 11
DEFAULT_JAVA: 17

steps:

Expand All @@ -25,7 +25,7 @@ jobs:

- uses: actions/setup-java@v2
with:
distribution: 'zulu'
distribution: 'temurin'
java-version: ${{ matrix.java }}

- uses: gradle/wrapper-validation-action@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:

- uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: 11
distribution: 'temurin'
java-version: 17

- uses: gradle/wrapper-validation-action@v1

Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"**/.project": true,
"**/.settings": true,
"**/.factorypath": true,
"**/build/": true,
"**/build/": false,
"**/bin/": true,
".gradle/": true,
".idea/": true,
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [1.8.0] - unreleased

### Breaking change

* Requires Java 17

### Feature

* [#216](https://github.com/itsallcode/white-rabbit/pull/216): Add support for macOS.

### Changed

* [#215](https://github.com/itsallcode/white-rabbit/pull/215): Upgrade dependencies, fix sonar issues.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ A time recording tool

### Requirements

* Java Runtime Environment (JRE) 11 or 17, e.g. [Eclipse Temurin](https://adoptium.net/).
* Java Runtime Environment (JRE) 17, e.g. [Eclipse Temurin](https://adoptium.net/).

### Install WhiteRabbit locally

Expand Down
6 changes: 3 additions & 3 deletions api/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.source=11
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.source=17
org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
id 'com.github.johnrengelman.shadow' version '7.0.0' apply false
id "com.moowork.node" version "1.3.1" apply false
id "com.github.ben-manes.versions" version "0.39.0"
id "org.panteleyev.jpackageplugin" version "1.3.1" apply false
}

ext {
Expand Down Expand Up @@ -40,7 +41,7 @@ subprojects {

java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
languageVersion = JavaLanguageVersion.of(17)
}
modularity.inferModulePath = false
}
Expand Down
6 changes: 3 additions & 3 deletions jfxui/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.problem.APILeak=warning
org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
Expand Down Expand Up @@ -105,7 +105,7 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=11
org.eclipse.jdt.core.compiler.source=17
org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
Expand Down
41 changes: 41 additions & 0 deletions jfxui/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'com.github.johnrengelman.shadow'
id 'org.panteleyev.jpackageplugin'
}

ext {
Expand Down Expand Up @@ -123,3 +124,43 @@ task uiTest(type: Test, group: 'verification') {
check.dependsOn uiTest

tasks["jacocoTestReport"].executionData fileTree(project.buildDir).include("jacoco/*.exec")


def jPackageDir = "$buildDir/jpackage-jars"

task copyJPackageDependencies(type: Copy, dependsOn: ["jar"]) {
from(configurations.runtimeClasspath).into jPackageDir
from(tasks.jar.outputs.files).into jPackageDir
}


tasks.jpackage {
dependsOn("copyJPackageDependencies")

input = jPackageDir
destination = "$buildDir/jpackage-dist"

appName = "WhiteRabbit"
vendor = '"It\'s all code"'
copyright = '"Copyright (C) 2021 Christoph Pirkl <christoph at users.sourceforge.net>"'
licenseFile = "${rootProject.rootDir}/LICENSE"
appDescription = '"A time recording tool"'
icon = "${projectDir}/src/main/resources/icon.png"

mainJar = tasks.jar.archiveFileName.get()
mainClass = project.mainClass

verbose = false
arguments = []
javaOptions = ["-Dfile.encoding=UTF-8"]
additionalParameters = ["--about-url", "https://github.com/itsallcode/white-rabbit/blob/develop/README.md"]
windows {
winConsole = true
}

mac {
macPackageIdentifier = "org.itsallcode.white-rabbit"
macPackageName = "WhiteRabbit"
icon = "${projectDir}/src/main/resources/icon.icns"
}
}
3 changes: 3 additions & 0 deletions jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/App.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.itsallcode.whiterabbit.jfxui;

import org.itsallcode.whiterabbit.jfxui.splashscreen.SplashScreenLoader;
import org.itsallcode.whiterabbit.jfxui.systemmenu.DesktopIntegration;

import javafx.application.Application;

Expand All @@ -11,6 +12,8 @@ public static void main(String[] args)
System.setProperty("javafx.preloader", SplashScreenLoader.class.getName());
System.setProperty("log4j.skipJansi", "false");
System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");

DesktopIntegration.getInstance().register();
Application.launch(JavaFxApp.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.itsallcode.whiterabbit.jfxui.property.DelayedPropertyListener;
import org.itsallcode.whiterabbit.jfxui.splashscreen.ProgressPreloaderNotification;
import org.itsallcode.whiterabbit.jfxui.splashscreen.ProgressPreloaderNotification.Type;
import org.itsallcode.whiterabbit.jfxui.systemmenu.DesktopIntegration;
import org.itsallcode.whiterabbit.jfxui.ui.AppUi;
import org.itsallcode.whiterabbit.jfxui.ui.InterruptionDialog;
import org.itsallcode.whiterabbit.jfxui.uistate.UiStateService;
Expand Down Expand Up @@ -107,6 +108,8 @@ private void doInitialize()
state = AppState.create(appService,
UiStateService.loadState(config, new DelayedPropertyListener(appService.scheduler())));
actions = UiActions.create(config, state, appService, getHostServices());

DesktopIntegration.getInstance().setUiActions(actions);
}

private Config loadConfig()
Expand Down
60 changes: 60 additions & 0 deletions jfxui/src/main/java/org/itsallcode/whiterabbit/jfxui/OsCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.itsallcode.whiterabbit.jfxui;


import java.awt.Desktop;
import java.util.Locale;

/**
* Helper class to check the operating system this Java VM runs in.
*
* please keep the notes below as a pseudo-license:
*
* http://stackoverflow.com/questions/228477/how-do-i-programmatically-determine-operating-system-in-java
* compare to
* http://svn.terracotta.org/svn/tc/dso/tags/2.6.4/code/base/common/src/com/tc/util/runtime/Os.java
* http://www.docjar.com/html/api/org/apache/commons/lang/SystemUtils.java.html
*/
public class OsCheck
{
/**
* Types of Operating Systems
*/
public enum OSType
{
WINDOWS, MACOS, LINUX, OTHER
}

/**
* Detect the operating system from the {@code os.name} System property and
* cache the result.
*
* @returns the operating system detected
*/
public OSType getOperatingSystemType()
{
return detectOperatingSystemType();
}

private static OSType detectOperatingSystemType()
{
final String os = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if ((os.indexOf("mac") >= 0) || (os.indexOf("darwin") >= 0))
{
return OSType.MACOS;
}
else if (os.indexOf("win") >= 0)
{
return OSType.WINDOWS;
}
else if (os.indexOf("linux") >= 0)
{
return OSType.LINUX;
}
return OSType.OTHER;
}

public boolean isDesktopSupported()
{
return Desktop.isDesktopSupported();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -15,16 +16,19 @@
import org.itsallcode.whiterabbit.logic.Config;
import org.itsallcode.whiterabbit.logic.model.MonthIndex;
import org.itsallcode.whiterabbit.logic.report.vacation.VacationReport;
import org.itsallcode.whiterabbit.logic.service.AppPropertiesService.AppProperties;
import org.itsallcode.whiterabbit.logic.service.AppService;

import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.stage.Modality;
import javafx.stage.Stage;

public final class UiActions
public class UiActions
{
private static final Logger LOG = LogManager.getLogger(UiActions.class);

Expand Down Expand Up @@ -146,4 +150,25 @@ public void exitApp()
{
Platform.exit();
}

public void showAboutDialog()
{
JavaFxUtil.runOnFxApplicationThread(() -> {
final AppProperties appProperties = appService.getAppProperties();
final Alert aboutDialog = new Alert(AlertType.INFORMATION);
aboutDialog.initModality(Modality.NONE);
if (state.getPrimaryStage().isPresent())
{
aboutDialog.initOwner(state.getPrimaryStage().get());
}
aboutDialog.setTitle("About White Rabbit");
aboutDialog.setHeaderText("About White Rabbit:");
aboutDialog.setContentText("Version: " + appProperties.getVersion());
final ButtonType close = new ButtonType("Close", ButtonData.CANCEL_CLOSE);
final ButtonType homepage = new ButtonType("Open Homepage", ButtonData.HELP);
aboutDialog.getButtonTypes().setAll(close, homepage);
final Optional<ButtonType> selectedButton = aboutDialog.showAndWait();
selectedButton.filter(response -> response == homepage).ifPresent(buttonType -> this.openHomepage());
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.itsallcode.whiterabbit.jfxui.systemmenu;

import org.itsallcode.whiterabbit.jfxui.UiActions;

public interface DesktopIntegration
{
public static DesktopIntegration getInstance()
{
return StaticInstanceHolder.getInstance();
}

void register();

void setUiActions(UiActions actions);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.itsallcode.whiterabbit.jfxui.systemmenu;

import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.awt.desktop.AboutEvent;
import java.util.Objects;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.itsallcode.whiterabbit.jfxui.UiActions;

class DesktopIntegrationImpl implements DesktopIntegration
{
private static final Logger LOG = LogManager.getLogger(DesktopIntegrationImpl.class);

private final Desktop desktop;

private UiActions actions;

DesktopIntegrationImpl(Desktop desktop)
{
this.desktop = desktop;
}

@Override
public void register()
{
LOG.debug("Registering desktop integration");
if (desktop.isSupported(Action.APP_ABOUT))
{
desktop.setAboutHandler(this::showAboutDialog);
}
}

@Override
public void setUiActions(UiActions actions)
{
this.actions = Objects.requireNonNull(actions);
}

private void showAboutDialog(AboutEvent e)
{
getActions().showAboutDialog();
}

private UiActions getActions()
{
if (actions == null)
{
throw new IllegalStateException("UI Actions not registered");
}
return actions;
}
}
Loading

0 comments on commit c28a1c3

Please sign in to comment.