Skip to content

Commit

Permalink
Merge pull request #34 from jpage4500/feature/01-31
Browse files Browse the repository at this point in the history
- open terminal if closed (on run script)
  • Loading branch information
jpage4500 authored Feb 5, 2025
2 parents ae8bc1a + e6ad1ec commit 32ba1ac
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.jpage4500.devicemanager.data.LogEntry;
import com.jpage4500.devicemanager.ui.dialog.ConnectDialog;
import com.jpage4500.devicemanager.ui.dialog.SettingsDialog;
import com.jpage4500.devicemanager.utils.*;
import com.jpage4500.devicemanager.utils.Timer;
import com.jpage4500.devicemanager.utils.*;
import se.vidstige.jadb.*;
import se.vidstige.jadb.managers.PackageManager;
import se.vidstige.jadb.managers.PropertyManager;
Expand Down Expand Up @@ -401,16 +401,20 @@ private void fetchCustomColumns(Device device) {
private void fetchFreeDiskSpace(Device device) {
ShellResult result = runShell(device, COMMAND_DISK_SIZE);
if (result.isSuccess && !result.resultList.isEmpty()) {
// only interested in last line
String last = result.resultList.get(result.resultList.size() - 1);
// /dev/fuse 115249236 14681484 100436680 13% /storage/emulated
// ^^^^^^^^^
String size = TextUtils.split(last, 3);
try {
// size is in 1k blocks
device.freeSpace = Long.parseLong(size) * 1000L;
} catch (Exception e) {
log.trace("fetchDeviceDetails: FREE_SPACE Exception:{}", e.getMessage());
for (Iterator<String> iterator = new ReverseIterator<>(result.resultList); iterator.hasNext(); ) {
String line = iterator.next();
// /dev/fuse 115249236 14681484 100436680 13% /storage/emulated
// ^^^^^^^^^
if (TextUtils.endsWith(line, "/storage/emulated")) {
String size = TextUtils.split(line, 3);
try {
// size is in 1k blocks
device.freeSpace = Long.parseLong(size) * 1000L;
return;
} catch (Exception e) {
log.trace("fetchDeviceDetails: FREE_SPACE Exception:{}", e.getMessage());
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.jpage4500.devicemanager.utils;

import java.util.Iterator;
import java.util.List;

/**
* iterate over a list from bottom to top
*/
public class ReverseIterator<T> implements Iterator<T>, Iterable<T> {

private final List<T> list;
private int position;

public ReverseIterator(List<T> list) {
this.list = list;
this.position = list.size() - 1;
}

@Override
public Iterator<T> iterator() {
return this;
}

@Override
public boolean hasNext() {
return position >= 0;
}

@Override
public T next() {
return list.get(position--);
}

@Override
public void remove() {
throw new UnsupportedOperationException();
}

}
2 changes: 2 additions & 0 deletions src/main/resources/scripts/run-custom.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ source ./env-vars.sh
function handleMacOSX() {
if [[ -d /Applications/iTerm.app ]]; then
echo "using iTerm"
open /Applications/iTerm.app
osascript <<END
tell application "iTerm2"
activate
Expand All @@ -29,6 +30,7 @@ END
else
echo "using Terminal"
osascript <<END
open -a Terminal
tell application "Terminal"
activate
tell application "System Events" to keystroke "t" using command down
Expand Down

0 comments on commit 32ba1ac

Please sign in to comment.