Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label printing fix #587

Merged
merged 3 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading