Skip to content

Commit c537d71

Browse files
committed
Convert to local variables initialized when prompt is displayed on main thread.
1 parent 7fd0771 commit c537d71

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

osx/src/main/java/ch/cyberduck/ui/cocoa/callback/PromptPasswordCallback.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
*/
1717

1818
import ch.cyberduck.binding.ProxyController;
19-
import ch.cyberduck.binding.application.NSControl;
2019
import ch.cyberduck.binding.application.SheetCallback;
21-
import ch.cyberduck.binding.foundation.NSNotification;
2220
import ch.cyberduck.core.Credentials;
2321
import ch.cyberduck.core.Host;
2422
import ch.cyberduck.core.LoginOptions;
@@ -43,7 +41,6 @@ public void close(final String input) {
4341
return;
4442
}
4543
alert.setPasswordFieldText(input);
46-
alert.passwordFieldTextDidChange(NSNotification.notificationWithName(NSControl.NSControlTextDidChangeNotification, input));
4744
alert.closeSheetWithOption(SheetCallback.ALTERNATE_OPTION);
4845
}
4946

osx/src/main/java/ch/cyberduck/ui/cocoa/controller/LoginController.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,14 @@ public class LoginController extends AlertController {
6161
private final LoginOptions options;
6262

6363
@Outlet
64-
private final NSTextField usernameField = NSTextField.textFieldWithString(StringUtils.EMPTY);
64+
private NSTextField usernameField = NSTextField.textFieldWithString(StringUtils.EMPTY);
6565
@Outlet
66-
private final NSTextField passwordField = NSSecureTextField.textFieldWithString(StringUtils.EMPTY);
66+
private NSTextField passwordField = NSSecureTextField.textFieldWithString(StringUtils.EMPTY);
6767
@Outlet
68-
private final NSPopUpButton privateKeyPopup = NSPopUpButton.buttonPullsDown(false);
68+
private NSPopUpButton privateKeyPopup = NSPopUpButton.buttonPullsDown(false);
6969
@Outlet
7070
private NSOpenPanel privateKeyOpenPanel;
7171

72-
7372
public LoginController(final Host bookmark, final String title, final String reason, final LoginOptions options) {
7473
super(new LoginInputValidator(bookmark, options));
7574
this.bookmark = bookmark;
@@ -102,6 +101,7 @@ public NSAlert loadAlert() {
102101
public NSView getAccessoryView(final NSAlert alert) {
103102
final NSView accessoryView = NSView.create();
104103
if(options.publickey) {
104+
privateKeyPopup = NSPopUpButton.buttonPullsDown(false);
105105
privateKeyPopup.setTarget(this.id());
106106
privateKeyPopup.setAction(Foundation.selector("privateKeyPopupClicked:"));
107107
privateKeyPopup.removeAllItems();
@@ -130,6 +130,7 @@ public NSView getAccessoryView(final NSAlert alert) {
130130
this.addAccessorySubview(accessoryView, privateKeyPopup);
131131
}
132132
if(options.password) {
133+
passwordField = NSSecureTextField.textFieldWithString(StringUtils.EMPTY);
133134
this.updateField(passwordField, bookmark.getCredentials().getPassword());
134135
passwordField.cell().setPlaceholderString(options.getPasswordPlaceholder());
135136
NSNotificationCenter.defaultCenter().addObserver(this.id(),
@@ -139,6 +140,7 @@ public NSView getAccessoryView(final NSAlert alert) {
139140
this.addAccessorySubview(accessoryView, passwordField);
140141
}
141142
if(options.user) {
143+
usernameField = NSTextField.textFieldWithString(StringUtils.EMPTY);
142144
this.updateField(usernameField, bookmark.getCredentials().getUsername());
143145
usernameField.cell().setPlaceholderString(options.getUsernamePlaceholder());
144146
NSNotificationCenter.defaultCenter().addObserver(this.id(),

osx/src/main/java/ch/cyberduck/ui/cocoa/controller/PasswordController.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@
4141

4242
import org.apache.commons.lang3.StringUtils;
4343
import org.rococoa.Foundation;
44+
import org.rococoa.Rococoa;
4445

4546
public class PasswordController extends AlertController {
4647

4748
@Outlet
48-
private final NSTextField inputField;
49+
private NSTextField inputField;
4950

5051
private final Host bookmark;
5152
private final Credentials credentials;
@@ -59,12 +60,6 @@ public PasswordController(final Host bookmark, final Credentials credentials, fi
5960
this.title = title;
6061
this.reason = reason;
6162
this.options = options;
62-
if(options.password) {
63-
this.inputField = NSSecureTextField.textFieldWithString(StringUtils.EMPTY);
64-
}
65-
else {
66-
this.inputField = NSTextField.textFieldWithString(StringUtils.EMPTY);
67-
}
6863
}
6964

7065
@Override
@@ -106,6 +101,12 @@ public void passwordFieldTextDidChange(final NSNotification notification) {
106101

107102
@Override
108103
public NSView getAccessoryView(final NSAlert alert) {
104+
if(options.password) {
105+
inputField = NSSecureTextField.textFieldWithString(StringUtils.EMPTY);
106+
}
107+
else {
108+
inputField = NSTextField.textFieldWithString(StringUtils.EMPTY);
109+
}
109110
final NSView accessoryView = NSView.create();
110111
inputField.cell().setPlaceholderString(options.getPasswordPlaceholder());
111112
NSNotificationCenter.defaultCenter().addObserver(this.id(),
@@ -117,7 +118,7 @@ public NSView getAccessoryView(final NSAlert alert) {
117118
}
118119

119120
public void setPasswordFieldText(final String input) {
120-
inputField.setStringValue(input);
121+
credentials.setPassword(input);
121122
}
122123

123124
@Override

osx/src/main/java/ch/cyberduck/ui/cocoa/controller/VaultController.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ public class VaultController extends FolderController {
4646
private final Callback callback;
4747

4848
@Outlet
49-
private final NSSecureTextField passwordField = NSSecureTextField.textFieldWithString(StringUtils.EMPTY);
49+
private NSSecureTextField passwordField;
5050
@Outlet
51-
private final NSSecureTextField confirmField = NSSecureTextField.textFieldWithString(StringUtils.EMPTY);
51+
private NSSecureTextField confirmField;
5252
@Outlet
53-
private final NSLevelIndicator strengthIndicator = NSLevelIndicator.levelIndicatorWithFrame(new NSRect(0, 18));
53+
private NSLevelIndicator strengthIndicator;
5454

5555
private final NSNotificationCenter notificationCenter
5656
= NSNotificationCenter.defaultCenter();
@@ -87,15 +87,17 @@ public void passwordFieldTextDidChange(final NSNotification notification) {
8787

8888
public NSView getAccessoryView(final NSAlert alert) {
8989
final NSView accessoryView = NSView.create();
90+
confirmField = NSSecureTextField.textFieldWithString(StringUtils.EMPTY);
9091
confirmField.cell().setPlaceholderString(LocaleFactory.localizedString("Confirm Passphrase", "Cryptomator"));
9192
this.addAccessorySubview(accessoryView, confirmField);
9293

94+
strengthIndicator = NSLevelIndicator.levelIndicatorWithFrame(new NSRect(0, 18));
9395
strengthIndicator.setTickMarkPosition(1);
9496
if(strengthIndicator.respondsToSelector(Foundation.selector("setLevelIndicatorStyle:"))) {
9597
strengthIndicator.setLevelIndicatorStyle(NSLevelIndicator.NSDiscreteCapacityLevelIndicatorStyle);
9698
}
9799
this.addAccessorySubview(accessoryView, strengthIndicator);
98-
100+
passwordField = NSSecureTextField.textFieldWithString(StringUtils.EMPTY);
99101
passwordField.cell().setPlaceholderString(LocaleFactory.localizedString("Passphrase", "Cryptomator"));
100102
notificationCenter.addObserver(this.id(),
101103
Foundation.selector("passwordFieldTextDidChange:"),

0 commit comments

Comments
 (0)