Skip to content

Fixes in "printers@cinnamon.org"#13524

Open
hans-fritz-pommes wants to merge 6 commits intolinuxmint:masterfrom
hans-fritz-pommes:patch-1
Open

Fixes in "printers@cinnamon.org"#13524
hans-fritz-pommes wants to merge 6 commits intolinuxmint:masterfrom
hans-fritz-pommes:patch-1

Conversation

@hans-fritz-pommes
Copy link

@hans-fritz-pommes hans-fritz-pommes commented Feb 1, 2026

I encountered several small issues with the printers applet.
I modified the applet.js in /usr/share/cinnamon/applets/printers@cinnamon.org and tested printing documents.
The things I did correct:

  • The "Cancel all jobs" command didn't work for an user who had no permisisons to run cancel -a for a specific printer, even if all of the jobs on this printer belonged to him.
    -> Now the "Cancel all jobs" command tries to cancel every single job, not cancel -a for every printer
  • The appearance of the listed jobs was really bad: e.g. when you had more than one job, the description for every job was "<desc. first job><desc. second job><desc..." and so on.
  • The job description consisted of: (job number) lpstat -o (lpstat several times, if there was more than one job - see point before)
    -> The description is now: (job number) 'document_name' on <printer_name> (<size in Bytes/MB/KB>) by <user> (using lpq -a).

The following problem could occur:
If a job has the same number as byte-size like the job-id of the following one, the username and the filesize of the first one will be strange (job-id and functions stay working).
I would say this will happen that seldom - we should ignore it.
Which user will open the menu exactly in that minute and have a problem with a strange username or filesize?

EDIT: fixed in new commit

@hans-fritz-pommes
Copy link
Author

Oh and I changed icons. If you think they're ugly, just revert it

@hans-fritz-pommes hans-fritz-pommes marked this pull request as draft February 1, 2026 19:18
@hans-fritz-pommes
Copy link
Author

I have an idea how to fix this mini-problem (identical bytes & job-number). But later

Fix mini-problem (See linuxmint#13524)
@hans-fritz-pommes hans-fritz-pommes marked this pull request as ready for review February 1, 2026 20:54
@hans-fritz-pommes
Copy link
Author

Ok, now the identical bytes/document-name & job-number-problem is fixed.

@hans-fritz-pommes hans-fritz-pommes marked this pull request as draft February 2, 2026 12:36
@hans-fritz-pommes
Copy link
Author

Sorry that I'm so chaotic
I forgot to take care of document names with whitespaces

Support filenames with whitespaces
@hans-fritz-pommes hans-fritz-pommes marked this pull request as ready for review February 2, 2026 14:11
@claudiux claudiux requested a review from clefebvre February 2, 2026 14:13
Comment on lines +14 to +27
function formatBytes(bytesStr) {
const bytes = parseInt(bytesStr, 10);
if (isNaN(bytes) || bytes === 0) return "0 Bytes";

const k = 1024;
const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
const value = bytes / Math.pow(k, i);

return value.toLocaleString(undefined, {
minimumFractionDigits: 1,
maximumFractionDigits: 1
}) + " " + sizes[i];
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using GLib.format_size() or GLib.format_size_full() instead here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice function!

let size = formatBytes(jobInfo[job][3]);

if(doc.length > 30) {
doc = doc + '...';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't part of your changes, but maybe fix this - it detects a long string but doesn't actually shorten it before adding ellipses.

}

let text = '(' + job + ') ' + _("'%s' on %s").format(doc, printer);
text = text + ' (' + size + ')' + _(" - by %s").format(user);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't this be a single translatable string?

# Translators: strings are job #, document name, printer name, size, username
# example: (23) 'test-doc.md' on HP_Smart_Tank_5100_series (44.0 KB) - by mtwebster
text = "(%s) '%s' on %s (%s) - by %s".format(job, doc, printer, size, user);

When 'Translators' is detected, these comments are included in the potfile to aid in translations

@github-actions
Copy link

github-actions bot commented Mar 5, 2026

Best-practices scanner

This is a regex-based check for API usage that can pose security, performance or
maintainability issues, or that may already be provided by Cinnamon. Having code flagged
by it doesn't automatically disqualify a pull request.

This check is not perfect will not replace a normal review.


Found 1 potential issue(s):

⚠️ lang_bind

files/usr/share/cinnamon/applets/printers@cinnamon.org/applet.js:218

Util.spawn_async(['/usr/bin/lpq', '-a'], Lang.bind(this, function(out2) {

Lang.bind() is deprecated. Use arrow functions (() => {}) or Function.prototype.bind() instead.


Automated pattern check.

Improved with mtwebsters ideas
(linuxmint#13524)
@github-actions
Copy link

github-actions bot commented Mar 5, 2026

Best-practices scanner

This is a regex-based check for API usage that can pose security, performance or
maintainability issues, or that may already be provided by Cinnamon. Having code flagged
by it doesn't automatically disqualify a pull request.

This check is not perfect will not replace a normal review.


Found 1 potential issue(s):

⚠️ lang_bind

files/usr/share/cinnamon/applets/printers@cinnamon.org/applet.js:203

Util.spawn_async(['/usr/bin/lpq', '-a'], Lang.bind(this, function(out2) {

Lang.bind() is deprecated. Use arrow functions (() => {}) or Function.prototype.bind() instead.


Automated pattern check.

@hans-fritz-pommes
Copy link
Author

Best-practices scanner

This is a regex-based check for API usage that can pose security, performance or maintainability issues, or that may already be provided by Cinnamon. Having code flagged by it doesn't automatically disqualify a pull request.

This check is not perfect will not replace a normal review.

Found 1 potential issue(s):

⚠️ lang_bind

files/usr/share/cinnamon/applets/printers@cinnamon.org/applet.js:218

Util.spawn_async(['/usr/bin/lpq', '-a'], Lang.bind(this, function(out2) {

Lang.bind() is deprecated. Use arrow functions (() => {}) or Function.prototype.bind() instead.

Automated pattern check.

What should be done with that?

@leigh123linux
Copy link
Member

Please squash the commits into one.

@mtwebster
Copy link
Member

mtwebster commented Mar 5, 2026

What should be done with that?

What it suggests - use an arrow function instead of using Lang.bind(). Look at other applets, it's a pretty straightforward change.

removed deprecated lang.bind
@hans-fritz-pommes
Copy link
Author

By the way:
I was wondering why ever lpstat was used for gathering the job-data.
This pull request removed lpq. I thought every system having lpstat also has lpq since it's a part of cups?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants