Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use OS specific colour theme #9263

Closed
wants to merge 27 commits into from

Conversation

shafinkamal
Copy link
Contributor

@shafinkamal shafinkamal commented Oct 18, 2022

Resolves #8729.

Currently, I have added a new Radio Button (see below) which the user would select so that their JabRef theme corresponds to the theme that their OS is currently. I have achieved that by referencing the jSystemThemeDetector library

Screen Shot 2022-10-18 at 8 19 37 pm

However, I am currently at a roadblock and would greatly appreciate some help. If my MacOS Theme is 'Light', I can change it to 'Dark' and within JabRef if I select 'Automatic detection' and then 'Save', JabRef will change from Light to Dark. However when going back the JabRef Preferences, the setting has not stayed at 'Automatic detection' and instead has moved to 'Dark theme'. This means that next time I change from Dark to Light on my MacOS System Preferences, this change won't be reflected in JabRef. I've attached a demo to visually show the behaviour.

jabref theme demo gif

Any pointers please? Thank you!!!

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

@@ -2067,7 +2067,8 @@ public AppearancePreferences getAppearancePreferences() {
appearancePreferences = new AppearancePreferences(
getBoolean(OVERRIDE_DEFAULT_FONT_SIZE),
getInt(MAIN_FONT_SIZE),
new Theme(get(FX_THEME))
new Theme(get(FX_THEME)),
false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to add a new constant for the new flag and get the value here : sth like getBoolean(AUTOMATIC_THEME_DETECTION) and then add a new listener so that the value gets stored and read on change

@ThiloteE ThiloteE changed the title Draft: Fix for issue 8729 -- WIP [WIP] Draft: Fix for issue 8729 - Add option to use OS specific colour theme Oct 18, 2022
@ThiloteE
Copy link
Member

To ease organizational workflows I have linked the pull-request to the issue with syntax as described in https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue

Linking a pull request to an issue using a keyword

You can link a pull request to an issue by using a supported keyword in the pull request's description or in a commit message. The pull request must be on the default branch.

  • close
  • closes
  • closed
  • fix
  • fixes
  • fixed
  • resolve
  • resolves
  • resolved

If you use a keyword to reference a pull request comment in another pull request, the pull requests will be linked. Merging the referencing pull request also closes the referenced pull request.

The syntax for closing keywords depends on whether the issue is in the same repository as the pull request.

shafinkamal and others added 10 commits October 19, 2022 17:59
Bumps [gittools/actions](https://github.com/gittools/actions) from 0.9.13 to 0.9.14.
- [Release notes](https://github.com/gittools/actions/releases)
- [Commits](GitTools/actions@v0.9.13...v0.9.14)

---
updated-dependencies:
- dependency-name: gittools/actions
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [hmarr/auto-approve-action](https://github.com/hmarr/auto-approve-action) from 2.4.0 to 3.0.0.
- [Release notes](https://github.com/hmarr/auto-approve-action/releases)
- [Commits](hmarr/auto-approve-action@v2.4.0...v3.0.0)

---
updated-dependencies:
- dependency-name: hmarr/auto-approve-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [actions/configure-pages](https://github.com/actions/configure-pages) from 1 to 2.
- [Release notes](https://github.com/actions/configure-pages/releases)
- [Commits](actions/configure-pages@v1...v2)

---
updated-dependencies:
- dependency-name: actions/configure-pages
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [controlsfx](https://github.com/controlsfx/controlsfx) from 11.1.1 to 11.1.2.
- [Release notes](https://github.com/controlsfx/controlsfx/releases)
- [Commits](controlsfx/controlsfx@11.1.1...11.1.2)

---
updated-dependencies:
- dependency-name: org.controlsfx:controlsfx
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Save files again relative to bib file

* Reworded

* Reintroduced default file chooser directory without swing

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update NativeDesktop.java

* Reworked ADR

* Added mac directory

* Removed comments

* Added linux support

* Revert "Save files again relative to bib file"

This reverts commit 3e640f5.

# Conflicts:
#	CHANGELOG.md
#	src/main/java/org/jabref/preferences/FilePreferences.java
#	src/main/java/org/jabref/preferences/JabRefPreferences.java
#	src/test/java/org/jabref/model/database/BibDatabaseContextTest.java

* Update src/main/java/org/jabref/gui/desktop/os/Windows.java

* fix merge errors

* fix wrong method call

* remove defautl
fix checkstyle

* reintroduce method to avoid calling get two times

* Introduced getPath method

* Update src/main/java/org/jabref/gui/desktop/os/Linux.java

fix env var

Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
Co-authored-by: Siedlerchr <siedlerkiller@gmail.com>
@shafinkamal shafinkamal marked this pull request as ready for review October 19, 2022 10:12
@shafinkamal
Copy link
Contributor Author

Updated behaviour.

Jabref theme switch demo

@shafinkamal shafinkamal changed the title [WIP] Draft: Fix for issue 8729 - Add option to use OS specific colour theme Fix for issue 8729 - Add option to use OS specific colour theme Oct 19, 2022
@shafinkamal
Copy link
Contributor Author

I've just noticed that I (at some point) pulled from upstream when in my remote branch accidentally which is why there are other people's contributions in this PR. Will this cause a problem? If so, let me know and I'll fix it up tomorrow.

Thanks (sorry about that)

@Siedlerchr
Copy link
Member

Siedlerchr commented Oct 19, 2022

@shafinkamal That's no problem, but you will probably need to sync your fork's main branch so that github correclty detecs the changes again

On your fork in github just use the sync fork e.g.
grafik

Thanks for your PR so far, it's overall looking good. But unfortunately the new dependency is blocked by https://bugs.openjdk.org/browse/JDK-8240567

@Siedlerchr Siedlerchr added status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers hacktoberfest-accepted labels Oct 20, 2022
@shafinkamal
Copy link
Contributor Author

Anything I can do to fix the failing tests or is it all good on my end? the fails seem to be related to servers and what not...

Anyways, let me know.

Thanks!

@Siedlerchr
Copy link
Member

Thanks it looks good, the failing tests are related to some jitpack error not resolving the dependency correctly.

@calixtus
Copy link
Member

U sure this works with modern verions of windows too, because it looks like microsoft removed some registry keys:
https://learn.microsoft.com/en-us/answers/questions/715081/how-to-detect-windows-dark-mode.html
?

@shafinkamal
Copy link
Contributor Author

shafinkamal commented Oct 21, 2022

I'm not too sure about the modern versions of Windows as I have geared this towards MacOS, because the issue (#8729) is specific to MacOS and I have MacOS so I can manually test it on modern versions of that.

I had included some Windows operations for the sake of coverage but perhaps another issue can be made to ensure further coverage of Windows (and other OS's). In the issue discussion, @Siedlerchr also mentions that a complete implementation would have to be done individually for each OS.

If we're worried about the code breaking the application on the more recent versions of Windows, we can comment out the Windows section and make this a purely MacOS specific feature (for the time being).

Comment on lines +24 to +33
public final boolean isDarkMode() {
switch (getOperatingSystem()) {
case WINDOWS: return isWindowsDarkMode();
case MACOS: return isMacOsDarkMode();
// currently theme detection not implemented for Linux and Solaris
case LINUX: return false;
case SOLARIS: return false;
default: return false;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please split up this class and use the existing OS package and classes to provide a method isDarkMode instead of introducing some code duplication to test for which os is runnning here?

Comment on lines +58 to +59
Process process = Runtime.getRuntime().exec(DARK_THEME_CMD);
StreamReader reader = new StreamReader(process.getInputStream());
Copy link
Member

@calixtus calixtus Oct 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You really should use JNA here, we already use it in other occasions and its a way cleaner solution.

this.shouldOverrideDefaultFontSize = new SimpleBooleanProperty(shouldOverrideDefaultFontSize);
this.mainFontSize = new SimpleIntegerProperty(mainFontSize);
this.theme = new SimpleObjectProperty<>(theme);
this.automaticThemeDetectionFlag = new SimpleBooleanProperty(automaticThemeDetectionFlag);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(should)AutoDetectTheme(Property)

Comment on lines 52 to 56
<Label fx:id="restartJabRefHint" styleClass="text" text="${'\nRestarting JabRef may be required to display changes in theme preferences.'}">
<font>
<Font name="Italic" size="13.0"/>
</font>
</Label>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why just fixed the restart for theme change issue a few months back. This would be a major regression.

@calixtus
Copy link
Member

Thanks for your interest in JabRef programming. I like the idea, yet there are some issues with you changes that should be adressed...

@calixtus
Copy link
Member

grafik
Make the auto detect option a checkbox and grey out the other options, when checked.

@shafinkamal
Copy link
Contributor Author

Hi @calixtus,

Thanks for the feedback. I'm quite busy this weekend and the following week, but I'll get around to implementing these changes when I have some more free time.

In the meantime, could you please assign me to issue #8729?

Thanks!

@tobiasdiez tobiasdiez changed the title Fix for issue 8729 - Add option to use OS specific colour theme Add option to use OS specific colour theme Oct 25, 2022
@tobiasdiez tobiasdiez added status: changes required Pull requests that are not yet complete and removed status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Oct 25, 2022
* upstream/main: (55 commits)
  Update guidelines-for-setting-up-a-local-workspace.md
  Add link to good first issues (and fix link)
  Refine guidelines (and fix .md file linking)
  Extend ArXiv fetcher results by using data from related DOIs (JabRef#9170)
  New Crowdin updates (JabRef#9366)
  Fix token
  New translations JabRef_en.properties (Chinese Simplified) (JabRef#9364)
  Fix date field change causes an uncaught exception (JabRef#9365)
  Add date format and respective test case (JabRef#9310)
  Bump jackson-datatype-jsr310 from 2.13.4 to 2.14.0 (JabRef#9357)
  Bump jackson-dataformat-yaml from 2.13.4 to 2.14.0 (JabRef#9356)
  Bump tika-core from 2.5.0 to 2.6.0 (JabRef#9358)
  Refine guideline "Set up a local workspace" (JabRef#9355)
  Adds missing "requires" statement (JabRef#9354)
  Bind "Find unlinked files" default directory to the current library (JabRef#9290)
  Rename "Remote" to "Tele" (JabRef#9270)
  Fixed display of file field adjusting for the dark theme (JabRef#9343)
  Update sorting of entries in maintable by special fields immediately (JabRef#9338)
  New translations JabRef_en.properties (German) (JabRef#9336)
  Fix Abbreviation for Escaped Ampersand (JabRef#9288)
  ...

# Conflicts:
#	CHANGELOG.md
#	src/main/java/org/jabref/preferences/AppearancePreferences.java
#	src/main/java/org/jabref/preferences/JabRefPreferences.java
#	src/test/java/org/jabref/gui/theme/ThemeManagerTest.java
@HoussemNasri
Copy link
Member

Hey @shafinkamal. Do you plan to continue working on this?

* upstream/main: (145 commits)
  Enable groups drag'n'drop to new library (JabRef#9460)
  Update MacOS jabrefHost.py to find local installs (JabRef#9487)
  Fix remember last open valid library with empty new one (JabRef#9489)
  Observable Preferences R (CitationKeyPatternPreferences) (JabRef#9486)
  Fixed ZBMathTest and extracted keyWordSeparator (JabRef#9485)
  New Crowdin updates (JabRef#9483)
  Add log for ignored excepton (JabRef#9302)
  Select Library to import into (JabRef#9402)
  Bump org.eclipse.jgit from 6.3.0.202209071007-r to 6.4.0.202211300538-r (JabRef#9476)
  Bump com.github.andygoossens.modernizer from 1.6.2 to 1.7.0 (JabRef#9478)
  Bump mockito-core from 4.9.0 to 4.10.0 (JabRef#9479)
  Bump checkstyle from 10.4 to 10.5.0 (JabRef#9477)
  Bump slf4j-api from 2.0.5 to 2.0.6 in /buildSrc (JabRef#9480)
  Bibtex month not deprecated (JabRef#9404)
  Show development information\n\n+semver: major
  Release v5.8
  Update external libraries add afterburner fx jabref add jakarta inject
  fix display name for artifact store
  Prepare CHANGELOG for release
  Also trigger on branch arm64mac-release
  ...

# Conflicts:
#	CHANGELOG.md
#	src/main/java/org/jabref/preferences/JabRefPreferences.java
@Siedlerchr
Copy link
Member

Closing this issue due to inactivity 💤
Please reopen the issue with additional information if the problem persists.

@Siedlerchr Siedlerchr closed this Jan 19, 2023
EthanYifanJu added a commit to EthanYifanJu/jabref that referenced this pull request Oct 23, 2023
- Add "Use System Preference" option under General -> Appearance -> Visual Theme
- Add flags to store whether user chose this option
- Add SystemThemeDetector.java for auto detect system theme(to do)
github-merge-queue bot pushed a commit that referenced this pull request Nov 9, 2023
* Add basic files and settings followed by PR #9263
- Add "Use System Preference" option under General -> Appearance -> Visual Theme
- Add flags to store whether user chose this option
- Add SystemThemeDetector.java for auto detect system theme(to do)

* Using jSystemThemeDetector to detect system theme
- Add jSystemThemeDetector dependency in build.gradle
- Implemented detector into codebase
- Delete unnecessary java file

* Add the "Use System Preference" to the English translation file

* Add library document and licence

* Add update to CHANGELOG.md

* Update checkstyle

* Update checkstyle

* Update CHANGELOG.md. Former log was put in a released part.

* Applied review notes and cleaned up

* Update JabRefGUI.java

Removed whitespace

---------

Co-authored-by: Carl Christian Snethlage <50491877+calixtus@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to use System Preference for Light/Dark Theme (Win/Lin/OSX)
7 participants