1
+ use std:: sync:: mpsc:: { self , Receiver } ;
2
+
1
3
// Copyright 2017 astonbitecode
2
4
// This file is part of rust-keylock password manager.
3
5
//
15
17
// along with rust-keylock. If not, see <http://www.gnu.org/licenses/>.
16
18
use j4rs:: { Instance , InvocationArg , Jvm } ;
17
19
use log:: * ;
18
- use rust_keylock:: {
19
- AsyncEditor ,
20
- Menu ,
21
- MessageSeverity ,
22
- RklConfiguration ,
23
- Safe , UserOption ,
24
- UserSelection ,
25
- } ;
26
- use std:: sync:: mpsc:: { self , Receiver } ;
27
- use super :: japi;
20
+
21
+ use rust_keylock:: { AsyncEditor , Entry , EntryPresentationType , Menu , MessageSeverity , UserOption , UserSelection } ;
28
22
use rust_keylock:: dropbox:: DropboxConfiguration ;
23
+ use rust_keylock:: nextcloud:: NextcloudConfiguration ;
24
+
25
+ use super :: japi;
29
26
30
27
pub struct AndroidImpl {
31
28
jvm : Jvm ,
@@ -74,14 +71,8 @@ impl AsyncEditor for AndroidImpl {
74
71
japi:: handle_instance_receiver_result ( instance_receiver)
75
72
}
76
73
77
- fn show_menu ( & self ,
78
- menu : & Menu ,
79
- safe : & Safe ,
80
- configuration : & RklConfiguration )
81
- -> Receiver < UserSelection > {
82
- debug ! ( "Opening menu '{:?}' with entries size {}" ,
83
- menu,
84
- safe. get_entries( ) . len( ) ) ;
74
+ fn show_menu ( & self , menu : & Menu ) -> Receiver < UserSelection > {
75
+ debug ! ( "Opening menu '{:?}'" , menu) ;
85
76
86
77
let instance_receiver_res = match menu {
87
78
& Menu :: Main => {
@@ -90,50 +81,6 @@ impl AsyncEditor for AndroidImpl {
90
81
"apply" ,
91
82
& [ InvocationArg :: from ( "Main" ) ] )
92
83
}
93
- & Menu :: EntriesList ( _) => {
94
- let java_entries: Vec < japi:: JavaEntry > = safe. get_entries ( ) . iter ( )
95
- . map ( |entry| japi:: JavaEntry :: new ( entry) )
96
- . collect ( ) ;
97
- let filter = if safe. get_filter ( ) . is_empty ( ) {
98
- "null" . to_string ( )
99
- } else {
100
- safe. get_filter ( ) . clone ( )
101
- } ;
102
- self . jvm . invoke_to_channel (
103
- & self . show_entries_set_cb ,
104
- "apply" ,
105
- & [
106
- InvocationArg :: from ( (
107
- java_entries. as_slice ( ) ,
108
- "org.astonbitecode.rustkeylock.api.JavaEntry" ,
109
- & self . jvm ) ) ,
110
- InvocationArg :: from ( filter) ] )
111
- }
112
- & Menu :: ShowEntry ( index) => {
113
- let entry = safe. get_entry_decrypted ( index) ;
114
- self . jvm . invoke_to_channel (
115
- & self . show_entry_cb ,
116
- "apply" ,
117
- & [
118
- InvocationArg :: new ( & japi:: JavaEntry :: new ( & entry) , "org.astonbitecode.rustkeylock.api.JavaEntry" ) ,
119
- InvocationArg :: from ( index as i32 ) ,
120
- InvocationArg :: from ( false ) ,
121
- InvocationArg :: from ( false )
122
- ] )
123
- }
124
- & Menu :: DeleteEntry ( index) => {
125
- let entry = japi:: JavaEntry :: new ( safe. get_entry ( index) ) ;
126
-
127
- self . jvm . invoke_to_channel (
128
- & self . show_entry_cb ,
129
- "apply" ,
130
- & [
131
- InvocationArg :: new ( & entry, "org.astonbitecode.rustkeylock.api.JavaEntry" ) ,
132
- InvocationArg :: from ( index as i32 ) ,
133
- InvocationArg :: from ( false ) ,
134
- InvocationArg :: from ( true )
135
- ] )
136
- }
137
84
& Menu :: NewEntry => {
138
85
let empty_entry = japi:: JavaEntry :: empty ( ) ;
139
86
// In order to denote that this is a new entry, put -1 as index
@@ -147,18 +94,6 @@ impl AsyncEditor for AndroidImpl {
147
94
InvocationArg :: from ( false )
148
95
] )
149
96
}
150
- & Menu :: EditEntry ( index) => {
151
- let selected_entry = safe. get_entry_decrypted ( index) ;
152
- self . jvm . invoke_to_channel (
153
- & self . show_entry_cb ,
154
- "apply" ,
155
- & [
156
- InvocationArg :: new ( & japi:: JavaEntry :: new ( & selected_entry) , "org.astonbitecode.rustkeylock.api.JavaEntry" ) ,
157
- InvocationArg :: from ( index as i32 ) ,
158
- InvocationArg :: from ( true ) ,
159
- InvocationArg :: from ( false )
160
- ] )
161
- }
162
97
& Menu :: ExportEntries => {
163
98
self . jvm . invoke_to_channel (
164
99
& self . show_menu_cb ,
@@ -171,20 +106,6 @@ impl AsyncEditor for AndroidImpl {
171
106
"apply" ,
172
107
& [ InvocationArg :: from ( "ImportEntries" ) ] )
173
108
}
174
- & Menu :: ShowConfiguration => {
175
- let conf_strings = vec ! [
176
- configuration. nextcloud. server_url. clone( ) ,
177
- configuration. nextcloud. username. clone( ) ,
178
- configuration. nextcloud. decrypted_password( ) . unwrap( ) ,
179
- configuration. nextcloud. use_self_signed_certificate. to_string( ) ,
180
- DropboxConfiguration :: dropbox_url( ) ,
181
- configuration. dropbox. decrypted_token( ) . unwrap( ) ,
182
- ] ;
183
- self . jvm . invoke_to_channel (
184
- & self . edit_configuration_cb ,
185
- "apply" ,
186
- & [ InvocationArg :: from ( ( conf_strings. as_slice ( ) , & self . jvm ) ) ] )
187
- }
188
109
& Menu :: Current => {
189
110
self . jvm . invoke_to_channel (
190
111
& self . show_menu_cb ,
@@ -201,6 +122,83 @@ impl AsyncEditor for AndroidImpl {
201
122
japi:: handle_instance_receiver_result ( instance_receiver_res)
202
123
}
203
124
125
+ fn show_entries ( & self , entries : Vec < Entry > , filter : String ) -> Receiver < UserSelection > {
126
+ let java_entries: Vec < japi:: JavaEntry > = entries. iter ( )
127
+ . map ( |entry| japi:: JavaEntry :: new ( entry) )
128
+ . collect ( ) ;
129
+ let filter = if filter. is_empty ( ) {
130
+ "null" . to_string ( )
131
+ } else {
132
+ filter
133
+ } ;
134
+
135
+ let instance_receiver_res = self . jvm . invoke_to_channel (
136
+ & self . show_entries_set_cb ,
137
+ "apply" ,
138
+ & [
139
+ InvocationArg :: from ( (
140
+ java_entries. as_slice ( ) ,
141
+ "org.astonbitecode.rustkeylock.api.JavaEntry" ,
142
+ & self . jvm ) ) ,
143
+ InvocationArg :: from ( filter) ] ) ;
144
+ japi:: handle_instance_receiver_result ( instance_receiver_res)
145
+ }
146
+
147
+ fn show_entry ( & self , entry : Entry , index : usize , presentation_type : EntryPresentationType ) -> Receiver < UserSelection > {
148
+ let instance_receiver_res = match presentation_type {
149
+ EntryPresentationType :: View => {
150
+ self . jvm . invoke_to_channel (
151
+ & self . show_entry_cb ,
152
+ "apply" ,
153
+ & [
154
+ InvocationArg :: new ( & japi:: JavaEntry :: new ( & entry) , "org.astonbitecode.rustkeylock.api.JavaEntry" ) ,
155
+ InvocationArg :: from ( index as i32 ) ,
156
+ InvocationArg :: from ( false ) ,
157
+ InvocationArg :: from ( false )
158
+ ] )
159
+ }
160
+ EntryPresentationType :: Delete => {
161
+ self . jvm . invoke_to_channel (
162
+ & self . show_entry_cb ,
163
+ "apply" ,
164
+ & [
165
+ InvocationArg :: new ( & japi:: JavaEntry :: new ( & entry) , "org.astonbitecode.rustkeylock.api.JavaEntry" ) ,
166
+ InvocationArg :: from ( index as i32 ) ,
167
+ InvocationArg :: from ( false ) ,
168
+ InvocationArg :: from ( true )
169
+ ] )
170
+ }
171
+ EntryPresentationType :: Edit => {
172
+ self . jvm . invoke_to_channel (
173
+ & self . show_entry_cb ,
174
+ "apply" ,
175
+ & [
176
+ InvocationArg :: new ( & japi:: JavaEntry :: new ( & entry) , "org.astonbitecode.rustkeylock.api.JavaEntry" ) ,
177
+ InvocationArg :: from ( index as i32 ) ,
178
+ InvocationArg :: from ( true ) ,
179
+ InvocationArg :: from ( false )
180
+ ] )
181
+ }
182
+ } ;
183
+
184
+ japi:: handle_instance_receiver_result ( instance_receiver_res)
185
+ }
186
+
187
+ fn show_configuration ( & self , nextcloud : NextcloudConfiguration , dropbox : DropboxConfiguration ) -> Receiver < UserSelection > {
188
+ let conf_strings = vec ! [
189
+ nextcloud. server_url. clone( ) ,
190
+ nextcloud. username. clone( ) ,
191
+ nextcloud. decrypted_password( ) . unwrap( ) ,
192
+ nextcloud. use_self_signed_certificate. to_string( ) ,
193
+ DropboxConfiguration :: dropbox_url( ) ,
194
+ dropbox. decrypted_token( ) . unwrap( ) ] ;
195
+ let instance_receiver_res = self . jvm . invoke_to_channel (
196
+ & self . edit_configuration_cb ,
197
+ "apply" ,
198
+ & [ InvocationArg :: from ( ( conf_strings. as_slice ( ) , & self . jvm ) ) ] ) ;
199
+ japi:: handle_instance_receiver_result ( instance_receiver_res)
200
+ }
201
+
204
202
fn exit ( & self , contents_changed : bool ) -> Receiver < UserSelection > {
205
203
debug ! ( "Exiting rust-keylock..." ) ;
206
204
if contents_changed {
0 commit comments