Add clipboard and default browser interaction

This commit is contained in:
Craig Everett 2024-09-27 10:41:00 +09:00
parent 9d092e7f55
commit cb21cefb24
6 changed files with 60 additions and 11 deletions

View File

@ -4,5 +4,5 @@
{included_applications,[]},
{applications,[stdlib,kernel]},
{vsn,"0.1.0"},
{modules,[clutch,gmc_con,gmc_gui,gmc_sup]},
{modules,[clutch,gmc_con,gmc_gui,gmc_jt,gmc_key_master,gmc_sup]},
{mod,{clutch,[]}}]}.

View File

@ -6,7 +6,7 @@
-vsn("0.1.0").
-behavior(application).
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
-export([ts/0]).

View File

@ -7,7 +7,7 @@
-module(gmc_con).
-vsn("0.1.0").
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
-behavior(gen_server).
@ -250,6 +250,8 @@ code_change(_, State, _) ->
{ok, State}.
terminate(normal, _) ->
zx:stop();
terminate(Reason, State) ->
ok = log(info, "Reason: ~tp, State: ~tp", [Reason, State]),
zx:stop().

View File

@ -9,7 +9,7 @@
-module(gmc_gui).
-vsn("0.1.0").
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
-behavior(wx_object).
@ -96,6 +96,10 @@ init(Prefs) ->
_ = wxSizer:add(BalanceSz, BalanceL, zxw:flags(base)),
_ = wxSizer:add(BalanceSz, BalanceT, zxw:flags(wide)),
NumbersSz = wxBoxSizer:new(?wxVERTICAL),
_ = wxSizer:add(NumbersSz, ID_Sz, zxw:flags(wide)),
_ = wxSizer:add(NumbersSz, BalanceSz, zxw:flags(wide)),
ButtonTemplates =
[{make_key, J("Create")},
{recover, J("Recover")},
@ -105,6 +109,8 @@ init(Prefs) ->
{send, J("Send Money")},
{recv, J("Receive Money")},
{grids, J("GRIDS URL")},
{copy, J("Copy")},
{www, J("WWW")},
{refresh, J("Refresh")}],
MakeButton =
@ -116,9 +122,16 @@ init(Prefs) ->
Buttons = lists:map(MakeButton, ButtonTemplates),
AccountSz = wxBoxSizer:new(?wxHORIZONTAL),
DetailsSz = wxBoxSizer:new(?wxHORIZONTAL),
ActionsSz = wxBoxSizer:new(?wxHORIZONTAL),
HistorySz = wxBoxSizer:new(?wxVERTICAL),
#w{wx = CopyBn} = lists:keyfind(copy, #w.name, Buttons),
#w{wx = WWW_Bn} = lists:keyfind(www, #w.name, Buttons),
_ = wxSizer:add(DetailsSz, NumbersSz, zxw:flags(wide)),
_ = wxSizer:add(DetailsSz, CopyBn, zxw:flags(base)),
_ = wxSizer:add(DetailsSz, WWW_Bn, zxw:flags(base)),
#w{wx = MakeBn} = lists:keyfind(make_key, #w.name, Buttons),
#w{wx = RecoBn} = lists:keyfind(recover, #w.name, Buttons),
#w{wx = MnemBn} = lists:keyfind(mnemonic, #w.name, Buttons),
@ -140,11 +153,9 @@ init(Prefs) ->
#w{wx = Refresh} = lists:keyfind(refresh, #w.name, Buttons),
_ = wxSizer:add(HistorySz, Refresh, zxw:flags(base)),
_ = wxSizer:add(MainSz, AccountSz, zxw:flags(base)),
_ = wxSizer:add(MainSz, Picker, zxw:flags(wide)),
_ = wxSizer:add(MainSz, ID_Sz, zxw:flags(base)),
_ = wxSizer:add(MainSz, BalanceSz, zxw:flags(base)),
_ = wxSizer:add(MainSz, DetailsSz, zxw:flags(base)),
_ = wxSizer:add(MainSz, ActionsSz, zxw:flags(base)),
_ = wxSizer:add(MainSz, HistorySz, [{proportion, 3}, {flag, ?wxEXPAND}]),
ok = wxFrame:setSizer(Frame, MainSz),
@ -267,6 +278,8 @@ handle_event(#wx{event = #wxCommand{type = command_button_clicked},
#w{name = mnemonic} -> show_mnemonic(State);
#w{name = rename} -> rename_key(State);
#w{name = drop_key} -> drop_key(State);
#w{name = copy} -> copy(State);
#w{name = www} -> www(State);
#w{name = grids} -> grids_dialogue(State);
#w{name = Name} -> handle_button(Name, State);
false -> State
@ -302,6 +315,8 @@ code_change(_, State, _) ->
{ok, State}.
terminate(wx_deleted, _) ->
wx:destroy();
terminate(Reason, State) ->
ok = log(info, "Reason: ~tp, State: ~tp", [Reason, State]),
wx:destroy().
@ -516,6 +531,38 @@ drop_key(Selected, State = #s{frame = Frame, j = J, accounts = Accounts}) ->
State.
copy(State = #s{id = {_, #w{wx = ID_T}}}) ->
String = wxStaticText:getLabel(ID_T),
CB = wxClipboard:get(),
ok =
case wxClipboard:open(CB) of
true ->
Text = wxTextDataObject:new([{text, String}]),
case wxClipboard:setData(CB, Text) of
true ->
R = wxClipboard:flush(CB),
log(info, "Address copied to system clipboard. Flushed: ~p", [R]);
false ->
log(info, "Failed to copy to clipboard")
end,
ok = wxClipboard:close(CB);
false ->
log(info, "Failed to acquire the clipboard.")
end,
State.
www(State = #s{id = {_, #w{wx = ID_T}}}) ->
String = wxStaticText:getLabel(ID_T),
URL = unicode:characters_to_list(["https://aescan.io/accounts/", String]),
ok =
case wx_misc:launchDefaultBrowser(URL) of
true -> log(info, "Opened in browser: ~ts", [URL]);
false -> log(info, "Failed to open browser: ~ts", [URL])
end,
State.
grids_dialogue(State = #s{frame = Frame, j = J}) ->
tell("Handle GRIDS URL"),
% ok =

View File

@ -15,7 +15,7 @@
-vsn("0.1.0").
-behaviour(supervisor).
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
-export([start_link/0]).

View File

@ -2,8 +2,8 @@
{type,gui}.
{modules,[]}.
{prefix,"gmc"}.
{desc,"A desktop client for the Gajumaru network of blockchain networks"}.
{author,"Craig Everett"}.
{desc,"A desktop client for the Gajumaru network of blockchain networks"}.
{package_id,{"otpr","clutch",{0,1,0}}}.
{deps,[{"otpr","erl_base58",{0,1,0}},
{"otpr","aeserialization",{0,1,0}},
@ -12,8 +12,8 @@
{"otpr","zxwidgets",{1,0,1}}]}.
{key_name,none}.
{a_email,"craigeverett@qpq.swiss"}.
{c_email,"craigeverett@qpq.swiss"}.
{copyright,"Craig Everett"}.
{c_email,"info@qpq.swiss"}.
{copyright,"QPQ AG"}.
{file_exts,[]}.
{license,"GPL-3.0-or-later"}.
{repo_url,"https://gitlab.com/ioecs/clutch"}.