mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 17:55:20 +00:00
kivy/android: ask for STORAGE permission at runtime
This commit is contained in:
parent
d5dc8d1ab2
commit
497d6019e1
2 changed files with 20 additions and 6 deletions
|
@ -7,7 +7,7 @@ import traceback
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
import threading
|
import threading
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import TYPE_CHECKING, Optional, Union, Callable
|
from typing import TYPE_CHECKING, Optional, Union, Callable, Sequence
|
||||||
|
|
||||||
from electrum.storage import WalletStorage, StorageReadWriteError
|
from electrum.storage import WalletStorage, StorageReadWriteError
|
||||||
from electrum.wallet_db import WalletDB
|
from electrum.wallet_db import WalletDB
|
||||||
|
@ -1223,11 +1223,26 @@ class ElectrumWindow(App):
|
||||||
self._password_dialog.open()
|
self._password_dialog.open()
|
||||||
|
|
||||||
def save_backup(self):
|
def save_backup(self):
|
||||||
|
if platform != 'android':
|
||||||
|
self._save_backup()
|
||||||
|
return
|
||||||
|
|
||||||
|
from android.permissions import request_permissions, Permission
|
||||||
|
def cb(permissions, grant_results: Sequence[bool]):
|
||||||
|
if not grant_results or not grant_results[0]:
|
||||||
|
self.show_error(_("Cannot save backup without STORAGE permission"))
|
||||||
|
return
|
||||||
|
# note: Clock.schedule_once is a hack so that we get called on a non-daemon thread
|
||||||
|
# (needed for WalletDB.write)
|
||||||
|
Clock.schedule_once(lambda dt: self._save_backup())
|
||||||
|
request_permissions([Permission.WRITE_EXTERNAL_STORAGE], cb)
|
||||||
|
|
||||||
|
def _save_backup(self):
|
||||||
new_path = self.wallet.save_backup(pin_code=self.pin_code)
|
new_path = self.wallet.save_backup(pin_code=self.pin_code)
|
||||||
if new_path:
|
if new_path:
|
||||||
self.show_info(_("Backup saved:") + f"\n{new_path}")
|
self.show_info(_("Backup saved:") + f"\n{new_path}")
|
||||||
else:
|
else:
|
||||||
self.show_error(_("Backup directory not configured"))
|
self.show_error(_("Backup NOT saved. Backup directory or password not configured."))
|
||||||
|
|
||||||
def export_private_keys(self, pk_label, addr):
|
def export_private_keys(self, pk_label, addr):
|
||||||
if self.wallet.is_watching_only():
|
if self.wallet.is_watching_only():
|
||||||
|
|
|
@ -426,12 +426,11 @@ def profiler(func):
|
||||||
|
|
||||||
|
|
||||||
def android_ext_dir():
|
def android_ext_dir():
|
||||||
import jnius
|
from android.storage import primary_external_storage_path
|
||||||
env = jnius.autoclass('android.os.Environment')
|
return primary_external_storage_path()
|
||||||
return env.getExternalStorageDirectory().getPath()
|
|
||||||
|
|
||||||
def android_backup_dir():
|
def android_backup_dir():
|
||||||
d = android_ext_dir() + '/org.electrum.electrum'
|
d = os.path.join(android_ext_dir(), 'org.electrum.electrum')
|
||||||
if not os.path.exists(d):
|
if not os.path.exists(d):
|
||||||
os.mkdir(d)
|
os.mkdir(d)
|
||||||
return d
|
return d
|
||||||
|
|
Loading…
Add table
Reference in a new issue