
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
capacitor-dark-mode
Advanced tools
For detailed tutorial on how to enable dark mode using this plugin visit: https://medium.com/@hinddeep.purohit007/supporting-dark-mode-in-ionic-capacitor-8e57fe9dbd47
Platforms Supported: Android, iOS, Electron and Web/PWA
This plugin can be used to monitor the changes made to system's dark mode.
npm install capacitor-dark-mode
Open MainActivity.java and add the following code inside this.init()
registerPlugin(DarkMode.class);
Adding the above mentioned line will add the following import statement:
import com.bkon.capacitor.DarkMode.DarkMode;
If you encounter errors, please add both the lines manually to MainActivity.java
In the native ios project you will find two modules namely, 'App' and 'Pods'
public override func traitCollectionDidChange(\_ previousTraitCollection: UITraitCollection?) {
if #available(iOS 13.0, \*) {
if self.traitCollection.userInterfaceStyle.rawValue != previousTraitCollection?.userInterfaceStyle.rawValue
{
var darkmode = ["isDarkModeOn":false]
if self.traitCollection.userInterfaceStyle.rawValue == 2
{
darkmode = ["isDarkModeOn":true]
}
else
{
darkmode = ["isDarkModeOn":false]
}
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "CAPDarkModeDidChange"), object: self, userInfo: darkmode )
}
else
{
// No Change
}
} else {
// Fallback on earlier versions.
}
}
import { Plugins } from '@capacitor/core';
const { DarkMode } = Plugins;
import 'capacitor-dark-mode';
SPECIAL NOTE: Remove the import " import 'capacitor-dark-mode' " when building the app for Android and iOS. THe native plugin will not be invoked if you forget to remove the import statement before building for Android and iOS Platform.
If you wish to listen to system wide dark mode chamges on the web/PWA, add the following line to enable the listener:
if(!(platform.is("android") || platform.is("ios")))
{
DarkMode.registerDarkModeChangeListener()
}
The event listener might run outside the zone of angular so we might have to trigger change detection ourselves. That is why changedetectorref.detectChanges() has been used.
DarkMode.addListener("darkModeStateChanged", (state: any) =>
if(state.isDarkModeOn)
{
// Dark mode is on. Apply dark theme to your app
changedetectorref.detectChanges()
}
else
{
// Dark mode is off. Apply light theme to your app
changedetectorref.detectChanges()
}
if(state.supported == false)
{
// Dark mode is not supported by the platform
changedetectorref.detectChanges()
}
});
let darkmode = await DarkMode.isDarkModeOn();
console.log(darkmode.isDarkModeOn);
FAQs
Handle dark mode changes on android and iOS
The npm package capacitor-dark-mode receives a total of 23 weekly downloads. As such, capacitor-dark-mode popularity was classified as not popular.
We found that capacitor-dark-mode demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.