Skip to content

Commit

Permalink
Merge pull request #4 from aaronfranke/fix-locale-nofail-symlink
Browse files Browse the repository at this point in the history
Fix empty locales and don't fail on symlinked desktop entries
  • Loading branch information
heliguy4599 authored Dec 21, 2024
2 parents 3818c75 + 2f5606d commit 2c316ca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/app_chooser_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const AppChooserPage = GObject.registerClass({
let total_rows = 0;
let dir_with_enumerator = dirs_with_enumerators[index];
const iteration = () => {
const path = dir_with_enumerator.path;
const folder_path = dir_with_enumerator.path;
const enumerator = dir_with_enumerator.enumerator;
const info = enumerator.next_file(null);
if (info === null) {
Expand All @@ -85,13 +85,17 @@ export const AppChooserPage = GObject.registerClass({
// Skip this iteration if the file is not a .desktop file
return true;
}
const entry = new AutostartEntry(`${path}/${info.get_name()}`);
const file_path = `${folder_path}/${info.get_name()}`;
let entry;
try {
entry = new AutostartEntry(file_path);
} catch (error) {
print("Ignition error: AppChooserPage: Error creating AutostartEntry: " + error);
return true;
}
const kf = new GLib.KeyFile();
try {
kf.load_from_file(
`${path}/${info.get_name()}`,
GLib.KeyFileFlags.KEEP_TRANSLATIONS,
);
kf.load_from_file(file_path, GLib.KeyFileFlags.KEEP_TRANSLATIONS);
} catch (error) { return true; }
const hidden = (
KeyFileUtils.get_boolean_safe(kf, "Desktop Entry", "Hidden", false)
Expand Down
14 changes: 10 additions & 4 deletions src/autostart_entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ export class AutostartEntry {
}

set name(value) {
this.keyfile.set_locale_string("Desktop Entry", "Name", this.locale, value);
this.keyfile.set_string("Desktop Entry", "Name", value);
if (this.locale !== null) {
this.keyfile.set_locale_string("Desktop Entry", "Name", this.locale, value);
}
}

set comment(value) {
this.keyfile.set_locale_string("Desktop Entry", "Comment", this.locale, value);
this.keyfile.set_string("Desktop Entry", "Comment", value);
if (this.locale !== null) {
this.keyfile.set_locale_string("Desktop Entry", "Comment", this.locale, value);
}
}

set exec(value) {
Expand Down Expand Up @@ -82,7 +88,7 @@ export class AutostartEntry {

path;
keyfile = new GLib.KeyFile({});
locale = "en_US";
locale = null;
signals = {
file_saved: new Signal(),
file_save_failed: new Signal(),
Expand All @@ -103,7 +109,7 @@ export class AutostartEntry {
throw new Error("Desktop Entry is not of type Application");
}
try {
this.locale = this.keyfile.get_locale_for_key("Desktop Entry", "Name", null) || "en_US";
this.locale = this.keyfile.get_locale_for_key("Desktop Entry", "Name", null);
} catch (error) {
// Not having a name set is fine
}
Expand Down

0 comments on commit 2c316ca

Please sign in to comment.