diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..ccc0ed7 --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,39 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle + +name: Java CI with Gradle + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + - name: Set execute permissions for gradlew + run: chmod +x gradlew + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3 + - name: Run the Gradle package task + uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629 + # with: + # arguments: -b ci.gradle package + - name: Build and Test with Gradle + run: ./gradlew build diff --git a/.gitignore b/.gitignore index 2ce1d2b..750c7d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,49 +1,50 @@ -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -# seems like no need in that -.idea/uiDesigner.xml -# same here, maybe for default worskapce -.idea/workspace.xml -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store - -# app specific +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/misc.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +# seems like no need in that +.idea/uiDesigner.xml +# same here, maybe for default worskapce +.idea/workspace.xml +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store + +# app specific debug.log \ No newline at end of file diff --git a/build.gradle b/build.gradle index e70252b..4ad7587 100644 --- a/build.gradle +++ b/build.gradle @@ -1,27 +1,26 @@ -plugins { - id 'java' -} - -group = 'github.kyxap.com' -version = '1.0-SNAPSHOT' - -repositories { - mavenCentral() -} - -dependencies { - implementation 'org.jetbrains:annotations:24.0.0' - testImplementation platform('org.junit:junit-bom:5.9.1') - testImplementation 'org.junit.jupiter:junit-jupiter' -} - -test { - useJUnitPlatform() -} - -jar { - manifest { - attributes "Main-Class": "github.kyxap.com.gui.tray.DriverUpdateChecker" - } - -} \ No newline at end of file +plugins { + id 'java' + id "maven-publish" +} + +group = 'github.kyxap.com' +version = '0.0.1' + +repositories { + mavenCentral() +} + +dependencies { + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +test { + useJUnitPlatform() +} + +jar { + manifest { + attributes "Main-Class": "github.kyxap.com.gui.tray.DriverUpdateChecker" + } +} diff --git a/src/main/java/github/kyxap/com/gui/tray/DriverUpdateChecker.java b/src/main/java/github/kyxap/com/gui/tray/DriverUpdateChecker.java index 37ae300..c183fe8 100644 --- a/src/main/java/github/kyxap/com/gui/tray/DriverUpdateChecker.java +++ b/src/main/java/github/kyxap/com/gui/tray/DriverUpdateChecker.java @@ -1,152 +1,154 @@ -package github.kyxap.com.gui.tray; - -import github.kyxap.com.config.ConfigProps; -import github.kyxap.com.utils.CmdWorker; -import github.kyxap.com.utils.HttpWorker; -import github.kyxap.com.utils.Logger; -import github.kyxap.com.utils.StringParser; - -import javax.imageio.ImageIO; -import java.awt.AWTException; -import java.awt.MenuItem; -import java.awt.PopupMenu; -import java.awt.SystemTray; -import java.awt.TrayIcon; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.net.URL; - -import static github.kyxap.com.config.AppConfig.getProperty; -import static github.kyxap.com.config.AppConfig.loadProperties; -import static github.kyxap.com.gui.windows.PopUpWorker.openAboutWindow; -import static github.kyxap.com.gui.windows.PopUpWorker.popUpInfo; -import static github.kyxap.com.utils.Scheduler.scheduleVersionCheck; - -/** - * https://www.nvidia.com/Download/Find.aspx?lang=en-us - * https://www.nvidia.com/Download/processFind.aspx?psid=127&pfid=995&osid=135&lid=1&whql=1&lang=en-us&ctk=0&qnfslb=00&dtcid=1 - *
- * linux versions: - * https://github.com/aaronp24/nvidia-versions - */ -public class DriverUpdateChecker { - - // Load an image for the tray icon - static URL TRAY_ICON = DriverUpdateChecker.class.getClassLoader().getResource("img/icon_v2a.png"); - - public static BufferedImage TRAY_ICON_IMG; - - private static String uri; - - public static void main(final String[] args) throws IOException { - // Load properties - loadProperties(); - // Access properties - uri = getProperty(ConfigProps.App.URI_TO_GET_DATA_FROM.getDescription()); - final boolean debugEnabled = Boolean.parseBoolean(getProperty(ConfigProps.LoggerSettings.DEBUG.getDescription())); - final boolean devOutputEnabled = Boolean.parseBoolean(getProperty(ConfigProps.LoggerSettings.DEV_OUTPUT.getDescription())); - Logger.setLoggerOutput(debugEnabled, devOutputEnabled); - - Logger.log("URI which will be using to parse data from: " + uri); - - if (SystemTray.isSupported()) { - final DriverUpdateChecker trayExample = new DriverUpdateChecker(); - trayExample.createSystemTray(); - } else { - // TODO: make sure scheduler works without tray - final String msg = "SystemTray is not supported on this platform, but scheduler is started"; - popUpInfo(msg); - Logger.log(msg); - } - scheduleVersionCheck(); - } - - private void createSystemTray() { - try { - // Create a system tray instance - final SystemTray systemTray = SystemTray.getSystemTray(); - - // Create a tray icon - TRAY_ICON_IMG = ImageIO.read(TRAY_ICON); - final TrayIcon trayIcon = new TrayIcon(TRAY_ICON_IMG, "GPU Update Checker", setPopupMenu()); - trayIcon.setImageAutoSize(true); - - // Set default action for double-click - trayIcon.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - // Your action on double-click - Logger.log("Tray icon clicked"); - } - }); - - // Add the tray icon to the system tray - systemTray.add(trayIcon); - - } catch (final AWTException e) { - e.printStackTrace(); - } catch (final IOException e) { - throw new RuntimeException(e); - } - } - - private PopupMenu setPopupMenu() { - final PopupMenu popupMenu = new PopupMenu(); - - // Add "Check Driver Updates" menu item - final MenuItem checkUpdatesItem = new MenuItem("Check Driver Updates"); - checkUpdatesItem.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - // Handle the "Check Driver Updates" action - Logger.log("Check Driver Updates clicked"); - if (isNewUpdateAvailable()) { - popUpInfo("New driver version updated is available"); - } else { - popUpInfo("You are using latest version, no updates available"); - } - } - }); - popupMenu.add(checkUpdatesItem); - - // Add "About" menu item - final MenuItem aboutItem = new MenuItem("About"); - aboutItem.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - // Handle the "About" action - Logger.log("About clicked"); - openAboutWindow(); - } - }); - popupMenu.add(aboutItem); - - // Add separator - popupMenu.addSeparator(); - - // Add "Exit" menu item - final MenuItem exitItem = new MenuItem("Exit"); - exitItem.addActionListener(new ActionListener() { - public void actionPerformed(final ActionEvent e) { - System.exit(0); - } - }); - - popupMenu.add(exitItem); - - return popupMenu; - } - - public static boolean isNewUpdateAvailable() { - if (uri != null) { - final String latestVer = StringParser.extractVersionFromHtlmString(HttpWorker.get(uri)); - final String installedVer = CmdWorker.runCmd("nvidia-smi"); - final String printInfo = "Needs update: "; - Logger.log(printInfo + !installedVer.equals(latestVer)); - - return !installedVer.equals(latestVer); - } else { - Logger.log("uri is null at the start"); - return false; - } - } -} +package github.kyxap.com.gui.tray; + +import github.kyxap.com.config.ConfigProps; +import github.kyxap.com.utils.CmdWorker; +import github.kyxap.com.utils.HttpWorker; +import github.kyxap.com.utils.Logger; +import github.kyxap.com.utils.StringParser; + +import javax.imageio.ImageIO; +import java.awt.AWTException; +import java.awt.MenuItem; +import java.awt.PopupMenu; +import java.awt.SystemTray; +import java.awt.TrayIcon; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.net.URL; + +import static github.kyxap.com.config.AppConfig.getProperty; +import static github.kyxap.com.config.AppConfig.loadProperties; +import static github.kyxap.com.gui.windows.PopUpType.ABOUT; +import static github.kyxap.com.gui.windows.PopUpType.INFO; +import static github.kyxap.com.gui.windows.PopUpWorker.openAboutWindow; +import static github.kyxap.com.gui.windows.PopUpWorker.popUpInfo; +import static github.kyxap.com.utils.Scheduler.scheduleVersionCheck; + +/** + * https://www.nvidia.com/Download/Find.aspx?lang=en-us + * https://www.nvidia.com/Download/processFind.aspx?psid=127&pfid=995&osid=135&lid=1&whql=1&lang=en-us&ctk=0&qnfslb=00&dtcid=1 + *
+ * linux versions: + * https://github.com/aaronp24/nvidia-versions + */ +public class DriverUpdateChecker { + + // Load an image for the tray icon + static URL TRAY_ICON = DriverUpdateChecker.class.getClassLoader().getResource("img/icon_v2a.png"); + + public static BufferedImage TRAY_ICON_IMG; + + private static String uri; + + public static void main(final String[] args) throws IOException { + // Load properties + loadProperties(); + // Access properties + uri = getProperty(ConfigProps.App.URI_TO_GET_DATA_FROM.getDescription()); + final boolean debugEnabled = Boolean.parseBoolean(getProperty(ConfigProps.LoggerSettings.DEBUG.getDescription())); + final boolean devOutputEnabled = Boolean.parseBoolean(getProperty(ConfigProps.LoggerSettings.DEV_OUTPUT.getDescription())); + Logger.setLoggerOutput(debugEnabled, devOutputEnabled); + + Logger.log("URI which will be using to parse data from: " + uri); + + if (SystemTray.isSupported()) { + final DriverUpdateChecker trayExample = new DriverUpdateChecker(); + trayExample.createSystemTray(); + } else { + // TODO: make sure scheduler works without tray + final String msg = "SystemTray is not supported on this platform, but scheduler is started"; + popUpInfo(INFO, msg); + Logger.log(msg); + } + scheduleVersionCheck(); + } + + private void createSystemTray() { + try { + // Create a system tray instance + final SystemTray systemTray = SystemTray.getSystemTray(); + + // Create a tray icon + TRAY_ICON_IMG = ImageIO.read(TRAY_ICON); + final TrayIcon trayIcon = new TrayIcon(TRAY_ICON_IMG, "GPU Update Checker", setPopupMenu()); + trayIcon.setImageAutoSize(true); + + // Set default action for double-click + trayIcon.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + // Your action on double-click + Logger.log("Tray icon clicked"); + } + }); + + // Add the tray icon to the system tray + systemTray.add(trayIcon); + + } catch (final AWTException e) { + e.printStackTrace(); + } catch (final IOException e) { + throw new RuntimeException(e); + } + } + + private PopupMenu setPopupMenu() { + final PopupMenu popupMenu = new PopupMenu(); + + // Add "Check Driver Updates" menu item + final MenuItem checkUpdatesItem = new MenuItem("Check Driver Updates"); + checkUpdatesItem.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + // Handle the "Check Driver Updates" action + Logger.log("Check Driver Updates clicked"); + if (isNewUpdateAvailable()) { + popUpInfo(INFO, "New driver version updated is available"); + } else { + popUpInfo(INFO, "You are using latest version, no updates available"); + } + } + }); + popupMenu.add(checkUpdatesItem); + + // Add "About" menu item + final MenuItem aboutItem = new MenuItem(ABOUT); + aboutItem.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + // Handle the "About" action + Logger.log(ABOUT + " clicked"); + openAboutWindow(); + } + }); + popupMenu.add(aboutItem); + + // Add separator + popupMenu.addSeparator(); + + // Add "Exit" menu item + final MenuItem exitItem = new MenuItem("Exit"); + exitItem.addActionListener(new ActionListener() { + public void actionPerformed(final ActionEvent e) { + System.exit(0); + } + }); + + popupMenu.add(exitItem); + + return popupMenu; + } + + public static boolean isNewUpdateAvailable() { + if (uri != null) { + final String latestVer = StringParser.extractVersionFromHtlmString(HttpWorker.get(uri)); + final String installedVer = CmdWorker.runCmd("nvidia-smi"); + final String printInfo = "Needs update: "; + Logger.log(printInfo + !installedVer.equals(latestVer)); + + return !installedVer.equals(latestVer); + } else { + Logger.log("uri is null at the start"); + return false; + } + } +} diff --git a/src/main/java/github/kyxap/com/gui/windows/PopUpType.java b/src/main/java/github/kyxap/com/gui/windows/PopUpType.java new file mode 100644 index 0000000..548ee46 --- /dev/null +++ b/src/main/java/github/kyxap/com/gui/windows/PopUpType.java @@ -0,0 +1,6 @@ +package github.kyxap.com.gui.windows; + +public class PopUpType { + public static final String INFO = "Info"; + public static final String ABOUT = "About"; +} diff --git a/src/main/java/github/kyxap/com/gui/windows/PopUpWorker.java b/src/main/java/github/kyxap/com/gui/windows/PopUpWorker.java index 2893c9f..00c99d7 100644 --- a/src/main/java/github/kyxap/com/gui/windows/PopUpWorker.java +++ b/src/main/java/github/kyxap/com/gui/windows/PopUpWorker.java @@ -1,106 +1,148 @@ -package github.kyxap.com.gui.windows; - -import github.kyxap.com.utils.CmdWorker; - -import java.awt.Dimension; -import java.awt.Frame; -import java.awt.Image; -import java.awt.Label; -import java.awt.Toolkit; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - -import static github.kyxap.com.gui.tray.DriverUpdateChecker.TRAY_ICON_IMG; - -public class PopUpWorker { - static Image POP_UP_ICON; - - public PopUpWorker(final Image POP_UP_ICON) { - this.POP_UP_ICON = POP_UP_ICON; - } - - public PopUpWorker() { - } - - /** - * No External dependecy on Swing, X works with extra - */ - public static void openAboutWindow() { - // Create and display a simple window for "About" - final Frame aboutFrame = new Frame("About"); - aboutFrame.setSize(300, 200); - - final Label label = new Label("Installed driver version: " + CmdWorker.runCmd("nvidia-smi")); - aboutFrame.add(label); - if (POP_UP_ICON == null) { - aboutFrame.setIconImage(TRAY_ICON_IMG); - } else aboutFrame.setIconImage(POP_UP_ICON); - - - // Allow closing the Frame by clicking the X button - aboutFrame.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent e) { - aboutFrame.dispose(); - } - }); - - // Center the Frame on the screen - centerFrameOnScreen(aboutFrame); - - aboutFrame.setVisible(true); - } - - public static void popUpError(final String error) { - // Create and display a simple window for "About" - final Frame aboutFrame = new Frame("Error"); - aboutFrame.setSize(300, 200); - - final Label label = new Label(error); - aboutFrame.add(label); -// aboutFrame.setIconImage(appIcon); - - // Allow closing the Frame by clicking the X button - aboutFrame.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent e) { - aboutFrame.dispose(); - } - }); - - // Center the Frame on the screen - centerFrameOnScreen(aboutFrame); - aboutFrame.setVisible(true); - } - - public static void popUpInfo(final String infoMsg) { - // Create and display a simple window for "About" - final Frame popUpInfo = new Frame("Info"); - popUpInfo.setSize(300, 200); - - final Label label = new Label(infoMsg); - popUpInfo.add(label); - if (POP_UP_ICON == null) { - popUpInfo.setIconImage(TRAY_ICON_IMG); - } else popUpInfo.setIconImage(POP_UP_ICON); - - // Allow closing the Frame by clicking the X button - popUpInfo.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent e) { - popUpInfo.dispose(); - } - }); - - // Center the Frame on the screen - centerFrameOnScreen(popUpInfo); - popUpInfo.setVisible(true); - } - - private static void centerFrameOnScreen(final Frame frame) { - final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - final int x = (screenSize.width - frame.getWidth()) / 2; - final int y = (screenSize.height - frame.getHeight()) / 2; - frame.setLocation(x, y); - } -} +package github.kyxap.com.gui.windows; + +import github.kyxap.com.utils.CmdWorker; + +import java.awt.Color; +import java.awt.Cursor; +import java.awt.Desktop; +import java.awt.Dimension; +import java.awt.Frame; +import java.awt.GridLayout; +import java.awt.Image; +import java.awt.Label; +import java.awt.Panel; +import java.awt.Toolkit; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.net.URI; + +import static github.kyxap.com.gui.tray.DriverUpdateChecker.TRAY_ICON_IMG; +import static github.kyxap.com.gui.windows.PopUpType.ABOUT; +import static github.kyxap.com.utils.URI.HOME; + +public class PopUpWorker { + static Image POP_UP_ICON; + + public PopUpWorker(final Image POP_UP_ICON) { + this.POP_UP_ICON = POP_UP_ICON; + } + + public PopUpWorker() { + } + + /** + * No External dependecy on Swing, X works with extra + */ + public static void openAboutWindow() { + // Create and display a simple window for "About" + final Frame popUpInfo = new Frame(ABOUT); + popUpInfo.setSize(300, 200); + + // Create a panel with GridLayout to center the label + final Panel panel = new Panel(new GridLayout(2, 1)); + popUpInfo.add(panel); + + final Label label = new Label("Installed driver version: " + CmdWorker.runCmd("nvidia-smi"), Label.CENTER); // Center-align the text in the label + panel.add(label); + + final Label linkLabel = new Label("Want to know more? Visit my github", Label.CENTER); + linkLabel.setForeground(Color.BLUE); + linkLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); + linkLabel.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + openLink(HOME); + popUpInfo.dispose(); + } + }); + panel.add(linkLabel); + + if (POP_UP_ICON == null) { + popUpInfo.setIconImage(TRAY_ICON_IMG); + } else { + popUpInfo.setIconImage(POP_UP_ICON); + } + + // Allow closing the Frame by clicking the X button + popUpInfo.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(final WindowEvent e) { + popUpInfo.dispose(); + } + }); + + // Center the Frame on the screen + centerFrameOnScreen(popUpInfo); + popUpInfo.setVisible(true); + } + + public static void popUpError(final String error) { + // Create and display a simple window for "About" + final Frame aboutFrame = new Frame("Error"); + aboutFrame.setSize(300, 200); + + final Label label = new Label(error); + aboutFrame.add(label); +// aboutFrame.setIconImage(appIcon); + + // Allow closing the Frame by clicking the X button + aboutFrame.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(final WindowEvent e) { + aboutFrame.dispose(); + } + }); + + // Center the Frame on the screen + centerFrameOnScreen(aboutFrame); + aboutFrame.setVisible(true); + } + + public static void popUpInfo(final String tittle, final String infoMsg) { + // Create and display a simple window for "About" + final Frame popUpInfo = new Frame(tittle); + popUpInfo.setSize(300, 200); + + // Create a panel with GridLayout to center the label + final Panel panel = new Panel(new GridLayout(1, 1)); + popUpInfo.add(panel); + + final Label label = new Label(infoMsg, Label.CENTER); // Center-align the text in the label + panel.add(label); + + if (POP_UP_ICON == null) { + popUpInfo.setIconImage(TRAY_ICON_IMG); + } else { + popUpInfo.setIconImage(POP_UP_ICON); + } + + // Allow closing the Frame by clicking the X button + popUpInfo.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(final WindowEvent e) { + popUpInfo.dispose(); + } + }); + + // Center the Frame on the screen + centerFrameOnScreen(popUpInfo); + popUpInfo.setVisible(true); + } + + private static void openLink(final String linkUrl) { + try { + Desktop.getDesktop().browse(new URI(linkUrl)); + } catch (final Exception e) { + e.printStackTrace(); + } + } + + private static void centerFrameOnScreen(final Frame frame) { + final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + final int x = (screenSize.width - frame.getWidth()) / 2; + final int y = (screenSize.height - frame.getHeight()) / 2; + frame.setLocation(x, y); + } +} diff --git a/src/main/java/github/kyxap/com/utils/Scheduler.java b/src/main/java/github/kyxap/com/utils/Scheduler.java index 3c73d78..c27d09b 100644 --- a/src/main/java/github/kyxap/com/utils/Scheduler.java +++ b/src/main/java/github/kyxap/com/utils/Scheduler.java @@ -1,39 +1,40 @@ -package github.kyxap.com.utils; - -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -import static github.kyxap.com.gui.tray.DriverUpdateChecker.isNewUpdateAvailable; -import static github.kyxap.com.gui.windows.PopUpWorker.popUpInfo; - -public class Scheduler { - private static final int period = 60; - private static final TimeUnit minutes = TimeUnit.MINUTES; - - public static void scheduleVersionCheck() { - // Create a scheduled executor service with a single thread - final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); - - // Define the task to be scheduled (replace with your actual task) - final Runnable task = () -> { - Logger.log("Scheduler executing started for every: " + period + " " + minutes.name().toLowerCase()); - // Replace the next line with the method you want to run - if (isNewUpdateAvailable()) popUpInfo("New driver version update is available"); - }; - - // Schedule the task to run every 60 minute with an initial delay of 0 seconds - scheduler.scheduleAtFixedRate(task, 0, period, minutes); - - // If you want the scheduler to keep running in the background, you may need to prevent the application from terminating - // For a simple console application, you can add a delay or use a loop to keep it running - try { - Thread.sleep(Long.MAX_VALUE); - } catch (final InterruptedException e) { - e.printStackTrace(); - } - - // Shutdown the scheduler when the application is about to exit - scheduler.shutdown(); - } -} +package github.kyxap.com.utils; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import static github.kyxap.com.gui.tray.DriverUpdateChecker.isNewUpdateAvailable; +import static github.kyxap.com.gui.windows.PopUpType.INFO; +import static github.kyxap.com.gui.windows.PopUpWorker.popUpInfo; + +public class Scheduler { + private static final int period = 60; + private static final TimeUnit minutes = TimeUnit.MINUTES; + + public static void scheduleVersionCheck() { + // Create a scheduled executor service with a single thread + final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); + + // Define the task to be scheduled (replace with your actual task) + final Runnable task = () -> { + Logger.log("Scheduler executing started for every: " + period + " " + minutes.name().toLowerCase()); + // Replace the next line with the method you want to run + if (isNewUpdateAvailable()) popUpInfo(INFO, "New driver version update is available"); + }; + + // Schedule the task to run every 60 minute with an initial delay of 0 seconds + scheduler.scheduleAtFixedRate(task, 0, period, minutes); + + // If you want the scheduler to keep running in the background, you may need to prevent the application from terminating + // For a simple console application, you can add a delay or use a loop to keep it running + try { + Thread.sleep(Long.MAX_VALUE); + } catch (final InterruptedException e) { + e.printStackTrace(); + } + + // Shutdown the scheduler when the application is about to exit + scheduler.shutdown(); + } +} diff --git a/src/main/java/github/kyxap/com/utils/URI.java b/src/main/java/github/kyxap/com/utils/URI.java new file mode 100644 index 0000000..3bbf7ef --- /dev/null +++ b/src/main/java/github/kyxap/com/utils/URI.java @@ -0,0 +1,5 @@ +package github.kyxap.com.utils; + +public class URI { + public static final String HOME = "https://github.com/kyxap/gpu-update-checker"; +} diff --git a/src/test/java/StringParserTest.java b/src/test/java/StringParserTest.java new file mode 100644 index 0000000..7bf6282 --- /dev/null +++ b/src/test/java/StringParserTest.java @@ -0,0 +1,29 @@ +import github.kyxap.com.utils.StringParser; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class StringParserTest { + + @Test + public void parseHtml() throws IOException { + // Path relative to src/test/resources + final String filePath = "rtx40xx.html"; + + // Resolve the path to the file + final Path path = Paths.get("src", "test", "resources", filePath); + + // Read the content of the file + final String content = Files.readString(path); + + final String parsedVer = StringParser.extractVersionFromHtlmString(content); + + // Perform assertions or further processing + assertEquals("546.29", parsedVer); + } +} diff --git a/src/test/resources/rtx40xx.html b/src/test/resources/rtx40xx.html new file mode 100644 index 0000000..74d5b35 --- /dev/null +++ b/src/test/resources/rtx40xx.html @@ -0,0 +1,685 @@ +
+
+
|
+