From 7eee06e27cf710b70892f5505c07e28b1401579d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 23 Dec 2024 09:30:24 +1100 Subject: [PATCH 1/3] Handle blank URL provided for file download --- assets/release_notes.md | 1 + lib/api.dart | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/assets/release_notes.md b/assets/release_notes.md index 91c6b49a..3b1237cc 100644 --- a/assets/release_notes.md +++ b/assets/release_notes.md @@ -1,6 +1,7 @@ ### 0.17.2 - December 2024 --- +- Fixed error message when printing a label to a remote machine - Prevent notification sounds from pause media playback - Updated translations diff --git a/lib/api.dart b/lib/api.dart index d686e1b1..9386efa8 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -817,6 +817,11 @@ class InvenTreeAPI { */ Future downloadFile(String url, {bool openOnDownload = true}) async { + if (url.isEmpty) { + // No URL provided for download + return; + } + // Find the local downlods directory final Directory dir = await getTemporaryDirectory(); From a7113924e0c8aac678376f14fff38b33ff546805 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 23 Dec 2024 09:35:13 +1100 Subject: [PATCH 2/3] Improved printing checks --- lib/labels.dart | 16 ++++++++++------ lib/widget/progress.dart | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/labels.dart b/lib/labels.dart index 1e15bd4a..e88210e2 100644 --- a/lib/labels.dart +++ b/lib/labels.dart @@ -111,27 +111,29 @@ Future selectAndPrintLabel( "items": [instanceId] } ).then((APIResponse response) { - hideLoadingOverlay(); if (response.isValid() && response.statusCode >= 200 && response.statusCode <= 201) { var data = response.asMap(); if (data.containsKey("output")) { - var label_file = (data["output"] ?? "") as String; + String? label_file = (data["output"]) as String?; + + if (label_file != null && label_file.isNotEmpty) { + // Attempt to open generated file + InvenTreeAPI().downloadFile(label_file); + } - // Attempt to open generated file - InvenTreeAPI().downloadFile(label_file); result = true; } } }); - } else { + + } else { // Legacy label printing API // Uses a GET request to a specially formed URL which depends on the parameters String url = "/label/${labelType}/${labelId}/print/?${labelQuery}&plugin=${pluginKey}"; await InvenTreeAPI().get(url).then((APIResponse response) { - hideLoadingOverlay(); if (response.isValid() && response.statusCode == 200) { var data = response.asMap(); if (data.containsKey("file")) { @@ -145,6 +147,8 @@ Future selectAndPrintLabel( }); } + hideLoadingOverlay(); + if (result) { showSnackIcon( L10().printLabelSuccess, diff --git a/lib/widget/progress.dart b/lib/widget/progress.dart index cc00c85b..3deb9387 100644 --- a/lib/widget/progress.dart +++ b/lib/widget/progress.dart @@ -66,5 +66,7 @@ void showLoadingOverlay() { void hideLoadingOverlay() { - Loader.hide(); + if (Loader.isShown) { + Loader.hide(); + } } From 9c29c4921149d78c75bc01c98a059914165d6b06 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 23 Dec 2024 09:48:44 +1100 Subject: [PATCH 3/3] Auto-select the correct printer --- lib/api.dart | 2 +- lib/inventree/model.dart | 2 +- lib/labels.dart | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/api.dart b/lib/api.dart index 9386efa8..24e8c1fd 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -1543,7 +1543,7 @@ class InvenTreeAPI { return setting.value; } - final response = await InvenTreeGlobalSetting().getModel(key); + final response = await InvenTreeUserSetting().getModel(key); if (response is InvenTreeUserSetting) { response.lastReload = DateTime.now(); diff --git a/lib/inventree/model.dart b/lib/inventree/model.dart index 2078f86d..fc90a2ba 100644 --- a/lib/inventree/model.dart +++ b/lib/inventree/model.dart @@ -904,7 +904,7 @@ class InvenTreeUserSetting extends InvenTreeGlobalSetting { @override InvenTreeGlobalSetting createFromJson(Map json) { - return InvenTreeGlobalSetting.fromJson(json); + return InvenTreeUserSetting.fromJson(json); } @override diff --git a/lib/labels.dart b/lib/labels.dart index e88210e2..819df713 100644 --- a/lib/labels.dart +++ b/lib/labels.dart @@ -63,7 +63,11 @@ Future selectAndPrintLabel( }); } - if (plugin_options.length == 1) { + String selectedPlugin = await InvenTreeAPI().getUserSetting("LABEL_DEFAULT_PRINTER"); + + if (selectedPlugin.isNotEmpty) { + initial_plugin = selectedPlugin; + } else if (plugin_options.length == 1) { initial_plugin = plugin_options.first["value"]; }