-
Notifications
You must be signed in to change notification settings - Fork 859
Expand file tree
/
Copy pathtestKeyringPrompt.js
More file actions
100 lines (83 loc) · 3.37 KB
/
testKeyringPrompt.js
File metadata and controls
100 lines (83 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Test helpers for keyring prompt dialog.
// Call from Looking Glass:
//
// imports.ui.testKeyringPrompt.passwordPrompt()
// imports.ui.testKeyringPrompt.passwordPrompt("Save this password in your keyring")
// imports.ui.testKeyringPrompt.passwordPromptNoChoice()
// imports.ui.testKeyringPrompt.confirmPrompt()
// imports.ui.testKeyringPrompt.newPasswordPrompt()
const Gcr = imports.gi.Gcr;
const KeyringPrompt = imports.ui.keyringPrompt;
function passwordPrompt(choiceLabel) {
let dialog = new KeyringPrompt.KeyringDialog();
let prompt = dialog.prompt;
prompt.set_message("Unlock Keyring");
prompt.set_description("Enter password for keyring 'login' to unlock");
prompt.set_choice_label(choiceLabel || "Always unlock this keyring whenever logged in");
prompt.set_continue_label("Unlock");
prompt.set_cancel_label("Cancel");
prompt.password_async(null, (source, result) => {
try {
let password = prompt.password_finish(result);
log(`[testKeyringPrompt] password: ${password}, choice_chosen: ${prompt.choice_chosen}`);
} catch(e) {
log(`[testKeyringPrompt] cancelled: ${e.message}`);
}
});
return dialog;
}
function passwordPromptNoChoice() {
let dialog = new KeyringPrompt.KeyringDialog();
let prompt = dialog.prompt;
prompt.set_message("Unlock Keyring");
prompt.set_description("Enter password for keyring 'login' to unlock");
prompt.set_choice_label("");
prompt.set_continue_label("Unlock");
prompt.set_cancel_label("Cancel");
prompt.password_async(null, (source, result) => {
try {
let password = prompt.password_finish(result);
log(`[testKeyringPrompt] password: ${password}`);
} catch(e) {
log(`[testKeyringPrompt] cancelled: ${e.message}`);
}
});
return dialog;
}
function confirmPrompt(choiceLabel) {
let dialog = new KeyringPrompt.KeyringDialog();
let prompt = dialog.prompt;
prompt.set_message("Trust This Key");
prompt.set_description("Do you want to mark this key as trusted?");
prompt.set_choice_label(choiceLabel || "Always trust this key");
prompt.set_continue_label("Trust");
prompt.set_cancel_label("Cancel");
prompt.confirm_async(null, (source, result) => {
try {
let reply = prompt.confirm_finish(result);
log(`[testKeyringPrompt] confirm reply: ${reply}, choice_chosen: ${prompt.choice_chosen}`);
} catch(e) {
log(`[testKeyringPrompt] cancelled: ${e.message}`);
}
});
return dialog;
}
function newPasswordPrompt(choiceLabel) {
let dialog = new KeyringPrompt.KeyringDialog();
let prompt = dialog.prompt;
prompt.set_message("Change Keyring Password");
prompt.set_description("Enter a new password for the 'login' keyring");
prompt.set_password_new(true);
prompt.set_choice_label(choiceLabel || "Always unlock this keyring whenever logged in");
prompt.set_continue_label("Continue");
prompt.set_cancel_label("Cancel");
prompt.password_async(null, (source, result) => {
try {
let password = prompt.password_finish(result);
log(`[testKeyringPrompt] new password: ${password}, choice_chosen: ${prompt.choice_chosen}`);
} catch(e) {
log(`[testKeyringPrompt] cancelled: ${e.message}`);
}
});
return dialog;
}