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

Fix: Parsing errors when strings contains quotation marks #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 19 additions & 19 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ const SpotifyLabel = new Lang.Class({
// Update padding of this.buttonText according to new value set in settings
_leftPaddingChanged: function() {
this.buttonText.set_style("padding-left: " + this.settings.get_int('left-padding') + "px; "
+ "padding-right: " + this.settings.get_int('right-padding') + "px; ");
+ "padding-right: " + this.settings.get_int('right-padding') + "px; ");
},
_rightPaddingChanged: function() {
this.buttonText.set_style("padding-left: " + this.settings.get_int('left-padding') + "px; "
+ "padding-right: " + this.settings.get_int('right-padding') + "px; ");
+ "padding-right: " + this.settings.get_int('right-padding') + "px; ");
},

// Update labelEventListener if toggle mode changes
Expand Down Expand Up @@ -140,14 +140,14 @@ function enable() {

// Load schema
gschema = Gio.SettingsSchemaSource.new_from_directory(
Me.dir.get_child('schemas').get_path(),
Gio.SettingsSchemaSource.get_default(),
false
);
Me.dir.get_child('schemas').get_path(),
Gio.SettingsSchemaSource.get_default(),
false
);

// Load settings
settings = new Gio.Settings({
settings_schema: gschema.lookup('org.gnome.shell.extensions.spotifylabel', true)
settings = new Gio.Settings({
settings_schema: gschema.lookup('org.gnome.shell.extensions.spotifylabel', true)
});

// Mandatory for removing the spMenu from the correct location
Expand Down Expand Up @@ -222,11 +222,16 @@ function parseSpotifyData(data) {
if(!data)
return createGreeting()

var re = RegExp('string \".*(?=\"\n)');

var titleBlock = data.substring(data.indexOf("xesam:title"));
var title = titleBlock.split("\"")[2]
var title = titleBlock.match(re)[0].substring(8);

var artistBlock = data.substring(data.indexOf("xesam:artist"));
var artist = artistBlock.split("\"")[2]
var artist = artistBlock.match(re)[0].substring(8);

if (title.includes("xesam") || artist.includes("xesam"))
return "Loading..."

//If the delimited '-' is in the title, we assume that it's remix, and encapsulate the end in brackets.
if(title.includes("-"))
Expand All @@ -239,13 +244,10 @@ function parseSpotifyData(data) {
if (title.length > this.settings.get_int('max-string-length'))
title = title.substring(0, this.settings.get_int('max-string-length')) + "...";

if (title.includes("xesam") || artist.includes("xesam"))
return "Loading..."

if (this.settings.get_boolean('artist-first')) {
return (artist + " - " + title);
}
return (title + " - " + artist);
return (artist + " - " + title);
}
return (title + " - " + artist);
}

function toggleWindow() {
Expand Down Expand Up @@ -315,6 +317,4 @@ function createGreeting() {

else
return "Can " + currentGenre + " be considered a lullaby? Sure!"


}
}