@maximilien0405/capacitor-android-launcher 7.0.2 → 7.0.4

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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Maximilien Zimmermann
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,22 +1,26 @@
1
1
  # Capacitor Android Launcher Plugin
2
2
 
3
- This Capacitor plugin allows you to open the launcher settings to set your app as the default launcher on Android.
3
+ The Capacitor Android Launcher Plugin allows you to set your app as the default launcher on Android devices.
4
4
 
5
- It can also, if needed, start (and stop) and immersive mode that hides the all UI elements (status bar and navigation bar). This is usefull for an Kiosk App, or for special apps made for childrens or seniors.
6
-
7
- > When set as the default launcher, your user will still be able to exit it, but when it happens it will re-open the app.
8
- If you really want to prevent your user from leaving, i suggest "pinning" the app, and then setting it as the default launcher.
5
+ It also provides immersive mode functionality, which hides all system UI elements (status bar and navigation bar). This can be useful for kiosk apps or even apps designed for children or seniors.
9
6
 
10
7
  ## Installation
11
8
 
9
+ To install the plugin, run the following commands:
10
+
12
11
  ```bash
13
12
  npm install @maximilien0405/capacitor-android-launcher
14
13
  npx cap sync
15
14
  ```
16
15
 
16
+ And import it just like this:
17
+ ```ts
18
+ import { AndroidLauncher } from '@maximilien0405/capacitor-android-launcher';
19
+ ```
20
+
17
21
  ## Usage
18
22
 
19
- #### Open Launcher Settings
23
+ ### Open Launcher Settings
20
24
 
21
25
  This method opens the settings page where the user can set your app as the default launcher.
22
26
 
@@ -24,27 +28,39 @@ This method opens the settings page where the user can set your app as the defau
24
28
  await AndroidLauncher.openLauncherSettings();
25
29
  ```
26
30
 
27
- #### Start Immersive Mode
31
+ ### Start Immersive Mode
28
32
 
29
- This method hides all system controls.
33
+ This method hides all system UI elements, creating a full-screen experience.
30
34
 
31
35
  ```ts
32
36
  await AndroidLauncher.startImmersiveMode();
33
37
  ```
34
38
 
35
- #### Stop Immersive Mode
39
+ ### Stop Immersive Mode
36
40
 
37
- This method restores the system controls.
41
+ This method restores the system UI elements.
38
42
 
39
43
  ```ts
40
44
  await AndroidLauncher.stopImmersiveMode();
41
45
  ```
42
46
 
43
- #### Check if is the Launcher
47
+ ### Check if App is the Default Launcher
44
48
 
45
49
  This method checks if your app is currently set as the default launcher.
46
50
 
47
51
  ```ts
48
52
  const isLauncher = await AndroidLauncher.isLauncherApp();
49
- console.log(isLauncher); // true or false
50
- ```
53
+ console.log(isLauncher); // true or false
54
+ ```
55
+
56
+ ## Notes
57
+
58
+ - When set as the default launcher, users can still exit the app. To prevent this, consider using Android's "pinning" feature in combination with this plugin.
59
+
60
+ ## Support
61
+
62
+ For issues or feature requests, please open an issue on the [GitHub repository](https://github.com/maximilien0405/capacitor-android-launcher).
63
+
64
+ ## License
65
+
66
+ This project is licensed under the MIT License. See the LICENSE file for details.
@@ -43,67 +43,58 @@ public class AndroidLauncher {
43
43
  }
44
44
  }
45
45
 
46
- // Starts immersive mode
47
- public void startImmersiveMode(PluginCall call) {
48
- runOnMainThread(() -> {
49
- try {
50
- enableImmersiveMode();
51
- call.resolve();
52
- } catch (Exception e) {
53
- call.reject("Error starting immersive mode", e);
54
- }
55
- });
56
- }
57
-
58
- private void enableImmersiveMode() {
59
- immersiveModeEnabled = true;
60
- setupSystemUiVisibilityListener();
46
+ private void setImmersiveMode(boolean enable) {
47
+ immersiveModeEnabled = enable;
61
48
  View decorView = this.bridge.getActivity().getWindow().getDecorView();
62
49
 
63
50
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
64
51
  WindowInsetsController insetsController = decorView.getWindowInsetsController();
65
52
  if (insetsController != null) {
66
- insetsController.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
67
- insetsController.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
53
+ if (enable) {
54
+ insetsController.hide(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
55
+ insetsController.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
56
+ } else {
57
+ insetsController.show(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
58
+ insetsController.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_TOUCH);
59
+ }
68
60
  }
69
61
  } else {
70
- int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
62
+ int flags = enable
63
+ ? View.SYSTEM_UI_FLAG_LAYOUT_STABLE
71
64
  | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
72
65
  | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
73
66
  | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
74
67
  | View.SYSTEM_UI_FLAG_FULLSCREEN
75
- | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
68
+ | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
69
+ : View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
76
70
  decorView.setSystemUiVisibility(flags);
77
71
  }
78
72
  }
79
73
 
80
- // Stops immersive mode
81
- public void stopImmersiveMode(PluginCall call) {
74
+ // Starts immersive mode
75
+ public void startImmersiveMode(PluginCall call) {
82
76
  runOnMainThread(() -> {
83
77
  try {
84
- clearImmersiveMode();
78
+ setImmersiveMode(true);
79
+ setupSystemUiVisibilityListener();
85
80
  call.resolve();
86
81
  } catch (Exception e) {
87
- call.reject("Error stopping immersive mode", e);
82
+ call.reject("Error starting immersive mode", e);
88
83
  }
89
84
  });
90
85
  }
91
86
 
92
- private void clearImmersiveMode() {
93
- immersiveModeEnabled = false;
94
- removeSystemUiVisibilityListener();
95
- View decorView = this.bridge.getActivity().getWindow().getDecorView();
96
-
97
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
98
- WindowInsetsController insetsController = decorView.getWindowInsetsController();
99
- if (insetsController != null) {
100
- insetsController.show(WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars());
101
- insetsController.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_TOUCH);
87
+ // Stops immersive mode
88
+ public void stopImmersiveMode(PluginCall call) {
89
+ runOnMainThread(() -> {
90
+ try {
91
+ setImmersiveMode(false);
92
+ removeSystemUiVisibilityListener();
93
+ call.resolve();
94
+ } catch (Exception e) {
95
+ call.reject("Error stopping immersive mode", e);
102
96
  }
103
- } else {
104
- int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
105
- decorView.setSystemUiVisibility(flags);
106
- }
97
+ });
107
98
  }
108
99
 
109
100
  // Helper to run things on the UI thread
@@ -132,14 +123,14 @@ public class AndroidLauncher {
132
123
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
133
124
  focusChangeListener = hasFocus -> {
134
125
  if (immersiveModeEnabled && hasFocus) {
135
- enableImmersiveMode();
126
+ setImmersiveMode(true);
136
127
  }
137
128
  };
138
129
  decorView.getViewTreeObserver().addOnWindowFocusChangeListener(focusChangeListener);
139
130
  } else {
140
131
  systemUiVisibilityChangeListener = visibility -> {
141
132
  if (immersiveModeEnabled && (visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
142
- enableImmersiveMode();
133
+ setImmersiveMode(true);
143
134
  }
144
135
  };
145
136
  decorView.setOnSystemUiVisibilityChangeListener(systemUiVisibilityChangeListener);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maximilien0405/capacitor-android-launcher",
3
- "version": "7.0.2",
3
+ "version": "7.0.4",
4
4
  "description": "Capacitor plugin to request your app to be the main launcher.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",