Skip to content

Commit 50770cf

Browse files
authored
Merge pull request #2 from joinflux/android-fix
Multiple fixes and improvements
2 parents f486ec9 + 9f63dd1 commit 50770cf

9 files changed

Lines changed: 87 additions & 21 deletions

File tree

.github/workflows/pr-build.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: PR Build
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: read
8+
9+
concurrency:
10+
group: pr-build-${{ github.event.pull_request.number || github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-node@v4
20+
with:
21+
node-version: 24
22+
cache: npm
23+
24+
- run: npm ci
25+
- run: npm run lint
26+
- run: npm run build

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515

1616
- uses: actions/setup-node@v4
1717
with:
18-
node-version: 20
18+
node-version: 24
1919
registry-url: https://registry.npmjs.org
2020
cache: npm
2121

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Requirements:
3131
## Usage
3232

3333
```ts
34-
import { SensitiveScreen } from 'capacitor-sensitive-screen';
34+
import { SensitiveScreen } from '@joinflux/capacitor-sensitive-screen';
3535
import { useEffect } from 'react';
3636

3737
export function AccountStatementRoute() {
@@ -228,9 +228,7 @@ with the version as the message, and creates a matching `vX.Y.Z` tag.
228228
1. Verifies the tag (e.g. `v0.2.0`) matches `package.json.version`. If not,
229229
it fails fast — this catches tags created by hand without a version bump.
230230
2. Runs `npm ci` and `npm run build`.
231-
3. Runs `npm publish --access public --provenance` using `NPM_TOKEN`. The
232-
`--provenance` flag attaches a signed attestation linking the published
233-
tarball back to this repo and this commit.
231+
3. Runs `npm publish --access public` using `Trusted Publisher`.
234232
4. Creates a GitHub Release for the tag with auto-generated release notes
235233
from the commits since the previous tag.
236234

android/src/main/java/finance/flux/sensitivescreen/SensitiveScreenPlugin.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.joinflux.sensitivescreen;
22

3+
import android.app.Activity;
4+
import android.view.Window;
35
import android.view.WindowManager;
46

57
import com.getcapacitor.Plugin;
@@ -12,16 +14,36 @@ public class SensitiveScreenPlugin extends Plugin {
1214

1315
@PluginMethod
1416
public void enable(final PluginCall call) {
15-
getActivity().runOnUiThread(() -> {
16-
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
17+
final Activity activity = getActivity();
18+
if (activity == null) {
19+
call.reject("Activity unavailable");
20+
return;
21+
}
22+
activity.runOnUiThread(() -> {
23+
final Window window = activity.getWindow();
24+
if (window == null) {
25+
call.reject("Window unavailable");
26+
return;
27+
}
28+
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
1729
call.resolve();
1830
});
1931
}
2032

2133
@PluginMethod
2234
public void disable(final PluginCall call) {
23-
getActivity().runOnUiThread(() -> {
24-
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
35+
final Activity activity = getActivity();
36+
if (activity == null) {
37+
call.reject("Activity unavailable");
38+
return;
39+
}
40+
activity.runOnUiThread(() -> {
41+
final Window window = activity.getWindow();
42+
if (window == null) {
43+
call.reject("Window unavailable");
44+
return;
45+
}
46+
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
2547
call.resolve();
2648
});
2749
}

biome.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3-
"organizeImports": { "enabled": true },
2+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3+
"organizeImports": {
4+
"enabled": true
5+
},
46
"linter": {
57
"enabled": true,
6-
"rules": { "recommended": true }
8+
"rules": {
9+
"recommended": true
10+
}
711
},
812
"formatter": {
913
"enabled": false

ios/Plugin/SensitiveScreenPlugin.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,28 @@ public class SensitiveScreenPlugin: CAPPlugin {
6767

6868
private func handleWillResignActive() {
6969
guard isEnabled, overlayView == nil else { return }
70-
guard let window = UIApplication.shared.windows.first else { return }
70+
guard let window = activeKeyWindow() else { return }
7171

7272
let overlay = buildOverlay(frame: window.bounds)
7373
window.addSubview(overlay)
7474
overlayView = overlay
7575
}
7676

77+
private func activeKeyWindow() -> UIWindow? {
78+
let scenes = UIApplication.shared.connectedScenes
79+
.compactMap { $0 as? UIWindowScene }
80+
81+
if let active = scenes.first(where: { $0.activationState == .foregroundActive }) {
82+
return active.keyWindow ?? active.windows.first { $0.isKeyWindow } ?? active.windows.first
83+
}
84+
85+
if let inactive = scenes.first(where: { $0.activationState == .foregroundInactive }) {
86+
return inactive.keyWindow ?? inactive.windows.first { $0.isKeyWindow } ?? inactive.windows.first
87+
}
88+
89+
return nil
90+
}
91+
7792
private func handleDidBecomeActive() {
7893
overlayView?.removeFromSuperview()
7994
overlayView = nil
@@ -133,7 +148,7 @@ public class SensitiveScreenPlugin: CAPPlugin {
133148
host.addSubview(imageView)
134149
NSLayoutConstraint.activate([
135150
imageView.centerXAnchor.constraint(equalTo: host.centerXAnchor),
136-
imageView.centerYAnchor.constraint(equalTo: host.centerYAnchor),
151+
imageView.centerYAnchor.constraint(equalTo: host.centerYAnchor)
137152
])
138153
}
139154

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"fmt": "npm run biome:fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
3838
"biome": "biome check src",
3939
"biome:fix": "biome check --write src",
40-
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
40+
"prettier": "prettier \"**/*.{css,html,ts,js}\"",
4141
"swiftlint": "node-swiftlint",
4242
"docgen": "docgen --api SensitiveScreenPlugin --output-readme README.md --output-json dist/docs.json",
4343
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
@@ -65,6 +65,9 @@
6565
},
6666
"prettier": "@ionic/prettier-config",
6767
"swiftlint": "@ionic/swiftlint-config",
68+
"engines": {
69+
"node": ">=18.0.0"
70+
},
6871
"capacitor": {
6972
"ios": {
7073
"src": "ios"

src/definitions.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
export type SensitiveScreenOverlayStyle = 'solid' | 'blur';
22

3-
export type SensitiveScreenBlurStyle =
4-
| 'light'
5-
| 'dark'
6-
| 'regular'
7-
| 'prominent'
8-
| 'extraLight';
3+
export type SensitiveScreenBlurStyle = 'light' | 'dark' | 'regular' | 'prominent' | 'extraLight';
94

105
export interface SensitiveScreenEnableOptions {
116
/**

0 commit comments

Comments
 (0)