Skip to content

Commit 0a755ab

Browse files
authored
AlbumArt3.0 v2.3.6: Updates the to_string() function (#1677)
1 parent 3dc3350 commit 0a755ab

File tree

4 files changed

+67
-49
lines changed

4 files changed

+67
-49
lines changed

AlbumArt3.0@claudiux/files/AlbumArt3.0@claudiux/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### v2.3.6~20251122
2+
* Updates the to_string() function.
3+
14
### v2.3.4~20251107
25
* Fixes error loading image.
36

AlbumArt3.0@claudiux/files/AlbumArt3.0@claudiux/desklet.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ const { timeout_add_seconds,
2525
const { to_string } = require("./lib/to-string");
2626

2727

28-
const DESKLET_UUID = "AlbumArt3.0@claudiux";
28+
const UUID = "AlbumArt3.0@claudiux";
2929
const HOME_DIR = GLib.get_home_dir();
30-
const DESKLET_DIR = HOME_DIR + "/.local/share/cinnamon/desklets/" + DESKLET_UUID;
30+
const DESKLET_DIR = HOME_DIR + "/.local/share/cinnamon/desklets/" + UUID;
3131
const ENABLED_DESKLETS_KEY = 'enabled-desklets';
3232
const XDG_RUNTIME_DIR = GLib.getenv("XDG_RUNTIME_DIR");
3333
const TMP_ALBUMART_DIR = XDG_RUNTIME_DIR + "/AlbumArt";
@@ -40,24 +40,25 @@ const DEL_SONG_ARTS_SCRIPT = DESKLET_DIR + "/scripts/del_song_arts.sh";
4040
const GET_IMAGE_SIZE_SCRIPT = DESKLET_DIR + "/scripts/get-image-size.sh";
4141
const INSTALL_TRANSLATIONS_SCRIPT = DESKLET_DIR + "/scripts/install-translations.sh";
4242

43-
44-
Gettext.bindtextdomain(DESKLET_UUID, HOME_DIR + "/.local/share/locale");
45-
//~ Gettext.bindtextdomain("cinnamon", "/usr/share/locale");
46-
43+
/**
44+
* _:
45+
* @str: string to try to translate.
46+
* Try firstly with UUID domain, secondly with "cinnamon" domain, then with general domain.
47+
*/
48+
Gettext.bindtextdomain(UUID, HOME_DIR + "/.local/share/locale");
49+
Gettext.bindtextdomain("cinnamon", "/usr/share/locale");
4750
function _(str) {
48-
let customTrans = Gettext.dgettext(DESKLET_UUID, str);
49-
if (customTrans != str && customTrans.length > 0)
51+
let customTrans = Gettext.dgettext(UUID, str);
52+
if (customTrans.length > 0 && customTrans !== str)
5053
return customTrans;
51-
52-
return str;
53-
//~ customTrans = Gettext.dgettext("cinnamon", str);
54-
//~ if (customTrans !== str && customTrans.length > 0)
55-
//~ return customTrans;
56-
57-
//~ return Gettext.gettext(str);
54+
customTrans = Gettext.dgettext("cinnamon", str);
55+
if (customTrans.length > 0 && customTrans !== str)
56+
return customTrans;
57+
return Gettext.gettext(str);
5858
}
5959

6060

61+
6162
class AlbumArtRadio30 extends Desklet.Desklet {
6263
constructor(metadata, desklet_id) {
6364
super(metadata, desklet_id);
@@ -89,7 +90,7 @@ class AlbumArtRadio30 extends Desklet.Desklet {
8990

9091
this._updateDecoration();
9192

92-
this.settings = new Settings.DeskletSettings(this, DESKLET_UUID, this.instance_id);
93+
this.settings = new Settings.DeskletSettings(this, UUID, this.instance_id);
9394
this.settings.bind('height', 'height', this.on_setting_changed);
9495
this.settings.bind('width', 'width', this.on_setting_changed);
9596
this.settings.bind('fade-delay', 'fade_delay', this.on_setting_changed);
@@ -116,7 +117,7 @@ class AlbumArtRadio30 extends Desklet.Desklet {
116117
var modify_ENABLED_DESKLETS_KEY = false;
117118
for (let i = 0; i < enabledDesklets.length; i++) {
118119
let [name, dId, x, y] = enabledDesklets[i].split(":");
119-
if (name == DESKLET_UUID) {
120+
if (name == UUID) {
120121
if (Math.ceil(x) != Math.ceil(this.desklet_x)) {
121122
modify_ENABLED_DESKLETS_KEY = true;
122123
x = "" + this.desklet_x;
@@ -205,7 +206,7 @@ class AlbumArtRadio30 extends Desklet.Desklet {
205206
var enabledDesklets = global.settings.get_strv(ENABLED_DESKLETS_KEY);
206207
for (let i = 0; i < enabledDesklets.length; i++) {
207208
let [name, dId, x, y] = enabledDesklets[i].split(":");
208-
if (name == DESKLET_UUID) {
209+
if (name == UUID) {
209210
this.desklet_x = Math.ceil(x);
210211
this.desklet_y = Math.ceil(y);
211212
break
@@ -279,7 +280,7 @@ class AlbumArtRadio30 extends Desklet.Desklet {
279280
var enabledDesklets = global.settings.get_strv(ENABLED_DESKLETS_KEY);
280281
for (let i = 0; i < enabledDesklets.length; i++) {
281282
let [name, dId, x, y] = enabledDesklets[i].split(":");
282-
if (name == DESKLET_UUID) {
283+
if (name == UUID) {
283284
if (Math.ceil(x) != Math.ceil(this.desklet_x) || Math.ceil(y) != Math.ceil(this.desklet_y)) {
284285
this.desklet_x = Math.ceil(x);
285286
this.desklet_y = Math.ceil(y);
Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,48 @@
1+
const ByteArray = imports.byteArray;
2+
13
const to_string = function(data) {
2-
return ""+stringFromUTF8Array(data);
4+
if (ByteArray.hasOwnProperty("toString")) {
5+
return ""+ByteArray.toString(data);
6+
} else {
7+
return ""+data.toString();
8+
}
39
}
410

5-
const stringFromUTF8Array = function(data) {
6-
const extraByteMap = [ 1, 1, 1, 1, 2, 2, 3, 0 ];
7-
var count = data.length;
8-
var str = "";
9-
10-
for (var index = 0;index < count;)
11-
{
12-
var ch = data[index++];
13-
if (ch & 0x80)
14-
{
15-
var extra = extraByteMap[(ch >> 3) & 0x07];
16-
if (!(ch & 0x40) || !extra || ((index + extra) > count))
17-
return null;
18-
19-
ch = ch & (0x3F >> extra);
20-
for (;extra > 0;extra -= 1)
21-
{
22-
var chx = data[index++];
23-
if ((chx & 0xC0) != 0x80)
24-
return null;
25-
26-
ch = (ch << 6) | (chx & 0x3F);
27-
}
28-
}
29-
30-
str += String.fromCharCode(ch);
31-
}
11+
//~ const to_string = function(data) {
12+
//~ return stringFromUTF8Array(data);
13+
//~ }
14+
15+
//~ const stringFromUTF8Array = function(data) {
16+
//~ const extraByteMap = [ 1, 1, 1, 1, 2, 2, 3, 0 ];
17+
//~ var count = data.length;
18+
//~ var str = "";
19+
20+
//~ for (var index = 0;index < count;)
21+
//~ {
22+
//~ var ch = data[index++];
23+
//~ if (ch & 0x80)
24+
//~ {
25+
//~ var extra = extraByteMap[(ch >> 3) & 0x07];
26+
//~ if (!(ch & 0x40) || !extra || ((index + extra) > count))
27+
//~ return null;
28+
29+
//~ ch = ch & (0x3F >> extra);
30+
//~ for (;extra > 0;extra -= 1)
31+
//~ {
32+
//~ var chx = data[index++];
33+
//~ if ((chx & 0xC0) != 0x80)
34+
//~ return null;
35+
36+
//~ ch = (ch << 6) | (chx & 0x3F);
37+
//~ }
38+
//~ }
39+
40+
//~ str += String.fromCharCode(ch);
41+
//~ }
42+
43+
//~ return str;
44+
//~ }
3245

33-
return str;
46+
module.exports = {
47+
to_string
3448
}

AlbumArt3.0@claudiux/files/AlbumArt3.0@claudiux/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"name": "Album Art for Radio3.0 and Enhanced Sound applets",
55
"description": "A digital photo frame desklet to display an album art, if available",
66
"prevent-decorations": true,
7-
"version": "2.3.5",
7+
"version": "2.3.6",
88
"author": "claudiux"
99
}

0 commit comments

Comments
 (0)