First-run wallet creatorator (v0.7.0) #24
@ -38,15 +38,15 @@
|
|||||||
mon = none :: none | reference()}).
|
mon = none :: none | reference()}).
|
||||||
|
|
||||||
-record(s,
|
-record(s,
|
||||||
{version = 1 :: integer(),
|
{version = 1 :: integer(),
|
||||||
window = none :: none | wx:wx_object(),
|
window = none :: none | wx:wx_object(),
|
||||||
timer = none :: none | reference(),
|
timer = none :: none | reference(),
|
||||||
tasks = [] :: [#ui{}],
|
tasks = [] :: [#ui{}],
|
||||||
selected = 0 :: non_neg_integer(),
|
selected = 0 :: non_neg_integer(),
|
||||||
wallet = none :: none | #wallet{},
|
wallet = none :: none | #wallet{},
|
||||||
pass = none :: none | binary(),
|
pass = none :: none | binary(),
|
||||||
prefs = #{} :: #{module() := term()},
|
prefs = #{} :: #{module() := term()},
|
||||||
wallets = [] :: [#wr{}]}).
|
wallets = [] :: [#wr{}]}).
|
||||||
|
|
||||||
|
|
||||||
-type state() :: #s{}.
|
-type state() :: #s{}.
|
||||||
@ -477,6 +477,9 @@ handle_cast(Unexpected, State) ->
|
|||||||
handle_info(tic, State) ->
|
handle_info(tic, State) ->
|
||||||
NewState = do_tic(State),
|
NewState = do_tic(State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
|
handle_info({show_ui, Name}, State) ->
|
||||||
|
NewState = do_show_ui(Name, State),
|
||||||
|
{noreply, NewState};
|
||||||
handle_info({'DOWN', Mon, process, PID, Info}, State) ->
|
handle_info({'DOWN', Mon, process, PID, Info}, State) ->
|
||||||
NewState = handle_down(Mon, PID, Info, State),
|
NewState = handle_down(Mon, PID, Info, State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
@ -486,6 +489,7 @@ handle_info(Unexpected, State) ->
|
|||||||
|
|
||||||
|
|
||||||
handle_down(Mon, PID, Info, State = #s{tasks = Tasks}) ->
|
handle_down(Mon, PID, Info, State = #s{tasks = Tasks}) ->
|
||||||
|
tell("Handling down"),
|
||||||
case lists:keytake(Mon, #ui.mon, Tasks) of
|
case lists:keytake(Mon, #ui.mon, Tasks) of
|
||||||
{value, #ui{}, NewTasks} ->
|
{value, #ui{}, NewTasks} ->
|
||||||
State#s{tasks = NewTasks};
|
State#s{tasks = NewTasks};
|
||||||
@ -531,7 +535,7 @@ do_show_ui(Name, State = #s{tasks = Tasks, prefs = Prefs}) ->
|
|||||||
Win = Name:start_link({TaskPrefs, TaskData}),
|
Win = Name:start_link({TaskPrefs, TaskData}),
|
||||||
PID = wx_object:get_pid(Win),
|
PID = wx_object:get_pid(Win),
|
||||||
Mon = monitor(process, PID),
|
Mon = monitor(process, PID),
|
||||||
ok = Name:to_front(Win),
|
% ok = Name:to_front(Win),
|
||||||
UI = #ui{name = Name, pid = PID, wx = Win, mon = Mon},
|
UI = #ui{name = Name, pid = PID, wx = Win, mon = Mon},
|
||||||
State#s{tasks = [UI | Tasks]}
|
State#s{tasks = [UI | Tasks]}
|
||||||
end.
|
end.
|
||||||
@ -1023,8 +1027,10 @@ do_open_wallet(Path, Phrase, State) ->
|
|||||||
State#s{pass = Pass, wallet = Recovered};
|
State#s{pass = Pass, wallet = Recovered};
|
||||||
Error ->
|
Error ->
|
||||||
ok = gd_gui:trouble(Error),
|
ok = gd_gui:trouble(Error),
|
||||||
New = default_wallet(),
|
% FIXME: This is chaotically stupid.
|
||||||
State#s{wallet = New}
|
tell("Sending myself the show_ui message"),
|
||||||
|
self() ! {show_ui, gd_v_wallman},
|
||||||
|
State
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -120,12 +120,12 @@ init({Prefs, Manifest}) ->
|
|||||||
ok;
|
ok;
|
||||||
Count > 1 ->
|
Count > 1 ->
|
||||||
true = wxFrame:show(Frame),
|
true = wxFrame:show(Frame),
|
||||||
ok
|
wxFrame:raise(Frame)
|
||||||
end,
|
end,
|
||||||
State = #s{wx = Wx, frame = Frame, lang = Lang, j = J, prefs = Prefs,
|
State = #s{wx = Wx, frame = Frame, lang = Lang, j = J, prefs = Prefs,
|
||||||
wallets = Manifest,
|
wallets = Manifest,
|
||||||
picker = Picker,
|
picker = Picker,
|
||||||
buttons = Buttons},
|
buttons = Buttons},
|
||||||
{Frame, State}.
|
{Frame, State}.
|
||||||
|
|
||||||
|
|
||||||
@ -136,8 +136,8 @@ handle_call(Unexpected, From, State) ->
|
|||||||
ok = log(warning, "Unexpected call from ~tp: ~tp~n", [From, Unexpected]),
|
ok = log(warning, "Unexpected call from ~tp: ~tp~n", [From, Unexpected]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
||||||
handle_cast(to_front, State = #s{frame = Frame}) ->
|
handle_cast(to_front, State = #s{frame = Frame}) ->
|
||||||
|
ok = ensure_shown(Frame),
|
||||||
ok = wxFrame:raise(Frame),
|
ok = wxFrame:raise(Frame),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_cast({show, Manifest}, State) ->
|
handle_cast({show, Manifest}, State) ->
|
||||||
@ -185,9 +185,9 @@ handle_event(#wx{event = #wxCommand{type = command_button_clicked},
|
|||||||
State = #s{wiz = {_, WizButtons}}) ->
|
State = #s{wiz = {_, WizButtons}}) ->
|
||||||
NewState =
|
NewState =
|
||||||
case lists:keyfind(ID, #w.id, WizButtons) of
|
case lists:keyfind(ID, #w.id, WizButtons) of
|
||||||
#w{name = noob} -> wiz_noob_assist(State);
|
#w{name = noob} -> wiz_noob_assist(State);
|
||||||
#w{name = l33t} -> close_wiz(State);
|
#w{name = l33t} -> close_wiz(State);
|
||||||
false -> State
|
false -> State
|
||||||
end,
|
end,
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
handle_event(#wx{event = #wxClose{}}, State = #s{wiz = {_, _}}) ->
|
handle_event(#wx{event = #wxClose{}}, State = #s{wiz = {_, _}}) ->
|
||||||
@ -236,7 +236,8 @@ do_close(#s{frame = Frame, prefs = Prefs}) ->
|
|||||||
end,
|
end,
|
||||||
NewPrefs = maps:put(geometry, Geometry, Prefs),
|
NewPrefs = maps:put(geometry, Geometry, Prefs),
|
||||||
ok = gd_con:save(?MODULE, NewPrefs),
|
ok = gd_con:save(?MODULE, NewPrefs),
|
||||||
ok = wxWindow:destroy(Frame).
|
ok = wxWindow:destroy(Frame),
|
||||||
|
exit(normal).
|
||||||
|
|
||||||
|
|
||||||
handle_button(Name, State) ->
|
handle_button(Name, State) ->
|
||||||
@ -283,13 +284,14 @@ do_open3(Path, State = #s{frame = Frame, j = J}) ->
|
|||||||
ok = wxDialog:setSizer(Dialog, Sizer),
|
ok = wxDialog:setSizer(Dialog, Sizer),
|
||||||
ok = wxBoxSizer:layout(Sizer),
|
ok = wxBoxSizer:layout(Sizer),
|
||||||
ok = wxDialog:setSize(Dialog, {500, 130}),
|
ok = wxDialog:setSize(Dialog, {500, 130}),
|
||||||
ok = wxFrame:center(Dialog),
|
ok = wxDialog:center(Dialog),
|
||||||
ok = wxStyledTextCtrl:setFocus(PassTx),
|
ok = wxStyledTextCtrl:setFocus(PassTx),
|
||||||
case wxDialog:showModal(Dialog) of
|
case wxDialog:showModal(Dialog) of
|
||||||
?wxID_OK ->
|
?wxID_OK ->
|
||||||
case wxTextCtrl:getValue(PassTx) of
|
case wxTextCtrl:getValue(PassTx) of
|
||||||
"" ->
|
"" ->
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok = wxDialog:destroy(Dialog),
|
||||||
|
ok = ensure_shown(Frame),
|
||||||
State;
|
State;
|
||||||
Phrase ->
|
Phrase ->
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok = wxDialog:destroy(Dialog),
|
||||||
@ -299,6 +301,7 @@ do_open3(Path, State = #s{frame = Frame, j = J}) ->
|
|||||||
end;
|
end;
|
||||||
?wxID_CANCEL ->
|
?wxID_CANCEL ->
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok = wxDialog:destroy(Dialog),
|
||||||
|
ok = ensure_shown(Frame),
|
||||||
State
|
State
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -307,7 +310,7 @@ do_wiz(State = #s{wx = WX, lang = Lang, wiz = none}) ->
|
|||||||
Trans = gd_jt:read_translations(?MODULE),
|
Trans = gd_jt:read_translations(?MODULE),
|
||||||
J = gd_jt:j(Lang, Trans),
|
J = gd_jt:j(Lang, Trans),
|
||||||
|
|
||||||
Frame = wxFrame:new(WX, ?wxID_ANY, J("Initializing Wallet")),
|
Wiz = wxFrame:new(WX, ?wxID_ANY, J("Initializing Wallet")),
|
||||||
MainSz = wxBoxSizer:new(?wxVERTICAL),
|
MainSz = wxBoxSizer:new(?wxVERTICAL),
|
||||||
|
|
||||||
ButtonTemplates =
|
ButtonTemplates =
|
||||||
@ -316,7 +319,7 @@ do_wiz(State = #s{wx = WX, lang = Lang, wiz = none}) ->
|
|||||||
|
|
||||||
MakeButton =
|
MakeButton =
|
||||||
fun({Name, Label}) ->
|
fun({Name, Label}) ->
|
||||||
B = wxButton:new(Frame, ?wxID_ANY, [{label, Label}]),
|
B = wxButton:new(Wiz, ?wxID_ANY, [{label, Label}]),
|
||||||
#w{name = Name, id = wxButton:getId(B), wx = B}
|
#w{name = Name, id = wxButton:getId(B), wx = B}
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -325,15 +328,16 @@ do_wiz(State = #s{wx = WX, lang = Lang, wiz = none}) ->
|
|||||||
Add = fun(#w{wx = Button}) -> wxBoxSizer:add(MainSz, Button, zxw:flags(wide)) end,
|
Add = fun(#w{wx = Button}) -> wxBoxSizer:add(MainSz, Button, zxw:flags(wide)) end,
|
||||||
ok = lists:foreach(Add, Buttons),
|
ok = lists:foreach(Add, Buttons),
|
||||||
|
|
||||||
ok = wxFrame:setSizer(Frame, MainSz),
|
ok = wxFrame:setSizer(Wiz, MainSz),
|
||||||
ok = wxSizer:layout(MainSz),
|
ok = wxSizer:layout(MainSz),
|
||||||
|
|
||||||
ok = wxFrame:connect(Frame, command_button_clicked),
|
ok = wxFrame:connect(Wiz, command_button_clicked),
|
||||||
ok = wxFrame:connect(Frame, close_window),
|
ok = wxFrame:connect(Wiz, close_window),
|
||||||
ok = wxFrame:setSize(Frame, {300, 300}),
|
ok = wxFrame:setSize(Wiz, {300, 300}),
|
||||||
ok = wxFrame:center(Frame),
|
ok = wxFrame:center(Wiz),
|
||||||
true = wxFrame:show(Frame),
|
true = wxFrame:show(Wiz),
|
||||||
State#s{wiz = {Frame, Buttons}}.
|
State#s{wiz = {Wiz, Buttons}}.
|
||||||
|
|
||||||
|
|
||||||
wiz_noob_assist(State = #s{j = J, wiz = {Wiz, _}}) ->
|
wiz_noob_assist(State = #s{j = J, wiz = {Wiz, _}}) ->
|
||||||
DefaultDir = zx_lib:path(var, "otpr", "gajudesk"),
|
DefaultDir = zx_lib:path(var, "otpr", "gajudesk"),
|
||||||
@ -342,8 +346,11 @@ wiz_noob_assist(State = #s{j = J, wiz = {Wiz, _}}) ->
|
|||||||
Name = io_lib:format(Form, [YY, MM, DD, Hr, Mn, Sc]),
|
Name = io_lib:format(Form, [YY, MM, DD, Hr, Mn, Sc]),
|
||||||
Path = filename:join(DefaultDir, Name ++ ".gaju"),
|
Path = filename:join(DefaultDir, Name ++ ".gaju"),
|
||||||
case do_new2(Path, J, Wiz) of
|
case do_new2(Path, J, Wiz) of
|
||||||
ok -> do_close(State);
|
ok ->
|
||||||
abort -> State
|
ok = do_close(State),
|
||||||
|
State;
|
||||||
|
abort ->
|
||||||
|
State
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@ -366,7 +373,9 @@ do_new(State = #s{frame = Frame, j = J, prefs = Prefs}) ->
|
|||||||
case do_new2(Path, J, Frame) of
|
case do_new2(Path, J, Frame) of
|
||||||
ok ->
|
ok ->
|
||||||
NewPrefs = maps:put(dir, Dir, Prefs),
|
NewPrefs = maps:put(dir, Dir, Prefs),
|
||||||
do_close(State#s{prefs = NewPrefs});
|
NewState = State#s{prefs = NewPrefs},
|
||||||
|
ok = do_close(NewState),
|
||||||
|
NewState;
|
||||||
abort ->
|
abort ->
|
||||||
State
|
State
|
||||||
end;
|
end;
|
||||||
@ -459,7 +468,9 @@ do_import(State = #s{frame = Frame, j = J, prefs = Prefs}) ->
|
|||||||
case do_import2(Dir, File, J, Frame) of
|
case do_import2(Dir, File, J, Frame) of
|
||||||
ok ->
|
ok ->
|
||||||
NewPrefs = maps:put(dir, Dir, Prefs),
|
NewPrefs = maps:put(dir, Dir, Prefs),
|
||||||
do_close(State#s{prefs = NewPrefs});
|
NewState = State#s{prefs = NewPrefs},
|
||||||
|
ok = do_close(NewState),
|
||||||
|
NewState;
|
||||||
abort ->
|
abort ->
|
||||||
State
|
State
|
||||||
end;
|
end;
|
||||||
@ -561,3 +572,13 @@ do_drop(Selected, State = #s{j = J, frame = Frame, wallets = Wallets}) ->
|
|||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
State.
|
State.
|
||||||
|
|
||||||
|
|
||||||
|
ensure_shown(Frame) ->
|
||||||
|
case wxWindow:isShown(Frame) of
|
||||||
|
true ->
|
||||||
|
ok;
|
||||||
|
false ->
|
||||||
|
true = wxFrame:show(Frame),
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user