Skip to content

Commit

Permalink
Merge pull request #88 from Suwayomi/start-popup
Browse files Browse the repository at this point in the history
Start popup
  • Loading branch information
aless2003 authored Jan 2, 2024
2 parents f2a275f + d53f34c commit 551eae5
Show file tree
Hide file tree
Showing 13 changed files with 209 additions and 30 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plugins {
}

group = 'online.hatsunemiku'
version = '1.0.3'
version = '1.0.4'
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

Expand Down
25 changes: 19 additions & 6 deletions frontend/css/views/settings-view.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,26 @@
*/

.settings-content {
display: flex;
justify-content: start;
flex-direction: column;
flex-grow: 1;
max-width: 100%;
display: flex;
justify-content: start;
flex-direction: column;
flex-grow: 1;
max-width: 100%;
}

.settings-view .content {
flex-direction: row;
flex-direction: row;
}

.settings-view .content .checkbox-container {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 1rem;
margin-bottom: 1rem;
border: 1px solid var(--miku-main-color);
border-radius: 0.5rem;
padding: 1rem;
width: 99% !important;
margin-right: 10vw !important;
}
23 changes: 23 additions & 0 deletions frontend/themes/miku/components/checkbox.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

vaadin-checkbox > label {
color: var(--miku-main-color);
font-weight: 500;
}

vaadin-checkbox::part(checkbox) {
border: 1px solid var(--miku-main-color);
background-color: var(--lumo-shade-20pct)
}

vaadin-checkbox[checked]::part(checkbox) {
background-color: var(--miku-frosted-glass-20)
}

vaadin-checkbox::part(checkbox)::after {
color: var(--miku-main-color);
}
4 changes: 4 additions & 0 deletions frontend/themes/miku/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@import "./components/buttons.css";
@import "./components/combo-box.css";
@import "./components/superfields/super-text-field.css";
@import "components/checkbox.css";

