Skip to content

Commit

Permalink
Added desktop detection support
Browse files Browse the repository at this point in the history
  • Loading branch information
fquinner committed Dec 12, 2020
1 parent 90846be commit 76b1f1e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ The script expects to be run **within** the WSL execution environment with:
* An **X11 Server** running on your **windows host** (e.g. X410, Xming etc). This server
must be *reachable* from your WSL env (test with something like `wsl.exe -- source ~/.bashrc ; xterm"`).
If this fails, check your `DISPLAY` variable (more details in [troubleshooting](#troubleshooting)).
* A desktop environment which has a freedesktop menu installed (e.g. gnome / xfce).
* A freedesktop menu installed (e.g. gnome-menus or a full desktop environment).

And optionally (but recommended):

* An installation of cairosvg if works on your distro (`pip install cairosvg`)
* Imagemagick installed (`sudo apt install imagemagick` / `dnf install imagemagick` etc)
* An installation of cairosvg if works on your distro (`pip install cairosvg`). This will allow you to convert `.svg`
based icons.
* Imagemagick installed (`sudo apt install imagemagick` / `dnf install imagemagick` etc). This will allow you to have
an additional opportunity to convert appropriate icon files if other methods fail.

## Installing and Running

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

setuptools.setup(
name="wsl-windows-toolbar",
version="0.6.0",
version="0.6.1",
author="Frank Quinn",
author_email="[email protected]",
description="Adds linux GUI application menu to a windows toolbar",
Expand Down
32 changes: 30 additions & 2 deletions wsl_windows_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shutil
import subprocess
import sys
import glob
import magic
from platform import uname
import click
Expand Down Expand Up @@ -60,6 +61,26 @@
DEFAULT_METADATA_DIRECTORY = os.path.join(
WSL_USERPROFILE, ".config", "wsl-windows-toolbar-launcher/metadata")

# Default order of preference for menu selection
MENU_PREFERENCES = ["gnome", "xfce", "kf5"]
DEFAULT_MENU_LOCATION = "/etc/xdg/menus"
MENUS_AVAILABLE = glob.glob("%s/*-applications.menu" % DEFAULT_MENU_LOCATION)
DEFAULT_MENU_FILE = None

# Prefer these as defaults if available
for menu_type in MENU_PREFERENCES:
menu_file_name = "/etc/xdg/menus/%s-applications.menu" % menu_type
if menu_file_name in MENUS_AVAILABLE:
DEFAULT_MENU_FILE = menu_file_name
break

# Otherwise prefer the first one available
if DEFAULT_MENU_FILE is None and len(MENUS_AVAILABLE) > 0:
DEFAULT_MENU_FILE = MENUS_AVAILABLE[0]

DEFAULT_METADATA_DIRECTORY = os.path.join(
WSL_USERPROFILE, ".config", "wsl-windows-toolbar-launcher/metadata")

FREEDESKTOP_FIELD_CODES = [
"%f",
"%F",
Expand Down Expand Up @@ -129,7 +150,7 @@
@click.option("--menu-file",
"-f",
type=click.File('r'),
default="/etc/xdg/menus/gnome-applications.menu",
default=DEFAULT_MENU_FILE,
show_default=True,
help="The *.menu menu file to parse")
@click.option("--wsl-executable",
Expand Down Expand Up @@ -218,7 +239,7 @@ def cli(install_directory,
logger.info("distribution = %s", distribution)
logger.info("user = %s", user)
logger.info("confirm_yes = %s", confirm_yes)
logger.info("menu_file = %s", menu_file.name)
logger.info("menu_file = %s", menu_file.name if menu_file else None)
logger.info("wsl_executable = %s", wsl_executable)
logger.info("target_name = %s", target_name)
logger.info("preferred_theme = %s", preferred_theme)
Expand All @@ -240,6 +261,13 @@ def cli(install_directory,
logger.info("install_directory = %s", install_directory)
logger.info("metadata_directory = %s", metadata_directory)

if not menu_file:
logger.error(
"Could not find an appropriate .menu file in %s - perhaps yum/apt install gnome-menus or another desktop?",
DEFAULT_MENU_LOCATION
)
sys.exit(os.EX_OSFILE)

if not confirm_yes:
logger.info("For full list of options available, call script again with --help")
logger.info("This script will write to the above locations if it can, but giving final chance to chicken out.")
Expand Down

0 comments on commit 76b1f1e

Please sign in to comment.