@brucewayne1939/sword-security 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,6 +22,68 @@ Sync native files
|
|
|
22
22
|
npx cap sync
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
Add the following to your `app.component.ts`:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { Security } from 'sword-security';
|
|
31
|
+
|
|
32
|
+
@Component({
|
|
33
|
+
// ...
|
|
34
|
+
})
|
|
35
|
+
export class AppComponent implements OnInit {
|
|
36
|
+
securityPopupOpen = false;
|
|
37
|
+
|
|
38
|
+
constructor(private alertController: AlertController) {}
|
|
39
|
+
|
|
40
|
+
async ngOnInit() {
|
|
41
|
+
await this.checkDeviceSecurity();
|
|
42
|
+
|
|
43
|
+
App.addListener('appStateChange', async ({ isActive }) => {
|
|
44
|
+
if (isActive) {
|
|
45
|
+
console.log('App resumed');
|
|
46
|
+
await this.checkDeviceSecurity();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async checkDeviceSecurity() {
|
|
52
|
+
try {
|
|
53
|
+
const rootResult = await Security.isRooted();
|
|
54
|
+
const devResult = await Security.isDeveloperModeEnabled();
|
|
55
|
+
console.log('Rooted:', rootResult.rooted);
|
|
56
|
+
console.log('Developer Mode:', devResult.enabled);
|
|
57
|
+
|
|
58
|
+
const insecure = rootResult.rooted || devResult.enabled;
|
|
59
|
+
|
|
60
|
+
if (insecure && !this.securityPopupOpen) {
|
|
61
|
+
this.securityPopupOpen = true;
|
|
62
|
+
|
|
63
|
+
const alert = await this.alertController.create({
|
|
64
|
+
header: 'Security Warning',
|
|
65
|
+
message: 'Developer options, USB debugging, or root access detected. Please disable them to continue.',
|
|
66
|
+
backdropDismiss: false,
|
|
67
|
+
buttons: [
|
|
68
|
+
{
|
|
69
|
+
text: 'Open Settings',
|
|
70
|
+
handler: async () => {
|
|
71
|
+
this.securityPopupOpen = false;
|
|
72
|
+
await Security.openDeveloperSettings();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
await alert.present();
|
|
79
|
+
}
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.error(err);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
25
87
|
## API
|
|
26
88
|
|
|
27
89
|
<docgen-index></docgen-index>
|