First-run wallet creatorator (v0.7.0) #24
@ -63,7 +63,7 @@
|
|||||||
when Name :: ui_name().
|
when Name :: ui_name().
|
||||||
|
|
||||||
show_ui(Name) ->
|
show_ui(Name) ->
|
||||||
gen_server:cast(?MODULE, {show_ui, Name}).
|
gen_server:call(?MODULE, {show_ui, Name}).
|
||||||
|
|
||||||
|
|
||||||
-spec open_wallet(Path, Phrase) -> Result
|
-spec open_wallet(Path, Phrase) -> Result
|
||||||
@ -329,6 +329,7 @@ init(none) ->
|
|||||||
T = erlang:send_after(tic(), self(), tic),
|
T = erlang:send_after(tic(), self(), tic),
|
||||||
State = #s{window = Window, timer = T, wallets = Wallets, prefs = Prefs},
|
State = #s{window = Window, timer = T, wallets = Wallets, prefs = Prefs},
|
||||||
NewState = do_show_ui(gd_v_wallman, State),
|
NewState = do_show_ui(gd_v_wallman, State),
|
||||||
|
ok = gd_v_wallman:first_run(),
|
||||||
{ok, NewState}.
|
{ok, NewState}.
|
||||||
|
|
||||||
|
|
||||||
@ -378,6 +379,9 @@ handle_call({save, Module, Prefs}, _, State) ->
|
|||||||
handle_call({mnemonic, ID}, _, State) ->
|
handle_call({mnemonic, ID}, _, State) ->
|
||||||
Response = do_mnemonic(ID, State),
|
Response = do_mnemonic(ID, State),
|
||||||
{reply, Response, State};
|
{reply, Response, State};
|
||||||
|
handle_call({show_ui, Name}, _, State) ->
|
||||||
|
NewState = do_show_ui(Name, State),
|
||||||
|
{reply, ok, NewState};
|
||||||
handle_call(Unexpected, From, State) ->
|
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}.
|
||||||
@ -391,13 +395,11 @@ handle_call(Unexpected, From, State) ->
|
|||||||
%% The gen_server:handle_cast/2 callback.
|
%% The gen_server:handle_cast/2 callback.
|
||||||
%% See: http://erlang.org/doc/man/gen_server.html#Module:handle_cast-2
|
%% See: http://erlang.org/doc/man/gen_server.html#Module:handle_cast-2
|
||||||
|
|
||||||
handle_cast({show_ui, Name}, State) ->
|
|
||||||
NewState = do_show_ui(Name, State),
|
|
||||||
{noreply, NewState};
|
|
||||||
handle_cast(close_wallet, State) ->
|
handle_cast(close_wallet, State) ->
|
||||||
NextState = do_close_wallet(State),
|
NextState = do_close_wallet(State),
|
||||||
ok = gd_gui:show([]),
|
ok = gd_gui:show([]),
|
||||||
NewState = do_show_ui(gd_v_wallman, NextState),
|
NewState = do_show_ui(gd_v_wallman, NextState),
|
||||||
|
ok = gd_v_wallman:to_front(),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
handle_cast({new_wallet, Net, Name, Path, Password}, State) ->
|
handle_cast({new_wallet, Net, Name, Path, Password}, State) ->
|
||||||
NewState = do_new_wallet(Net, Name, Path, Password, State),
|
NewState = do_new_wallet(Net, Name, Path, Password, State),
|
||||||
@ -535,7 +537,6 @@ 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),
|
|
||||||
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.
|
||||||
@ -867,7 +868,9 @@ do_make_key(Name, Seed, base58, Transform, State) ->
|
|||||||
|
|
||||||
do_make_key2(_, _, _, State = #s{wallet = none}) ->
|
do_make_key2(_, _, _, State = #s{wallet = none}) ->
|
||||||
ok = gd_gui:trouble("No wallet selected!"),
|
ok = gd_gui:trouble("No wallet selected!"),
|
||||||
do_show_ui(gd_v_wallman, State);
|
NewState = do_show_ui(gd_v_wallman, State),
|
||||||
|
ok = gd_v_wallman:to_front(),
|
||||||
|
NewState;
|
||||||
do_make_key2(Name, Bin, Transform,
|
do_make_key2(Name, Bin, Transform,
|
||||||
State = #s{wallet = Current, wallets = Wallets, pass = Pass}) ->
|
State = #s{wallet = Current, wallets = Wallets, pass = Pass}) ->
|
||||||
#wallet{name = WalletName, poas = POAs, keys = Keys} = Current,
|
#wallet{name = WalletName, poas = POAs, keys = Keys} = Current,
|
||||||
|
@ -361,6 +361,7 @@ refresh(State) ->
|
|||||||
|
|
||||||
wallman(State) ->
|
wallman(State) ->
|
||||||
ok = gd_con:show_ui(gd_v_wallman),
|
ok = gd_con:show_ui(gd_v_wallman),
|
||||||
|
ok = gd_v_wallman:to_front(),
|
||||||
State.
|
State.
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
-behavior(wx_object).
|
-behavior(wx_object).
|
||||||
%-behavior(gd_v).
|
%-behavior(gd_v).
|
||||||
-include_lib("wx/include/wx.hrl").
|
-include_lib("wx/include/wx.hrl").
|
||||||
-export([to_front/1, trouble/1]).
|
-export([to_front/0, to_front/1, first_run/0, trouble/1]).
|
||||||
-export([show/2]).
|
-export([show/2]).
|
||||||
-export([start_link/1]).
|
-export([start_link/1]).
|
||||||
-export([init/1, terminate/2, code_change/3,
|
-export([init/1, terminate/2, code_change/3,
|
||||||
@ -35,6 +35,12 @@
|
|||||||
|
|
||||||
%%% Interface
|
%%% Interface
|
||||||
|
|
||||||
|
-spec to_front() -> ok.
|
||||||
|
|
||||||
|
to_front() ->
|
||||||
|
wx_object:cast(?MODULE, to_front).
|
||||||
|
|
||||||
|
|
||||||
-spec to_front(Win) -> ok
|
-spec to_front(Win) -> ok
|
||||||
when Win :: wx:wx_object().
|
when Win :: wx:wx_object().
|
||||||
|
|
||||||
@ -42,6 +48,12 @@ to_front(Win) ->
|
|||||||
wx_object:cast(Win, to_front).
|
wx_object:cast(Win, to_front).
|
||||||
|
|
||||||
|
|
||||||
|
-spec first_run() -> ok.
|
||||||
|
|
||||||
|
first_run() ->
|
||||||
|
wx_object:cast(?MODULE, first_run).
|
||||||
|
|
||||||
|
|
||||||
-spec trouble(Info) -> ok
|
-spec trouble(Info) -> ok
|
||||||
when Info :: term().
|
when Info :: term().
|
||||||
|
|
||||||
@ -116,19 +128,6 @@ init({Prefs, Manifest}) ->
|
|||||||
ok = wxFrame:connect(Frame, command_button_clicked),
|
ok = wxFrame:connect(Frame, command_button_clicked),
|
||||||
ok = wxFrame:connect(Frame, close_window),
|
ok = wxFrame:connect(Frame, close_window),
|
||||||
ok = wxListBox:connect(Picker, command_listbox_doubleclicked),
|
ok = wxListBox:connect(Picker, command_listbox_doubleclicked),
|
||||||
Count = length(Manifest),
|
|
||||||
ok =
|
|
||||||
if
|
|
||||||
Count =:= 0 ->
|
|
||||||
self() ! wiz,
|
|
||||||
ok;
|
|
||||||
Count =:= 1 ->
|
|
||||||
self() ! open,
|
|
||||||
ok;
|
|
||||||
Count > 1 ->
|
|
||||||
true = wxFrame:show(Frame),
|
|
||||||
wxFrame:raise(Frame)
|
|
||||||
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,
|
||||||
@ -137,6 +136,7 @@ init({Prefs, Manifest}) ->
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%%% wx_object
|
%%% wx_object
|
||||||
|
|
||||||
handle_call(Unexpected, From, State) ->
|
handle_call(Unexpected, From, State) ->
|
||||||
@ -147,6 +147,9 @@ handle_cast(to_front, State = #s{frame = Frame}) ->
|
|||||||
ok = ensure_shown(Frame),
|
ok = ensure_shown(Frame),
|
||||||
ok = wxFrame:raise(Frame),
|
ok = wxFrame:raise(Frame),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
|
handle_cast(first_run, State) ->
|
||||||
|
NewState = do_first_run(State),
|
||||||
|
{noreply, NewState};
|
||||||
handle_cast({trouble, Info}, State) ->
|
handle_cast({trouble, Info}, State) ->
|
||||||
ok = handle_troubling(State, Info),
|
ok = handle_troubling(State, Info),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
@ -158,12 +161,6 @@ handle_cast(Unexpected, State) ->
|
|||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
||||||
handle_info(wiz, State) ->
|
|
||||||
NewState = do_wiz(State),
|
|
||||||
{noreply, NewState};
|
|
||||||
handle_info(open, State) ->
|
|
||||||
NewState = do_open(State),
|
|
||||||
{noreply, NewState};
|
|
||||||
handle_info(Unexpected, State) ->
|
handle_info(Unexpected, State) ->
|
||||||
ok = log(warning, "Unexpected info: ~tp~n", [Unexpected]),
|
ok = log(warning, "Unexpected info: ~tp~n", [Unexpected]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
@ -232,6 +229,20 @@ do_show(Manifest, State = #s{picker = Picker}) ->
|
|||||||
State#s{wallets = Manifest}.
|
State#s{wallets = Manifest}.
|
||||||
|
|
||||||
|
|
||||||
|
do_first_run(State = #s{frame = Frame, wallets = Manifest}) ->
|
||||||
|
Count = length(Manifest),
|
||||||
|
if
|
||||||
|
Count =:= 0 ->
|
||||||
|
do_wiz(State);
|
||||||
|
Count =:= 1 ->
|
||||||
|
do_open(State);
|
||||||
|
Count > 1 ->
|
||||||
|
true = wxFrame:show(Frame),
|
||||||
|
wxFrame:raise(Frame),
|
||||||
|
State
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
close_wiz(State = #s{frame = Frame, wiz = {Wiz, _}}) ->
|
close_wiz(State = #s{frame = Frame, wiz = {Wiz, _}}) ->
|
||||||
ok = wxWindow:destroy(Wiz),
|
ok = wxWindow:destroy(Wiz),
|
||||||
true = wxFrame:show(Frame),
|
true = wxFrame:show(Frame),
|
||||||
@ -274,8 +285,11 @@ do_open(State = #s{wallets = [#wr{pass = false, path = Path}], frame = Frame}) -
|
|||||||
State;
|
State;
|
||||||
do_open(State = #s{picker = Picker}) ->
|
do_open(State = #s{picker = Picker}) ->
|
||||||
case wxListBox:getSelection(Picker) of
|
case wxListBox:getSelection(Picker) of
|
||||||
-1 -> State;
|
-1 ->
|
||||||
Selected -> do_open2(Selected + 1, State)
|
State;
|
||||||
|
Selected ->
|
||||||
|
ok = do_open2(Selected + 1, State),
|
||||||
|
State
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_open2(Selected, State = #s{wallets = Wallets}) ->
|
do_open2(Selected, State = #s{wallets = Wallets}) ->
|
||||||
@ -284,8 +298,7 @@ do_open2(Selected, State = #s{wallets = Wallets}) ->
|
|||||||
do_open3(Path, State);
|
do_open3(Path, State);
|
||||||
#wr{pass = false, path = Path} ->
|
#wr{pass = false, path = Path} ->
|
||||||
ok = gd_con:open_wallet(Path, none),
|
ok = gd_con:open_wallet(Path, none),
|
||||||
ok = do_close(State),
|
do_close(State)
|
||||||
State
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_open3(Path, State = #s{frame = Frame, j = J}) ->
|
do_open3(Path, State = #s{frame = Frame, j = J}) ->
|
||||||
@ -310,24 +323,20 @@ do_open3(Path, State = #s{frame = Frame, j = J}) ->
|
|||||||
case wxTextCtrl:getValue(PassTx) of
|
case wxTextCtrl:getValue(PassTx) of
|
||||||
"" ->
|
"" ->
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok = wxDialog:destroy(Dialog),
|
||||||
ok = ensure_shown(Frame),
|
ensure_shown(Frame);
|
||||||
State;
|
|
||||||
Phrase ->
|
Phrase ->
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok = wxDialog:destroy(Dialog),
|
||||||
ok =
|
case gd_con:open_wallet(Path, Phrase) of
|
||||||
case gd_con:open_wallet(Path, Phrase) of
|
ok ->
|
||||||
ok ->
|
do_close(State);
|
||||||
do_close(State);
|
Error ->
|
||||||
Error ->
|
ok = ensure_shown(Frame),
|
||||||
ok = ensure_shown(Frame),
|
trouble(Error)
|
||||||
trouble(Error)
|
end
|
||||||
end,
|
|
||||||
State
|
|
||||||
end;
|
end;
|
||||||
?wxID_CANCEL ->
|
?wxID_CANCEL ->
|
||||||
ok = wxDialog:destroy(Dialog),
|
ok = wxDialog:destroy(Dialog),
|
||||||
ok = ensure_shown(Frame),
|
ensure_shown(Frame)
|
||||||
State
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user