v1.3.1: Auto-execute AI actions, Keep Screen On, status toasts

This commit is contained in:
admin
2026-05-19 17:12:07 +04:00
Unverified
parent 83fb658a1e
commit 88378b6342
8 changed files with 213 additions and 5 deletions

View File

@@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:allowBackup="true"

View File

@@ -9,6 +9,7 @@ public class MainActivity extends BridgeActivity {
protected void onCreate(Bundle savedInstanceState) {
registerPlugin(ShellPlugin.class);
registerPlugin(InstallerPlugin.class);
registerPlugin(WakePlugin.class);
super.onCreate(savedInstanceState);
}
}

View File

@@ -0,0 +1,69 @@
package ai.z.chat;
import android.content.Context;
import android.os.PowerManager;
import android.view.WindowManager;
import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;
@CapacitorPlugin(name = "Wake")
public class WakePlugin extends Plugin {
private PowerManager.WakeLock wakeLock;
private boolean isHeld = false;
@Override
public void load() {
super.load();
}
@PluginMethod
public void acquire(PluginCall call) {
if (isHeld && wakeLock != null) {
call.resolve(new JSObject().put("held", true));
return;
}
try {
getActivity().runOnUiThread(() -> {
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
});
PowerManager pm = (PowerManager) getContext().getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "zai-chat:wakelock");
wakeLock.acquire(12 * 60 * 60 * 1000L);
isHeld = true;
call.resolve(new JSObject().put("held", true));
} catch (Exception e) {
call.reject("Wake lock failed: " + e.getMessage());
}
}
@PluginMethod
public void release(PluginCall call) {
try {
getActivity().runOnUiThread(() -> {
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
});
if (wakeLock != null && wakeLock.isHeld()) {
wakeLock.release();
}
wakeLock = null;
isHeld = false;
call.resolve(new JSObject().put("held", false));
} catch (Exception e) {
call.reject("Wake release failed: " + e.getMessage());
}
}
@PluginMethod
public void isHeld(PluginCall call) {
call.resolve(new JSObject().put("held", isHeld));
}
}