html {

Expand All @@ -38,6 +39,9 @@ html {
--miku-unselected-color-50: rgba(55, 59, 62, 0.5);

--miku-frosted-glass: rgba(255, 255, 255, 0.1);
--miku-frosted-glass-20: rgba(255, 255, 255, 0.2);
--miku-frosted-glass-30: rgba(255, 255, 255, 0.3);
--miku-frosted-glass-50: rgba(255, 255, 255, 0.5);
--miku-frosted-glass-80: rgba(255, 255, 255, 0.8);

--miku-frosted-glass-blue: rgb(0, 255, 246, 0.2);
Expand Down
17 changes: 11 additions & 6 deletions linux/flatpak/online.hatsune_miku.tachidesk-vaadinui.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,19 @@
</screenshot>
</screenshots>
<releases>
<release version="1.0.3" date="2023-12-06">
<release version="1.0.4" date="2024-01-02">
<description>
<p>Fixes an issue where the Client might not start correctly, because of an invalid Server response</p>
<p>Adds a Popup on startup, as some systems don't have a Task Tray. Also fixes some general issues</p>
<ul>
<li>Refine server connection check route by @aless2003</li>
<li>bump version by @aless2003</li>
<li>style: format code with Google Java Format by @deepsource-autofix[bot]</li>
<li>Merge pull request #84 from Suwayomi/start-error by @aless2003</li>
<li>Refactor browser opening logic and add initialization notification</li>
<li>Update file and server directory definitions</li>
<li>Optimize Imports</li>
<li>Replace FeignException with ResourceAccessException in ServerStartView</li>
<li>Add start popup enable/disable setting</li>
<li>rename super-checkbox.css to checkbox.css</li>
<li>The code has been updated to ensure that the SettingsView does not fail when the server isn't running yet</li>
<li>Add default initialization for Settings#startPopup</li>
<li>Bump version to 1.0.4</li>
</ul>
</description>
</release>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import online.hatsunemiku.tachideskvaadinui.data.settings.reader.ReaderSettings;
Expand All @@ -22,6 +23,11 @@ public class Settings {
@JsonProperty("url")
private String url;

@Getter
@Setter
@JsonProperty("startPopup")
private boolean startPopup;

@Getter
@JsonProperty("defaultReaderSettings")
private final ReaderSettings defaultReaderSettings;
Expand All @@ -37,10 +43,13 @@ public class Settings {
@JsonCreator
public Settings(
@NotNull @JsonProperty("url") String url,
@JsonProperty("startPopup") Boolean startPopup,
@JsonProperty("defaultReaderSettings") ReaderSettings defaultReaderSettings,
@JsonProperty("mangaReaderSettings") Map<Integer, ReaderSettings> mangaReaderSettings,
@JsonProperty("defaultSearchLang") String defaultSearchLang) {

this.startPopup = Objects.requireNonNullElse(startPopup, true);

if (defaultReaderSettings == null) {
defaultReaderSettings = new ReaderSettings();
}
Expand All @@ -59,6 +68,7 @@ public Settings(@NotNull String url) {
this.url = url;
this.defaultReaderSettings = new ReaderSettings();
this.mangaReaderSettings = new HashMap<>();
this.startPopup = true;
}

public void setUrl(@NonNull String url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

package online.hatsunemiku.tachideskvaadinui.services;

import feign.RetryableException;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import online.hatsunemiku.tachideskvaadinui.services.client.LibUpdateClient;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

Expand All @@ -34,7 +36,12 @@ public boolean fetchUpdate() {

URI baseUrl = URI.create(settings.getUrl());

var response = client.fetchUpdate(baseUrl);
ResponseEntity<Void> response;
try {
response = client.fetchUpdate(baseUrl);
} catch (RetryableException e) {
return false;
}

return response.getStatusCode().is2xxSuccessful();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class TachideskMaintainer {
private final RestTemplate client;
private final TachideskStarter starter;
private final SettingsService settingsService;
private static final File serverDir = new File("server");
private static File serverDir;
private final File projectDir;
@Getter private boolean updating = false;
@Getter private double progress = 0;
Expand All @@ -65,6 +65,8 @@ public TachideskMaintainer(
} else {
projectDir = PathUtils.getProjectDir().toFile();
}

serverDir = new File(projectDir, "server");
}

@EventListener({ApplicationReadyEvent.class, UrlChangeEvent.class})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
package online.hatsunemiku.tachideskvaadinui.startup;

import jakarta.annotation.PreDestroy;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import javax.swing.*;
import lombok.extern.slf4j.Slf4j;
import online.hatsunemiku.tachideskvaadinui.data.Meta;
import online.hatsunemiku.tachideskvaadinui.data.settings.Settings;
import online.hatsunemiku.tachideskvaadinui.data.settings.event.UrlChangeEvent;
import online.hatsunemiku.tachideskvaadinui.services.SettingsService;
import online.hatsunemiku.tachideskvaadinui.utils.BrowserUtils;
import online.hatsunemiku.tachideskvaadinui.utils.SerializationUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -65,24 +65,23 @@ public void startJar(File projectDir) {
}

if (!isJavaInstalled) {
Desktop desktop = Desktop.getDesktop();
String url =
"https://github.com/aless2003/Tachidesk-VaadinUI/blob/master/Install%20Process.md#when-starting-its-stuck-on-waiting-for-server-to-start";
try {
desktop.browse(URI.create(url));
Thread.sleep(6000);
BrowserUtils.openBrowser(url);
} catch (IOException e) {
log.error("Failed to open browser", e);
} catch (InterruptedException e) {
log.error("Failed to sleep", e);
}
System.exit(-1);
return;
}

log.info("Starting jar with data dir: {}", dataDirFile.getAbsolutePath());
ProcessBuilder processBuilder = new ProcessBuilder("java", dataDirArg, "-jar", jarLocation);
processBuilder.redirectOutput(new File("server.log"));

File logFile = new File(projectDir, "server.log");

processBuilder.redirectOutput(logFile);

try {
serverProcess = processBuilder.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
import java.awt.TrayIcon;
import java.awt.TrayIcon.MessageType;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import javax.swing.*;
import lombok.extern.slf4j.Slf4j;
import online.hatsunemiku.tachideskvaadinui.data.settings.Settings;
import online.hatsunemiku.tachideskvaadinui.services.SettingsService;
import online.hatsunemiku.tachideskvaadinui.utils.BrowserUtils;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
Expand All @@ -27,6 +32,12 @@
@Slf4j
public class TrayHandler {

private final SettingsService settingsService;

public TrayHandler(SettingsService settingsService) {
this.settingsService = settingsService;
}

@EventListener(ApplicationStartedEvent.class)
public void registerTray() {
if (SystemTray.isSupported()) {
Expand All @@ -53,11 +64,10 @@ public void registerTray() {

trayIcon.addActionListener(
e -> {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(URI.create("http://localhost:8080"));
} catch (Exception ex) {
throw new RuntimeException(ex);
BrowserUtils.openBrowser("http://localhost:8080");
} catch (IOException ex) {
log.error("Couldn't open browser", ex);
}
});
} catch (FileNotFoundException e) {
Expand All @@ -71,6 +81,8 @@ public void registerTray() {
} else {
log.info("System tray not supported");
}

showPopup();
}

private PopupMenu createTrayMenu() {
Expand All @@ -96,4 +108,40 @@ private PopupMenu createTrayMenu() {

return menu;
}

private void showPopup() {
Settings settings = settingsService.getSettings();

if (!settings.isStartPopup()) {
return;
}

String title = "Tachidesk VaadinUI started";
String message =
"""
Please visit http://localhost:8080 to use the UI.
If you have a System Tray, you can also click the tray icon there to open the UI.
Do you want to open the UI in your browser now?
""";

Thread thread =
new Thread(
() -> {
int answer =
JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION);

if (answer == JOptionPane.YES_OPTION) {
try {
BrowserUtils.openBrowser("http://localhost:8080");
} catch (IOException e) {
log.error("Couldn't open browser", e);
}
} else {
log.info("User didn't want to open browser");
}
});

thread.start();
}
}
;
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

package online.hatsunemiku.tachideskvaadinui.utils;

import java.awt.*;
import java.io.IOException;
import java.net.URI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BrowserUtils {

private static final Logger log = LoggerFactory.getLogger(BrowserUtils.class);

public static void openBrowser(String url) throws IOException {
boolean useDesktop =
Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE);

if (useDesktop) {
try {
Desktop.getDesktop().browse(URI.create(url));
} catch (IOException e) {
log.error("Browser couldn't be opened", e);
}
} else {
log.info("Desktop not supported, opening browser via xdg-open");

try {
ProcessBuilder pb = new ProcessBuilder("xdg-open", url);
var process = pb.start();

if (process.waitFor() != 0) {
throw new IOException("Could not open browser via xdg-open");
}
} catch (IOException e) {
log.error("Browser couldn't be opened", e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
Loading

0 comments on commit 551eae5

Please sign in to comment.