Skip to content

Commit 32ba1ac

Browse files
authored
Merge pull request #34 from jpage4500/feature/01-31
- open terminal if closed (on run script)
2 parents ae8bc1a + e6ad1ec commit 32ba1ac

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

src/main/java/com/jpage4500/devicemanager/manager/DeviceManager.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import com.jpage4500.devicemanager.data.LogEntry;
66
import com.jpage4500.devicemanager.ui.dialog.ConnectDialog;
77
import com.jpage4500.devicemanager.ui.dialog.SettingsDialog;
8-
import com.jpage4500.devicemanager.utils.*;
98
import com.jpage4500.devicemanager.utils.Timer;
9+
import com.jpage4500.devicemanager.utils.*;
1010
import se.vidstige.jadb.*;
1111
import se.vidstige.jadb.managers.PackageManager;
1212
import se.vidstige.jadb.managers.PropertyManager;
@@ -401,16 +401,20 @@ private void fetchCustomColumns(Device device) {
401401
private void fetchFreeDiskSpace(Device device) {
402402
ShellResult result = runShell(device, COMMAND_DISK_SIZE);
403403
if (result.isSuccess && !result.resultList.isEmpty()) {
404-
// only interested in last line
405-
String last = result.resultList.get(result.resultList.size() - 1);
406-
// /dev/fuse 115249236 14681484 100436680 13% /storage/emulated
407-
// ^^^^^^^^^
408-
String size = TextUtils.split(last, 3);
409-
try {
410-
// size is in 1k blocks
411-
device.freeSpace = Long.parseLong(size) * 1000L;
412-
} catch (Exception e) {
413-
log.trace("fetchDeviceDetails: FREE_SPACE Exception:{}", e.getMessage());
404+
for (Iterator<String> iterator = new ReverseIterator<>(result.resultList); iterator.hasNext(); ) {
405+
String line = iterator.next();
406+
// /dev/fuse 115249236 14681484 100436680 13% /storage/emulated
407+
// ^^^^^^^^^
408+
if (TextUtils.endsWith(line, "/storage/emulated")) {
409+
String size = TextUtils.split(line, 3);
410+
try {
411+
// size is in 1k blocks
412+
device.freeSpace = Long.parseLong(size) * 1000L;
413+
return;
414+
} catch (Exception e) {
415+
log.trace("fetchDeviceDetails: FREE_SPACE Exception:{}", e.getMessage());
416+
}
417+
}
414418
}
415419
}
416420
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.jpage4500.devicemanager.utils;
2+
3+
import java.util.Iterator;
4+
import java.util.List;
5+
6+
/**
7+
* iterate over a list from bottom to top
8+
*/
9+
public class ReverseIterator<T> implements Iterator<T>, Iterable<T> {
10+
11+
private final List<T> list;
12+
private int position;
13+
14+
public ReverseIterator(List<T> list) {
15+
this.list = list;
16+
this.position = list.size() - 1;
17+
}
18+
19+
@Override
20+
public Iterator<T> iterator() {
21+
return this;
22+
}
23+
24+
@Override
25+
public boolean hasNext() {
26+
return position >= 0;
27+
}
28+
29+
@Override
30+
public T next() {
31+
return list.get(position--);
32+
}
33+
34+
@Override
35+
public void remove() {
36+
throw new UnsupportedOperationException();
37+
}
38+
39+
}

src/main/resources/scripts/run-custom.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ source ./env-vars.sh
1515
function handleMacOSX() {
1616
if [[ -d /Applications/iTerm.app ]]; then
1717
echo "using iTerm"
18+
open /Applications/iTerm.app
1819
osascript <<END
1920
tell application "iTerm2"
2021
activate
@@ -29,6 +30,7 @@ END
2930
else
3031
echo "using Terminal"
3132
osascript <<END
33+
open -a Terminal
3234
tell application "Terminal"
3335
activate
3436
tell application "System Events" to keystroke "t" using command down

0 commit comments

Comments
 (0)