mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-02 02:41:28 +00:00
add management app skeleton and ConfirmDialog
We might rewrite PinDialog as a content for ConfirmDialog in the future. Also, I'm beginning to hit memory issues on a 64-bit system.
This commit is contained in:
parent
9c34491e20
commit
6a647b124d
@ -29,7 +29,7 @@ def layout_homescreen(initialize_msg=None):
|
|||||||
features.device_id = 'DEADBEEF'
|
features.device_id = 'DEADBEEF'
|
||||||
features.coins = []
|
features.coins = []
|
||||||
features.imported = False
|
features.imported = False
|
||||||
features.initialized = True
|
features.initialized = False
|
||||||
features.label = 'My TREZOR'
|
features.label = 'My TREZOR'
|
||||||
features.major_version = 2
|
features.major_version = 2
|
||||||
features.minor_version = 0
|
features.minor_version = 0
|
||||||
@ -39,7 +39,7 @@ def layout_homescreen(initialize_msg=None):
|
|||||||
features.passphrase_cached = False
|
features.passphrase_cached = False
|
||||||
features.passphrase_protection = False
|
features.passphrase_protection = False
|
||||||
features.vendor = 'bitcointrezor.com'
|
features.vendor = 'bitcointrezor.com'
|
||||||
wire.write_msg(features)
|
wire.write(features)
|
||||||
yield loop.Wait([dispatcher.dispatch(),
|
yield loop.Wait([dispatcher.dispatch(),
|
||||||
swipe_to_rotate(),
|
swipe_to_rotate(),
|
||||||
animate_logo()])
|
animate_logo()])
|
||||||
|
17
src/apps/management/__init__.py
Normal file
17
src/apps/management/__init__.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from trezor.dispatcher import register
|
||||||
|
from trezor.utils import unimport_func
|
||||||
|
|
||||||
|
|
||||||
|
@unimport_func
|
||||||
|
def dispatch_LoadDevice(mtype, mbuf):
|
||||||
|
from trezor.messages.LoadDevice import LoadDevice
|
||||||
|
|
||||||
|
message = LoadDevice.loads(mbuf)
|
||||||
|
|
||||||
|
from .layout_load_device import layout_load_device
|
||||||
|
return layout_load_device(message)
|
||||||
|
|
||||||
|
|
||||||
|
def boot():
|
||||||
|
LoadDevice = 13
|
||||||
|
register(LoadDevice, dispatch_LoadDevice)
|
37
src/apps/management/layout_load_device.py
Normal file
37
src/apps/management/layout_load_device.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
from trezor import wire
|
||||||
|
from trezor import ui
|
||||||
|
from trezor.utils import unimport_gen
|
||||||
|
|
||||||
|
|
||||||
|
@unimport_gen
|
||||||
|
def confirm():
|
||||||
|
from trezor.ui.confirm import ConfirmDialog, CONFIRMED
|
||||||
|
from trezor.messages.ButtonRequest import ButtonRequest
|
||||||
|
from trezor.messages.ButtonRequestType import Other
|
||||||
|
from trezor.messages.ButtonAck import ButtonAck
|
||||||
|
|
||||||
|
dialog = ConfirmDialog()
|
||||||
|
dialog.render()
|
||||||
|
|
||||||
|
ack = yield from wire.call(ButtonRequest(code=Other), ButtonAck)
|
||||||
|
res = yield from dialog.wait()
|
||||||
|
|
||||||
|
return res == CONFIRMED
|
||||||
|
|
||||||
|
|
||||||
|
@unimport_gen
|
||||||
|
def layout_load_device(message):
|
||||||
|
|
||||||
|
ui.clear()
|
||||||
|
ui.display.text_center(120, 40, 'Really load device?', ui.BOLD, ui.WHITE, ui.BLACK)
|
||||||
|
ui.display.text_center(120, 100, 'Never do this, please.', ui.NORMAL, ui.WHITE, ui.BLACK)
|
||||||
|
|
||||||
|
confirmed = yield from confirm()
|
||||||
|
|
||||||
|
if confirmed:
|
||||||
|
from trezor.messages.Success import Success
|
||||||
|
wire.write(Success(message='Loaded'))
|
||||||
|
else:
|
||||||
|
from trezor.messages.Failure import Failure
|
||||||
|
from trezor.messages.FailureType import ActionCancelled
|
||||||
|
wire.write(Failure(message='Cancelled', code=ActionCancelled))
|
@ -2,11 +2,11 @@ from trezor import loop
|
|||||||
from trezor import ui
|
from trezor import ui
|
||||||
from trezor import msg
|
from trezor import msg
|
||||||
from trezor.ui.pin import PinDialog, PIN_CONFIRMED, PIN_CANCELLED
|
from trezor.ui.pin import PinDialog, PIN_CONFIRMED, PIN_CANCELLED
|
||||||
from trezor.utils import unimport_func
|
from trezor.utils import unimport_gen
|
||||||
from trezor.res import loadres
|
from trezor.res import loadres
|
||||||
|
|
||||||
|
|
||||||
@unimport_func
|
@unimport_gen
|
||||||
def layout_tap_to_confirm(address, amount, currency):
|
def layout_tap_to_confirm(address, amount, currency):
|
||||||
|
|
||||||
# ui.display.bar(0, 0, 240, 40, ui.GREEN)
|
# ui.display.bar(0, 0, 240, 40, ui.GREEN)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from trezor import wire
|
from trezor import wire
|
||||||
from trezor import ui
|
from trezor import ui
|
||||||
from trezor.ui.button import Button, CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE
|
from trezor.ui.button import Button, CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE
|
||||||
from trezor.ui.pin import PinDialog
|
|
||||||
from trezor.utils import unimport_gen
|
from trezor.utils import unimport_gen
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,15 +4,17 @@ from trezor import msg
|
|||||||
# Load all applications
|
# Load all applications
|
||||||
from apps import playground
|
from apps import playground
|
||||||
from apps import homescreen
|
from apps import homescreen
|
||||||
|
from apps import management
|
||||||
from apps import wallet
|
from apps import wallet
|
||||||
|
|
||||||
# Initialize all applications
|
# Initialize all applications
|
||||||
playground.boot()
|
playground.boot()
|
||||||
homescreen.boot()
|
homescreen.boot()
|
||||||
|
management.boot()
|
||||||
wallet.boot()
|
wallet.boot()
|
||||||
|
|
||||||
# just a demo to show how to register USB ifaces
|
# just a demo to show how to register USB ifaces
|
||||||
msg.setup( [ (1, 0xF53C), (2, 0xF1D0) ] )
|
msg.setup([(1, 0xF53C), (2, 0xF1D0)])
|
||||||
|
|
||||||
# Load default homescreen
|
# Load default homescreen
|
||||||
from apps.homescreen.layout_homescreen import layout_homescreen
|
from apps.homescreen.layout_homescreen import layout_homescreen
|
||||||
|
@ -39,6 +39,10 @@ NORMAL = const(1)
|
|||||||
BOLD = const(2)
|
BOLD = const(2)
|
||||||
|
|
||||||
|
|
||||||
|
def clear(color=BLACK):
|
||||||
|
display.bar(0, 0, 240, 240, color)
|
||||||
|
|
||||||
|
|
||||||
def in_area(pos: tuple, area: tuple) -> bool:
|
def in_area(pos: tuple, area: tuple) -> bool:
|
||||||
x, y = pos
|
x, y = pos
|
||||||
ax, ay, aw, ah = area
|
ax, ay, aw, ah = area
|
||||||
|
42
src/trezor/ui/confirm.py
Normal file
42
src/trezor/ui/confirm.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
from .button import Button, BTN_CLICKED
|
||||||
|
from .button import CONFIRM_BUTTON, CONFIRM_BUTTON_ACTIVE
|
||||||
|
from .button import CANCEL_BUTTON, CANCEL_BUTTON_ACTIVE
|
||||||
|
from trezor import loop
|
||||||
|
|
||||||
|
|
||||||
|
CONFIRMED = const(1)
|
||||||
|
CANCELLED = const(2)
|
||||||
|
|
||||||
|
|
||||||
|
class ConfirmDialog():
|
||||||
|
|
||||||
|
def __init__(self, content=None, confirm='Confirm', cancel='Cancel'):
|
||||||
|
self.content = content
|
||||||
|
self.confirm = Button((0, 240 - 60, 120, 60), confirm,
|
||||||
|
normal_style=CONFIRM_BUTTON,
|
||||||
|
active_style=CONFIRM_BUTTON_ACTIVE)
|
||||||
|
self.cancel = Button((120, 240 - 60, 120, 60), cancel,
|
||||||
|
normal_style=CANCEL_BUTTON,
|
||||||
|
active_style=CANCEL_BUTTON_ACTIVE)
|
||||||
|
|
||||||
|
def render(self):
|
||||||
|
if self.content is not None:
|
||||||
|
self.content.render()
|
||||||
|
self.confirm.render()
|
||||||
|
self.cancel.render()
|
||||||
|
|
||||||
|
def send(self, event, pos):
|
||||||
|
if self.confirm.send(event, pos) == BTN_CLICKED:
|
||||||
|
return CONFIRMED
|
||||||
|
if self.cancel.send(event, pos) == BTN_CLICKED:
|
||||||
|
return CANCELLED
|
||||||
|
if self.content is not None:
|
||||||
|
return self.content.send(event, pos)
|
||||||
|
|
||||||
|
def wait(self):
|
||||||
|
while True:
|
||||||
|
self.render()
|
||||||
|
event, *pos = yield loop.Select(loop.TOUCH)
|
||||||
|
result = self.send(event, pos)
|
||||||
|
if result is not None:
|
||||||
|
return result
|
@ -69,7 +69,7 @@ def write_wire_msg(mtype, mbuf):
|
|||||||
data = rep[1:]
|
data = rep[1:]
|
||||||
|
|
||||||
|
|
||||||
def read_msg(*types):
|
def read(*types):
|
||||||
mtype, mbuf = yield from read_wire_msg()
|
mtype, mbuf = yield from read_wire_msg()
|
||||||
for t in types:
|
for t in types:
|
||||||
if t.wire_type == mtype:
|
if t.wire_type == mtype:
|
||||||
@ -78,13 +78,13 @@ def read_msg(*types):
|
|||||||
raise Exception('Unexpected message')
|
raise Exception('Unexpected message')
|
||||||
|
|
||||||
|
|
||||||
def write_msg(m):
|
def write(m):
|
||||||
mbuf = m.dumps()
|
mbuf = m.dumps()
|
||||||
mtype = m.message_type.wire_type
|
mtype = m.message_type.wire_type
|
||||||
write_wire_msg(mtype, mbuf)
|
write_wire_msg(mtype, mbuf)
|
||||||
|
|
||||||
|
|
||||||
def call(req, *types):
|
def call(req, *types):
|
||||||
write_msg(req)
|
write(req)
|
||||||
res = yield from read_msg(*types)
|
res = yield from read(*types)
|
||||||
return res
|
return res
|
||||||
|
Loading…
Reference in New Issue
Block a user