const Lang = imports.lang;

const St = imports.gi.St;
const Gio = imports.gi.Gio;

const Main = imports.ui.main;
const MessageTray = imports.ui.messageTray;

const Gettext = imports.gettext.domain('gnome-shell-extensions');
const _ = Gettext.gettext;

const ExtensionUtils = imports.misc.extensionUtils;
const Local = ExtensionUtils.getCurrentExtension();

const NotificationIcon = 'imgur-uploader-color';
const NotificationSourceName = 'ImgurUploader';




const NotificationService = new Lang.Class({
  Name: "ImgurUploader.NotificationService",

  _init: function () {
    this._notificationSource = new MessageTray.Source(
      NotificationSourceName, NotificationIcon
    );
    this._notifications = [];
  },

  make: function () {
    let n = new MessageTray.Notification(
        this._notificationSource, _("Upload")
    );

    Main.messageTray.add(this._notificationSource);
    this._notificationSource.notify(n);
    return n;
  },

  setProgress: function (notification, bytes, total) {
    notification.update(
        _("Upload"),
        '' + Math.floor(100 * (bytes / total)) + '%'
    );

    // this._notificationSource.notify(notification);
  },

  setFinished: function (notification, url) {
    notification.setResident(true);

    notification.update(_("Upload Complete"), url);
    notification.addButton('copy', _("Copy Link"));

    notification.connect('action-invoked', function (n, action) {
      if (action === 'copy') {
        St.Clipboard.get_default().set_text(St.ClipboardType.PRIMARY, url);
        St.Clipboard.get_default().set_text(St.ClipboardType.CLIPBOARD, url);
      }
    });

    this._notificationSource.notify(notification);
  },

  setError: function (notification, error) {
    notification.setResident(true);

    notification.update(
        _("Error"),
        error,
        { secondaryGIcon: new Gio.ThemedIcon({name: 'dialog-error'}) }
    );

    this._notificationSource.notify(notification);
  }
});


@@ -449,16 +449,83 @@
 der';%0A%0A%0A
+%0Aconst Version312 = Convenience.currentVersionGreaterEqual(%223.12%22);
 %0A%0Aconst 
@@ -1368,154 +1368,86 @@
 l);%0A
+%0A
     
-notification.addButton('copy', _(%22Copy Link%22));%0A%0A    notification.connect('action-invoked', function (n, action) %7B%0A      if (action === 'copy'
+if (Version312) %7B%0A      notification.addAction(_(%22Copy Link%22), function (
 ) %7B%0A
@@ -1611,16 +1611,362 @@
    %7D
+);%0A    %7D else %7B%0A      notification.addButton('copy', _(%22Copy Link%22));%0A      notification.connect('action-invoked', function (n, action) %7B%0A        if (action === 'copy') %7B%0A          St.Clipboard.get_default().set_text(St.ClipboardType.PRIMARY, url);%0A          St.Clipboard.get_default().set_text(St.ClipboardType.CLIPBOARD, url);%0A        %7D%0A      %7D);
 %0A    %7D
-);
 %0A%0A  

fix bug where button isn't added in Gnome3.12