|
1 | 1 | // @flow |
2 | 2 |
|
3 | | -import { Android, Config, Project, ProjectSettings, Simulator, UrlUtils } from 'xdl'; |
| 3 | +import { Android, Config, Project, ProjectSettings, Simulator, UrlUtils, UserSettings } from 'xdl'; |
4 | 4 |
|
5 | 5 | import chalk from 'chalk'; |
6 | 6 | import indent from 'indent-string'; |
@@ -138,34 +138,54 @@ async function handleKeypress(key) { |
138 | 138 | const lanAddress = await UrlUtils.constructManifestUrlAsync(process.cwd(), { |
139 | 139 | hostType: 'lan', |
140 | 140 | }); |
141 | | - |
| 141 | + const defaultRecipient = await UserSettings.getAsync('sendTo', null); |
142 | 142 | const rl = readline.createInterface({ |
143 | 143 | input: process.stdin, |
144 | | - output: process.stdout |
| 144 | + output: process.stdout, |
145 | 145 | }); |
146 | | - |
147 | | - clearConsole(); |
148 | | - log.withTimestamp('Please enter your phone number or email address (empty to cancel):') |
149 | | - rl.question('> ', async (sendTo) => { |
| 146 | + const handleKeypress = (chr, key) => { |
| 147 | + if (key && key.name === 'escape') { |
| 148 | + cleanup(); |
| 149 | + cancel(); |
| 150 | + } |
| 151 | + }; |
| 152 | + const cleanup = () => { |
150 | 153 | rl.close(); |
| 154 | + process.stdin.removeListener('keypress', handleKeypress); |
151 | 155 | startWaitingForCommand(); |
| 156 | + }; |
| 157 | + const cancel = () => { |
| 158 | + clearConsole(); |
| 159 | + printUsage(); |
| 160 | + }; |
| 161 | + clearConsole(); |
| 162 | + process.stdin.addListener('keypress', handleKeypress); |
| 163 | + log('Please enter your phone number or email address (press ESC to cancel) '); |
| 164 | + rl.question(defaultRecipient ? `[default: ${defaultRecipient}]> ` : '> ', async sendTo => { |
| 165 | + cleanup(); |
| 166 | + if (!sendTo && defaultRecipient) { |
| 167 | + sendTo = defaultRecipient; |
| 168 | + } |
| 169 | + sendTo = sendTo && sendTo.trim(); |
152 | 170 | if (!sendTo) { |
153 | | - clearConsole(); |
154 | | - printUsage(); |
| 171 | + cancel(); |
155 | 172 | return; |
156 | 173 | } |
157 | | - |
158 | 174 | log.withTimestamp(`Sending ${lanAddress} to ${sendTo}...`); |
159 | 175 |
|
| 176 | + let sent = false; |
160 | 177 | try { |
161 | 178 | await Exp.sendAsync(sendTo, lanAddress, true); |
162 | 179 | log.withTimestamp(`Sent link successfully.`); |
| 180 | + sent = true; |
163 | 181 | } catch (err) { |
164 | 182 | log.withTimestamp(`Could not send link. ${err}`); |
165 | 183 | } |
166 | 184 | printUsage(); |
| 185 | + if (sent) { |
| 186 | + await UserSettings.setAsync('sendTo', sendTo); |
| 187 | + } |
167 | 188 | }); |
168 | | - |
169 | 189 | return; |
170 | 190 | } |
171 | 191 | case 'q': |
|
0 commit comments