Password input field for a Gnome shell extension
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

This bounty is for Gnome JavaScript code that allows a user to enter a password in a dialog box, and then returns the password to a Gnome shell extension.

Exact specifications:

The dialog should be opened programmatically from within a Gnome shell extension - it is not expected that you write an entire extension - an example how to launch the dialog from an extension will suffice.

The password dialog should be themed similarly to other Gnome shell input dialogs (e.g. the WiFi authentication dialog), and should have these following elements:
- a title in bold font
- a descriptive string in normal font
- an input field where strings are hidden with ***
- a Cancel and Connect button

The dialog should return the typed password when Connect is pressed. If Cancel is pressed, no password is returned.

Gnome shell documentation is sparse. For some helpful generic info, see:

http://codeisland.org/2013/making-gnome-shell-extensions/
http://mathematicalcoffee.blogspot.com.es/2012/09/gnome-shell-javascript-source.html

awarded to feroldi

Crowdsource coding tasks.

1 Solution


Code: gist

  • a title in bold font;
  • a descriptive string in normal font;
  • an input field where strings are hidden with ***;
  • a Cancel and Connect button;

    • The dialog should return the typed password when Connect is pressed. If Cancel is pressed, no password is returned;

EDIT: I remade it the way it was intended.

Code: gist

To open the dialog, just do this:

let diag = new PasswordDialog();
diag.open(global.get_current_time());

When you connect, the password will be stored in object._password, and you can call .get_password() to get it.

From the command line, I get these errors: `(gjs:18532): Gtk-WARNING **: Attempting to add a widget with type GtkEntry to a GtkApplicationWindow, but as a GtkBin subclass a GtkApplicationWindow can only contain one widget at a time; it already contains a widget of type GtkLabel (gjs:18532): Gtk-WARNING **: Attempting to add a widget with type GtkButton to a GtkApplicationWindow, but as a GtkBin subclass a GtkApplicationWindow can only contain one widget at a time; it already contains a widget of type GtkLabel (gjs:18532): Gtk-WARNING **: Attempting to add a widget with type GtkButton to a GtkApplicationWindow, but as a GtkBin subclass a GtkApplicationWindow can only contain one widget at a time; it already contains a widget of type GtkLabel`
greipes over 3 years ago
Also, it fails when running from an actual Gnome extension.
greipes over 3 years ago
And, it is not themed.
greipes over 3 years ago
Oh, I'll fix it. Sorry.
feroldi over 3 years ago
Can you show me the error you get running it from a gnome extension? I just updated the code (and I'll check the theme thing).
feroldi over 3 years ago
I still have issues running it with gjs. There are commas missing on lines 96 and 101. When fixed, gjs throws these warnings/errors: % gjs password.js Gjs-Message: JS WARNING: [password.js 45]: assignment to undeclared variable MainWindow (gjs:25120): Gtk-WARNING **: Attempting to add a widget with type GtkEntry to a GtkWindow, but as a GtkBin subclass a GtkWindow can only contain one widget at a time; it already contains a widget of type GtkLabel (gjs:25120): Gtk-WARNING **: Attempting to add a widget with type GtkButton to a GtkWindow, but as a GtkBin subclass a GtkWindow can only contain one widget at a time; it already contains a widget of type GtkLabel
greipes over 3 years ago
gjs errors continued: (gjs:25120): Gjs-WARNING **: JS ERROR: ReferenceError: MyWindow is not defined Password<.buildUI@password.js:73 wrapper@resource:///org/gnome/gjs/modules/lang.js:169 Password<.onStartup@password.js:29 wrapper@resource:///org/gnome/gjs/modules/lang.js:169 @password.js:131 (gjs:25120): Gjs-WARNING **: JS ERROR: TypeError: this.window is undefined Password<.onActivate@password.js:24 wrapper@resource:///org/gnome/gjs/modules/lang.js:169 @password.js:131
greipes over 3 years ago
How do you want the password to be shown/returned?
feroldi over 3 years ago
It should ideally not be shown as it is typed. It should be returned as a string back to the extension/gjs code when the dialog is closed by clicking connect.
greipes over 3 years ago