def METHOD_NAME(self, *, gui_dir: Path, icon_path: Optional[str] = None) -> None:
    """Write the desktop file.
    :param gui_dir: The desktop file destination directory.
    :param icon_path: The icon corresponding to this desktop file.
    """
    self._parse_and_reformat(icon_path=icon_path)
    gui_dir.mkdir(parents=True, exist_ok=True)
    # Rename the desktop file to match the app name. This will help
    # unity8 associate them (https://launchpad.net/bugs/1659330).
    target = gui_dir / f"{self._app_name}.desktop"
    if target.exists():
        # Unlikely. A desktop file in meta/gui/ already existed for
        # this app. Let's pretend it wasn't there and overwrite it.
        target.unlink()
    with target.open("w", encoding="utf-8") as target_file:
        self._parser.METHOD_NAME(target_file, space_around_delimiters=False)