#!/bin/sh
#
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

set -e

action="$1"
if [ "$2" = "in-favour" ]; then
  # Treat conflict remove as an upgrade.
  action="upgrade"
fi
# Don't clean-up just for an upgrade.`
if [ "$action" = "upgrade" ] ; then
  exit 0
fi

# Remove icons from the system icons
XDG_ICON_RESOURCE="`which xdg-icon-resource 2> /dev/null || true`"
if [ ! -x "$XDG_ICON_RESOURCE" ]; then
  echo "Error: Could not find xdg-icon-resource" >&2
  exit 1
fi
# GWD Modification
#   Added /resources/ below as the GWD icons are located in a subdirectory
#   next to the main executable. Also, removed the .png extension from the
#   filename to extract the size.
for icon in "/opt/google/webdesigner/resources/product_logo_"*.png; do
  size="$(echo ${icon} | sed 's/[^0-9]//g')"
  "$XDG_ICON_RESOURCE" uninstall --size "${size}" "google-webdesigner"
done

UPDATE_MENUS="`which update-menus 2> /dev/null || true`"
if [ -x "$UPDATE_MENUS" ]; then
  update-menus
fi

# Update cache of .desktop file MIME types. Non-fatal since it's just a cache.
update-desktop-database > /dev/null 2>&1 || true

# Remove from the alternatives system
# GWD Modification
#   Removed the update-alternatives call as GWD is not an alternative app that
#   the OS needs to be aware of.
# update-alternatives --remove x-www-browser /usr/bin/google-webdesigner
# update-alternatives --remove gnome-www-browser /usr/bin/google-webdesigner

# update-alternatives --remove  /usr/bin/google-webdesigner
