Skip to content

Commit a5cff61

Browse files
committed
Fix %there pin command shortcut icon lookup
1 parent 22d847b commit a5cff61

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

pythonhere/android_here.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_current_intent() -> Intent:
2222
return PythonActivity.mActivity.getIntent()
2323

2424

25-
def get_startup_script(intent: None = None) -> str | None:
25+
def get_startup_script(intent: Intent | None = None) -> str | None:
2626
"""Return script entrypoint that was passed to a given, or current, intent."""
2727
if not intent:
2828
intent = get_current_intent()
@@ -35,8 +35,7 @@ def restart_app(script: str = None):
3535
Logger.info("PythonHere: restart requested with a script: %s", script)
3636
activity = PythonActivity.mActivity
3737
intent = Intent(activity.getApplicationContext(), PythonActivity)
38-
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
39-
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
38+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
4039

4140
if script:
4241
intent.setData(Uri.parse(script))
@@ -59,11 +58,17 @@ def on_new_intent(intent):
5958

6059

6160
def create_shortcut_icon() -> Icon:
62-
"""Create icon to use for a shurtcut."""
61+
"""Create icon to use for a shortcut."""
6362
activity = PythonActivity.mActivity
64-
Drawable = autoclass(f"{activity.getPackageName()}.R$drawable")
6563
context = cast("android.content.Context", activity.getApplicationContext())
66-
return Icon.createWithResource(context, Drawable.icon)
64+
65+
app_info = context.getApplicationInfo()
66+
icon_res_id = app_info.icon
67+
68+
if not icon_res_id:
69+
raise RuntimeError("Application icon resource id was not found")
70+
71+
return Icon.createWithResource(context, icon_res_id)
6772

6873

6974
def resolve_script_path(script: str) -> str:
@@ -97,4 +102,6 @@ def pin_shortcut(script: str, label: str):
97102
)
98103

99104
manager = activity.getSystemService(Context.SHORTCUT_SERVICE)
105+
if not manager.isRequestPinShortcutSupported():
106+
raise RuntimeError("Pinned shortcuts are not supported by this launcher")
100107
manager.requestPinShortcut(shortcut, None)

0 commit comments

Comments
 (0)