Skip to content

Commit 823a7d5

Browse files
committed
prevent quick sequential calls of the status command
1 parent 629c132 commit 823a7d5

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

app/src/main/java/app/trigger/MainActivity.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646

4747
public class MainActivity extends AppCompatActivity implements OnTaskCompleted {
48+
private static final String TAG = "MainActivity";
4849
private boolean hasSetupSelected = false;
4950
private ImageView stateImage;
5051
private ImageButton lockButton;
@@ -154,10 +155,14 @@ private void updateSpinner(boolean match_ssid) {
154155
spinner.setAdapter(adapter);
155156
spinner.setSelection(selection);
156157
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
158+
int check = 0; // prevent triggering on creation
159+
157160
@Override
158161
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
159-
updateButtons();
160-
callRequestHandler(Action.fetch_state);
162+
if (check++ > 0) {
163+
updateButtons();
164+
callRequestHandler(Action.fetch_state);
165+
}
161166
}
162167

163168
@Override
@@ -251,9 +256,19 @@ protected void onPause() {
251256

252257
// listen for connectivity changes
253258
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
259+
long lastTrigger = System.currentTimeMillis();
260+
254261
@Override
255262
public void onReceive(Context context, Intent intent) {
256-
callRequestHandler(Action.fetch_state);
263+
if (isInitialStickyBroadcast()) {
264+
return;
265+
}
266+
267+
long now = System.currentTimeMillis();
268+
if ((lastTrigger + 1000L) < now) {
269+
lastTrigger = now;
270+
callRequestHandler(Action.fetch_state);
271+
}
257272
}
258273
};
259274

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
* fix SSH_ORIGINAL_COMMAND for command in .ssh/authorized_keys
1+
* fix SSH_ORIGINAL_COMMAND for command in .ssh/authorized_keys
2+
* prevent quick sequential calls of the status command

0 commit comments

Comments
 (0)