Code Monkey home page Code Monkey logo

timbru31 / cordova-plugin-android-dark-mode-support Goto Github PK

View Code? Open in Web Editor NEW
12.0 4.0 1.0 264 KB

๐ŸŒš/๐ŸŒž Apache Cordova plugin to enable proper dark mode support for Android WebView's

Home Page: https://www.npmjs.com/package/cordova-plugin-android-dark-mode-support

License: MIT License

JavaScript 14.86% Kotlin 85.14%
android cordova-plugin kotlin ionic phonegap phonegap-plugin dark-mode cordova-android cordova-android-plugin ionic-plugin capacitor capacitor-plugin cordova

cordova-plugin-android-dark-mode-support's Introduction

cordova-plugin-android-dark-mode-support

Linting npm audit

Known Vulnerabilities

Commitizen friendly License npm

Apache Cordova plugin to enable proper dark mode support for Android WebView's

Context/Background

While Android supports a dark mode since API level 29 (Android 10), Android WebView's need explicit support for this. This plugin changes the used Cordova WebView, no matter if the default from cordova-android or a custom one such as the cordova-plugin-ionic-webview to enable or disable the dark mode. This results in a correct usage of the (prefers-color-scheme: dark) media query.

Additionally, when the native configuration changes, it is re-evaluated whether the dark mode is currently active.

Under the hood, the Configuration.UI_MODE_NIGHT_YES, WebSettingsCompat.setForceDark and WebSettingsCompat.setForceDarkStrategy are used. You can read more here: https://developer.android.com/guide/webapps/dark-theme

Attention for SDK >= 33 / Android 13

In Android 13 (SDK 33) you do not this plugin anymore as the behavior was changed again. All you need to do is tweak the used theme by setting:

<preference name="AndroidPostSplashScreenTheme" value="@style/Theme.AppCompat.DayNight.NoActionBar" />

Supported platforms

  • Android

Prerequisites/Warnings

Kotlin support is required. Due to the AndroidX support libraries used, only cordova-android >= 11.0.0 is supported.
You need to enable Kotlin config.xml by setting GradlePluginKotlinEnabled to true.

Installation

from npm (recommended)

$ cordova plugin add cordova-plugin-android-dark-mode-support

from git (unstable)

$ cordova plugin add https://github.com/timbru31/cordova-plugin-android-dark-mode-support.git

Usage

Just install the plugin. Initially it will check the dark mode settings of the device and update once a new configuration is received.
For a instance a timed/schedule theme change can issue a new configuration.


Built by (c) Tim Brust and contributors. Released under the MIT license.

cordova-plugin-android-dark-mode-support's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar github-actions[bot] avatar timbru31 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

oriolsr

cordova-plugin-android-dark-mode-support's Issues

Darkmode targetSDK 33 Android (might need to adjust)

Since the targetSDK 33 on Android WebView the behaviour of darkmode has changed.
It now could 'work' without the plugin however out of the box it does not function at all.
That includes whilst using this plugin.

My finding are based on using using ionic-webview

The change that one should make in order for it to work (again) is change the style of the app theme in
cordova/platforms/android/app/src/main/res/values/styles.xml

@style/Theme.AppCompat.Light.NoActionBar to @style/Theme.AppCompat.DayNight.NoActionBar

Note that with this change it does not propagate when the phone theme is changed (ligt, dark) while the app is still open.

Old:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
    <style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@android:color/white</item>
        <item name="android:statusBarColor">@android:color/white</item>
        <item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
    </style>
</resources>

new

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
    <style name="AppTheme" parent="@style/Theme.AppCompat.DayNight.NoActionBar">
        <item name="android:windowBackground">@android:color/white</item>
        <item name="android:statusBarColor">@android:color/white</item>
        <item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
    </style>

App falsely marked as "Virus detected" when using this plugin

This is not an issue with the plugin. The plugin works fine. I'm purely writing this to see if anybody else has experienced (and solved) the same issue.

Whenever I try to install the debug build of my app, a big red message flashes up, warning me of a "trojan" inside the app. This is a "feature" in Xioami brand mobile phones that's based on the the "Avast" engine. I can reproduce the same issue on virustotal.com. The "Avast-Mobile" engine detects something, while all of the otther engines have no issues:

image

I disabled one plugin after another and only this one triggers the false positive. I checked all of the code and of course found nothing.

Interestingly, when disabling "GradlePluginKotlinEnabled", the app crashes on startup (as expected), but in that case it doesn't get detected by Avast. So I suppose it might have to do something with the bytecode generated by Kotlin?

Any help or idea is appreciated. I'm thinking about rewriting the Kotlin part in Java to see if that helps, but maybe somebody else has been able to solve the same issue.

Error adding plugin de.dustplanet.cordova.AndroidDarkModeSupport.

Hi i installed your plugin today and now my app ist crasching even after i uninstaled it.
it has the problem that is trys to load de.dustplanet.cordova.AndroidDarkModeSupport.

Stacktrace:

System.err: java.lang.ClassNotFoundException: de.dustplanet.cordova.AndroidDarkModeSupport
System.err:    at java.lang.Class.classForName(Native Method)
System.err:    at java.lang.Class.forName(Class.java:453)
System.err:    at java.lang.Class.forName(Class.java:378)
System.err:    at org.apache.cordova.PluginManager.instantiatePlugin(PluginManager.java:564)
System.err:    at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:183)
System.err:    at org.apache.cordova.PluginManager.startupPlugins(PluginManager.java:108)
System.err:    at org.apache.cordova.PluginManager.init(PluginManager.java:96)
System.err:    at org.apache.cordova.CordovaWebViewImpl.init(CordovaWebViewImpl.java:119)
System.err:    at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:152)
System.err:    at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:227)
System.err:    at de.terraconnect.smarthome.MainActivity.onCreate(MainActivity.java:39)
System.err:    at android.app.Activity.performCreate(Activity.java:7327)
System.err:    at android.app.Activity.performCreate(Activity.java:7318)
System.err:    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
System.err:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3094)
System.err:    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3257)
System.err:    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
System.err:    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
System.err:    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
System.err:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
System.err:    at android.os.Handler.dispatchMessage(Handler.java:106)
System.err:    at android.os.Looper.loop(Looper.java:214)
System.err:    at android.app.ActivityThread.main(ActivityThread.java:7050)
System.err:    at java.lang.reflect.Method.invoke(Native Method)
System.err:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
System.err:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "de.dustplanet.cordova.AndroidDarkModeSupport" on path: DexPathList[[zip file "/data/app/de.terraconnect.smarthome-dUL3NQv8pLh0Bq2aJlXJUw==/base.apk"],nativeLibraryDirectories=[/data/app/de.terraconnect.smarthome-dUL3NQv8pLh0Bq2aJlXJUw==/lib/arm64, /system/lib64, /system/vendor/lib64]]
System.err:    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
System.err:    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
System.err:    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
System.err:    ... 26 more
System.out: Error adding plugin de.dustplanet.cordova.AndroidDarkModeSupport.
AndroidRuntime: Shutting down VM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.