Skip to content

Commit

Permalink
Adding UpdateCheck class
Browse files Browse the repository at this point in the history
  • Loading branch information
zohaibanwer984 committed Dec 3, 2024
1 parent 2b42354 commit 04b4cfa
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion App.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#Sat Jul 27 17:57:27 PKT 2024
BracketMatching=true
CodeFolding=true
DEV=true
FontFamily=Consolas
HighlightCurrentLine=true
LineNumbers=true
LineWrap=false
editorTheme=default
fontSize=16
lookAndFeel=com.formdev.flatlaf.FlatLightLaf
version=1.0.4
3 changes: 2 additions & 1 deletion src/main/java/com/zam/ui/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@
* - Providing the main method to launch the application.
*
* @author Muhammed Zohaib
* @version 1.0.3
* @version 1.0.4
* @since 2023-11-29
*/
public class App extends JFrame {

// Constants
private static final double SCREEN_WIDTH_RATIO = 0.5;
private static final double SCREEN_HEIGHT_RATIO = 0.65;
public static final String APP_VERSION = "1.0.4";

// Private Componnets
private final JSplitPane splitPane;
Expand Down
54 changes: 54 additions & 0 deletions src/main/java/com/zam/utils/UpdateChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.zam.utils;

import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URI;
import java.util.Properties;

public class UpdateChecker {
private static final String UPDATE_URL = "https://raw.githubusercontent.com/zohaibanwer984/BitCode-Java-IDE/development/App.properties";
private static final String CURRENT_VERSION = "1.0.0";

public static void main(String[] args) {
SwingUtilities.invokeLater(UpdateChecker::checkForUpdate);
}

public static void checkForUpdate() {
try {
// Fetch the properties file
Properties remoteProperties = new Properties();
HttpURLConnection connection = (HttpURLConnection) new URI(UPDATE_URL).toURL().openConnection();
connection.setRequestMethod("GET");

try (InputStream inputStream = connection.getInputStream()) {
remoteProperties.load(inputStream);
}

// Get version
String latestVersion = remoteProperties.getProperty("version");
// String downloadUrl = remoteProperties.getProperty("downloadUrl");
String downloadUrl = "LINK TO DOWNLOAD";

// Compare versions
if (latestVersion != null && !CURRENT_VERSION.equals(latestVersion)) {
int choice = JOptionPane.showConfirmDialog(
null,
"A new version (" + latestVersion + ") is available. Do you want to download it?",
"Update Available",
JOptionPane.YES_NO_OPTION
);

if (choice == JOptionPane.YES_OPTION && downloadUrl != null) {
Desktop.getDesktop().browse(new URI(downloadUrl));
}
} else {
JOptionPane.showMessageDialog(null, "You are already using the latest version.", "No Updates", JOptionPane.INFORMATION_MESSAGE);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Failed to check for updates: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
}
}

0 comments on commit 04b4cfa

Please sign in to comment.