Skip to content

Commit

Permalink
Label printing fix (#587)
Browse files Browse the repository at this point in the history
* Handle blank URL provided for file download

* Improved printing checks

* Auto-select the correct printer
  • Loading branch information
SchrodingersGat authored Dec 22, 2024
1 parent dc8191c commit bc44b99
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
1 change: 1 addition & 0 deletions assets/release_notes.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
7 changes: 6 additions & 1 deletion lib/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,11 @@ class InvenTreeAPI {
*/
Future<void> 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();

Expand Down Expand Up @@ -1538,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();
Expand Down
2 changes: 1 addition & 1 deletion lib/inventree/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ class InvenTreeUserSetting extends InvenTreeGlobalSetting {

@override
InvenTreeGlobalSetting createFromJson(Map<String, dynamic> json) {
return InvenTreeGlobalSetting.fromJson(json);
return InvenTreeUserSetting.fromJson(json);
}

@override
Expand Down
22 changes: 15 additions & 7 deletions lib/labels.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ Future<void> 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"];
}

Expand Down Expand Up @@ -111,27 +115,29 @@ Future<void> 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")) {
Expand All @@ -145,6 +151,8 @@ Future<void> selectAndPrintLabel(
});
}

hideLoadingOverlay();

if (result) {
showSnackIcon(
L10().printLabelSuccess,
Expand Down
4 changes: 3 additions & 1 deletion lib/widget/progress.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,7 @@ void showLoadingOverlay() {


void hideLoadingOverlay() {
Loader.hide();
if (Loader.isShown) {
Loader.hide();
}
}

0 comments on commit bc44b99

Please sign in to comment.