From 30e96c756f44c5cc44ac3bf84efd18e32aa5821f Mon Sep 17 00:00:00 2001 From: David Jones Date: Tue, 16 Sep 2025 09:41:52 +0100 Subject: [PATCH 1/4] add menu entry for export --- app/src/main/res/menu/shortcut_popup_menu.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/res/menu/shortcut_popup_menu.xml b/app/src/main/res/menu/shortcut_popup_menu.xml index 3fc992eed4..2345267b5c 100644 --- a/app/src/main/res/menu/shortcut_popup_menu.xml +++ b/app/src/main/res/menu/shortcut_popup_menu.xml @@ -2,4 +2,5 @@ + From f4ec10c07baef430f4ca47c7b53d273c21ca8fb4 Mon Sep 17 00:00:00 2001 From: David Jones Date: Tue, 16 Sep 2025 10:10:40 +0100 Subject: [PATCH 2/4] add export function --- .../java/com/winlator/ShortcutsFragment.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/app/src/main/java/com/winlator/ShortcutsFragment.java b/app/src/main/java/com/winlator/ShortcutsFragment.java index c4095dc117..f0f25b7a03 100644 --- a/app/src/main/java/com/winlator/ShortcutsFragment.java +++ b/app/src/main/java/com/winlator/ShortcutsFragment.java @@ -13,6 +13,7 @@ import android.widget.ImageView; import android.widget.PopupMenu; import android.widget.TextView; +import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -27,6 +28,11 @@ import com.winlator.contentdialog.ContentDialog; import com.winlator.contentdialog.ShortcutSettingsDialog; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -128,11 +134,73 @@ else if (itemId == R.id.shortcut_remove) { loadShortcutsList(); }); } + else if (itemId == R.id.shortcut_export_to_frontend) { + exportShortcutToFrontend(shortcut); + } return true; }); listItemMenu.show(); } + private void exportShortcutToFrontend(Shortcut shortcut) { + // Attempt to make the frontend dir + File frontendDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "Winlator/Frontend"); + if (!frontendDir.exists() && !frontendDir.mkdirs()) { + Toast.makeText(getContext(), "Failed to create default frontend directory", Toast.LENGTH_SHORT).show(); + return; + } + + // Create the export file in the Frontend directory + File exportFile = new File(frontendDir, shortcut.file.getName()); + + boolean fileExists = exportFile.exists(); + boolean containerIdFound = false; + + try { + List lines = new ArrayList<>(); + + // Read the original file or existing file if it exists + try (BufferedReader reader = new BufferedReader(new FileReader(shortcut.file))) { + String line; + while ((line = reader.readLine()) != null) { + if (line.startsWith("container_id=")) { + // Replace the existing container_id line + lines.add("container_id=" + shortcut.container.id); + containerIdFound = true; + } else { + lines.add(line); + } + } + } + + // If no container_id was found, add it + if (!containerIdFound) { + lines.add("container_id=" + shortcut.container.id); + } + + // Write the contents to the export file + try (FileWriter writer = new FileWriter(exportFile, false)) { + for (String line : lines) { + writer.write(line + "\n"); + } + writer.flush(); + } + + // Determine the toast message + String message; + if (fileExists) { + message = "Frontend Shortcut Updated at " + exportFile.getPath(); + } else { + message = "Frontend Shortcut Exported to " + exportFile.getPath(); + } + + // Show a toast message to the user + Toast.makeText(getContext(), message, Toast.LENGTH_LONG).show(); + } catch (IOException e) { + Toast.makeText(getContext(), "Failed to export shortcut", Toast.LENGTH_LONG).show(); + } + } + private void runFromShortcut(Shortcut shortcut) { Activity activity = getActivity(); From e29715d322e353091bef2363ec07f9ef6926cd07 Mon Sep 17 00:00:00 2001 From: David Jones Date: Tue, 16 Sep 2025 12:12:42 +0100 Subject: [PATCH 3/4] Update shortcut_popup_menu.xml --- app/src/main/res/menu/shortcut_popup_menu.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/menu/shortcut_popup_menu.xml b/app/src/main/res/menu/shortcut_popup_menu.xml index 2345267b5c..d8c92e9aa8 100644 --- a/app/src/main/res/menu/shortcut_popup_menu.xml +++ b/app/src/main/res/menu/shortcut_popup_menu.xml @@ -2,5 +2,5 @@ - + From c3abd89b72e38bcf987de664b22f673bf2c93d8b Mon Sep 17 00:00:00 2001 From: David Jones Date: Tue, 16 Sep 2025 12:25:39 +0100 Subject: [PATCH 4/4] Update strings.xml --- app/src/main/res/values/strings.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4879afecf5..828e2205af 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -225,4 +225,5 @@ Warning: Installing a new version of Wine is recommended for testing purposes only. Startup Selection Wine Debug Channel - \ No newline at end of file + Export for frontend +