v1.3.1: Auto-execute AI actions, Keep Screen On, status toasts
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
69
android/app/src/main/java/ai/z/chat/WakePlugin.java
Normal file
69
android/app/src/main/java/ai/z/chat/WakePlugin.java
Normal 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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user