diff --git a/builders/linux-installer/install.sh b/builders/linux-installer/install.sh index f300754..25b5d40 100755 --- a/builders/linux-installer/install.sh +++ b/builders/linux-installer/install.sh @@ -9,6 +9,7 @@ fi desktopFile="BitKip.desktop" uninstallDesktopFile="BitKipUninstall.desktop" desktopFilePath="./application/$desktopFile" +uninstallDesktopFilePath="./application/$uninstallDesktopFile" for user in $(cut -d: -f1 /etc/passwd); do @@ -19,7 +20,7 @@ for user in $(cut -d: -f1 /etc/passwd); do done mv "$desktopFilePath" /usr/share/applications/ -mv "$uninstallDesktopFile" /usr/share/applications/ +mv "$uninstallDesktopFilePath" /usr/share/applications/ chmod a+rx ./application/bitkip mv ./application/bitkip /usr/bin/ diff --git a/src/main/java/ir/darkdeveloper/bitkip/BitKip.java b/src/main/java/ir/darkdeveloper/bitkip/BitKip.java index 93acd6c..9e613a7 100644 --- a/src/main/java/ir/darkdeveloper/bitkip/BitKip.java +++ b/src/main/java/ir/darkdeveloper/bitkip/BitKip.java @@ -5,6 +5,7 @@ import io.helidon.webserver.WebServer; import ir.darkdeveloper.bitkip.config.AppConfigs; import ir.darkdeveloper.bitkip.config.observers.QueueSubject; +import ir.darkdeveloper.bitkip.exceptions.DeniedException; import ir.darkdeveloper.bitkip.repo.DownloadsRepo; import ir.darkdeveloper.bitkip.repo.QueuesRepo; import ir.darkdeveloper.bitkip.repo.ScheduleRepo; @@ -17,6 +18,7 @@ import javafx.application.Application; import javafx.application.Platform; import javafx.stage.Stage; +import org.controlsfx.control.Notifications; import java.awt.*; @@ -55,6 +57,20 @@ public void start(Stage stage) { startServer(); } + private void initStartup() { + try { + if (!startup && existsOnStartup()) + removeFromStartup(); + if (startup && !existsOnStartup()) + addToStartup(); + } catch (DeniedException e) { + Notifications.create() + .title("Failed") + .text(e.getMessage()) + .showError(); + } + } + private void initTray(Stage stage) { if (SystemTray.isSupported()) { diff --git a/src/main/java/ir/darkdeveloper/bitkip/controllers/SettingsController.java b/src/main/java/ir/darkdeveloper/bitkip/controllers/SettingsController.java index 6312060..10673ec 100644 --- a/src/main/java/ir/darkdeveloper/bitkip/controllers/SettingsController.java +++ b/src/main/java/ir/darkdeveloper/bitkip/controllers/SettingsController.java @@ -302,7 +302,7 @@ private void onStartupCheck() { initStartup(); } - public static void initStartup() { + private void initStartup() { try { if (startup && !existsOnStartup()) addToStartup(); @@ -325,10 +325,16 @@ public static void addToStartup() throws DeniedException { System.getProperty("user.dir") + "\\BitKip.exe"); } else if (com.sun.jna.Platform.isLinux()) { var userHome = System.getProperty("user.home"); - var path = userHome + File.separator + ".config" + File.separator + "autostart" + "BitKip.d"; - var changedNamePath = userHome + File.separator + ".config" + File.separator + "autostart" + "BitKip.desktop"; + var configPath = userHome + File.separator + ".config" + File.separator + "autostart" + File.separator; + var path = configPath + "BitKip.d"; + var changedNamePath = configPath + "BitKip.desktop"; + var of = Path.of(changedNamePath); + try { - Files.move(Path.of(path), Path.of(changedNamePath), StandardCopyOption.REPLACE_EXISTING); + if (!new File(path).exists()) + Files.copy(Path.of("/usr/share/applications/BitKip.desktop"), of, StandardCopyOption.REPLACE_EXISTING); + else + Files.move(Path.of(path), of, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { throw new DeniedException("Failed to add BitKip to startup"); } @@ -342,7 +348,7 @@ public static boolean existsOnStartup() { "BitKip"); else if (com.sun.jna.Platform.isLinux()) { var userHome = System.getProperty("user.home"); - var path = userHome + File.separator + ".config" + File.separator + "autostart" + "BitKip.desktop"; + var path = userHome + File.separator + ".config" + File.separator + "autostart" + File.separator + "BitKip.desktop"; return new File(path).exists(); } return false; @@ -355,8 +361,8 @@ public static void removeFromStartup() throws DeniedException { "BitKip"); } else if (com.sun.jna.Platform.isLinux()) { var userHome = System.getProperty("user.home"); - var path = userHome + File.separator + ".config" + File.separator + "autostart" + "BitKip.desktop"; - var changedNamePath = userHome + File.separator + ".config" + File.separator + "autostart" + "BitKip.d"; + var path = userHome + File.separator + ".config" + File.separator + "autostart" + File.separator + "BitKip.desktop"; + var changedNamePath = userHome + File.separator + ".config" + File.separator + "autostart" + File.separator + "BitKip.d"; try { Files.move(Path.of(path), Path.of(changedNamePath), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) {