Skip to content

Commit e2eaaa8

Browse files
committed
make desktop file application name configurable
1 parent 8a25e20 commit e2eaaa8

File tree

7 files changed

+32
-6
lines changed

7 files changed

+32
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 2.1
2+
- `config.toml` supports `application_name` for generated XDG desktop files
3+
- defaults to `{profile_name} (qutebrowser profile)`, you may want just `{profile_name}`
4+
- `qbpm desktop` can be used to replace existing desktop files
5+
16
# 2.0
27
## config
38
qbpm now reads configuration options from `$XDG_CONFIG_HOME/qbpm/config.toml`!

src/qbpm/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Config:
2020
qutebrowser_config_directory: Path | None = None
2121
profile_directory: Path = field(default_factory=paths.default_profile_dir)
2222
generate_desktop_file: bool = platform.system() == "Linux"
23+
application_name: str = "{profile_name} (qutebrowser profile)"
2324
desktop_file_directory: Path = field(
2425
default_factory=paths.default_qbpm_application_dir
2526
)

src/qbpm/config.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@ config.load_autoconfig()
1717
# location of the qutebrowser config to inherit from
1818
# qutebrowser_config_directory = "~/.config/qutebrowser"
1919

20-
# when creating a profile also generate an XDG desktop entry that launches the profile
20+
# when creating a profile also generate an XDG desktop file that launches the profile
2121
# defaults to true on linux
2222
# generate_desktop_file = false
2323
# desktop_file_directory = "~/.local/share/applications/qbpm"
2424

25+
# application name in XDG desktop file (replace existing with `qbpm desktop PROFILE_NAME`)
26+
# supported placeholders: {profile_name}
27+
# application_name = "{profile_name} (qutebrowser profile)"
28+
2529
# profile selection menu for `qbpm choose`
2630
# when not set, qbpm will try to find a menu program on your $PATH
2731
# run `qbpm choose --help` for a list of known menu programs

src/qbpm/desktop.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
]
1919

2020

21-
def create_desktop_file(profile: Profile, application_dir: Path) -> None:
21+
def create_desktop_file(
22+
profile: Profile, application_dir: Path, application_name: str
23+
) -> None:
24+
application_name = application_name.format(profile_name=profile.name)
2225
text = textwrap.dedent(f"""\
2326
[Desktop Entry]
24-
Name={profile.name} (qutebrowser profile)
27+
Name={application_name}
2528
StartupWMClass=qutebrowser
2629
GenericName={profile.name}
2730
Icon=qutebrowser

src/qbpm/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,9 @@ def desktop(
284284
profile = Profile(profile_name, config.profile_directory)
285285
exists = profiles.check(profile)
286286
if exists:
287-
create_desktop_file(profile, config.desktop_file_directory)
287+
create_desktop_file(
288+
profile, config.desktop_file_directory, config.application_name
289+
)
288290
exit_with(exists)
289291

290292

src/qbpm/profiles.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ def new_profile(
123123
if config.symlink_autoconfig:
124124
link_autoconfig(profile, qb_config_dir, overwrite)
125125
if config.generate_desktop_file:
126-
create_desktop_file(profile, config.desktop_file_directory)
126+
create_desktop_file(
127+
profile, config.desktop_file_directory, config.application_name
128+
)
127129
print(profile.root)
128130
return True
129131
return False

tests/test_desktop.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pathlib import Path
22

33
from qbpm import Profile
4+
from qbpm.config import Config
45
from qbpm.desktop import create_desktop_file
56

67
TEST_DIR = Path(__file__).resolve().parent
@@ -10,7 +11,15 @@ def test_create_desktop_file(tmp_path: Path):
1011
application_path = tmp_path / "applications"
1112
application_path.mkdir()
1213
profile = Profile("test", tmp_path)
13-
create_desktop_file(profile, application_path)
14+
create_desktop_file(profile, application_path, Config.load(None).application_name)
1415
assert (application_path / "test.desktop").read_text() == (
1516
TEST_DIR / "test.desktop"
1617
).read_text().replace("{qbpm}", " ".join(profile.cmdline()))
18+
19+
20+
def test_custom_name(tmp_path: Path):
21+
application_path = tmp_path / "applications"
22+
application_path.mkdir()
23+
profile = Profile("test", tmp_path)
24+
create_desktop_file(profile, application_path, "test")
25+
assert "Name=test\n" in (application_path / "test.desktop").read_text()

0 commit comments

Comments
 (0)