From ad86fbe2cffa2bea07d004782e711932c5c91a79 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 3 Dec 2021 10:41:15 +0200 Subject: Improving identity use The URL checks for determining which identity was in use were a bit too page-specific. Now the URL prefix usage is applied more consistently. The identity toolbar menu is now more useful in that it allows both switching identities and stopping the use of the current identity. --- po/en.po | 2 +- res/lang/cs.bin | Bin 31087 -> 31081 bytes res/lang/de.bin | Bin 30094 -> 30088 bytes res/lang/en.bin | Bin 26191 -> 26185 bytes res/lang/eo.bin | Bin 25145 -> 25139 bytes res/lang/es.bin | Bin 29918 -> 29912 bytes res/lang/es_MX.bin | Bin 27250 -> 27244 bytes res/lang/fi.bin | Bin 29751 -> 29745 bytes res/lang/fr.bin | Bin 30898 -> 30892 bytes res/lang/gl.bin | Bin 29103 -> 29097 bytes res/lang/hu.bin | Bin 30923 -> 30917 bytes res/lang/ia.bin | Bin 28250 -> 28244 bytes res/lang/ie.bin | Bin 28838 -> 28832 bytes res/lang/isv.bin | Bin 24911 -> 24905 bytes res/lang/pl.bin | Bin 29526 -> 29520 bytes res/lang/ru.bin | Bin 44286 -> 44280 bytes res/lang/sk.bin | Bin 25247 -> 25241 bytes res/lang/sr.bin | Bin 43712 -> 43706 bytes res/lang/tok.bin | Bin 26960 -> 26954 bytes res/lang/tr.bin | Bin 29144 -> 29138 bytes res/lang/uk.bin | Bin 43631 -> 43625 bytes res/lang/zh_Hans.bin | Bin 25145 -> 25139 bytes res/lang/zh_Hant.bin | Bin 25343 -> 25337 bytes src/app.c | 4 ++- src/gmcerts.c | 16 +++++++++- src/ui/certlistwidget.c | 13 ++++---- src/ui/documentwidget.c | 9 ++++-- src/ui/root.c | 78 ++++++++++++++++++++++++++---------------------- src/ui/sidebarwidget.c | 59 +++++++++++++++++++----------------- 29 files changed, 108 insertions(+), 73 deletions(-) diff --git a/po/en.po b/po/en.po index 4e013941..6b604d61 100644 --- a/po/en.po +++ b/po/en.po @@ -639,7 +639,7 @@ msgstr "Export" # The %s represents the name of an identity. #, c-format msgid "ident.switch" -msgstr "Switch to %s" +msgstr "Use %s" msgid "heading.ident.use" msgstr "IDENTITY USAGE" diff --git a/res/lang/cs.bin b/res/lang/cs.bin index 7c08bcfe..cf37c7de 100644 Binary files a/res/lang/cs.bin and b/res/lang/cs.bin differ diff --git a/res/lang/de.bin b/res/lang/de.bin index e3f45a34..a9d497d7 100644 Binary files a/res/lang/de.bin and b/res/lang/de.bin differ diff --git a/res/lang/en.bin b/res/lang/en.bin index 0c65ffd3..5e24ab94 100644 Binary files a/res/lang/en.bin and b/res/lang/en.bin differ diff --git a/res/lang/eo.bin b/res/lang/eo.bin index 9edecafe..789c01c2 100644 Binary files a/res/lang/eo.bin and b/res/lang/eo.bin differ diff --git a/res/lang/es.bin b/res/lang/es.bin index 9e7d0585..7ca8e297 100644 Binary files a/res/lang/es.bin and b/res/lang/es.bin differ diff --git a/res/lang/es_MX.bin b/res/lang/es_MX.bin index 1dd95a4e..43a5bb77 100644 Binary files a/res/lang/es_MX.bin and b/res/lang/es_MX.bin differ diff --git a/res/lang/fi.bin b/res/lang/fi.bin index 1d5e4624..5a0ec586 100644 Binary files a/res/lang/fi.bin and b/res/lang/fi.bin differ diff --git a/res/lang/fr.bin b/res/lang/fr.bin index c0202489..329cae2b 100644 Binary files a/res/lang/fr.bin and b/res/lang/fr.bin differ diff --git a/res/lang/gl.bin b/res/lang/gl.bin index 34d16341..527de83b 100644 Binary files a/res/lang/gl.bin and b/res/lang/gl.bin differ diff --git a/res/lang/hu.bin b/res/lang/hu.bin index 2ab5484b..82257541 100644 Binary files a/res/lang/hu.bin and b/res/lang/hu.bin differ diff --git a/res/lang/ia.bin b/res/lang/ia.bin index c43aec10..5f1d7ab2 100644 Binary files a/res/lang/ia.bin and b/res/lang/ia.bin differ diff --git a/res/lang/ie.bin b/res/lang/ie.bin index 8a1d71e4..0d866d47 100644 Binary files a/res/lang/ie.bin and b/res/lang/ie.bin differ diff --git a/res/lang/isv.bin b/res/lang/isv.bin index e9978815..d30dcf4f 100644 Binary files a/res/lang/isv.bin and b/res/lang/isv.bin differ diff --git a/res/lang/pl.bin b/res/lang/pl.bin index b6de49f1..e9fd8460 100644 Binary files a/res/lang/pl.bin and b/res/lang/pl.bin differ diff --git a/res/lang/ru.bin b/res/lang/ru.bin index 7f153025..f8a69f51 100644 Binary files a/res/lang/ru.bin and b/res/lang/ru.bin differ diff --git a/res/lang/sk.bin b/res/lang/sk.bin index 35fdb2b1..9d0e9f04 100644 Binary files a/res/lang/sk.bin and b/res/lang/sk.bin differ diff --git a/res/lang/sr.bin b/res/lang/sr.bin index bd9ca450..bbaba1e9 100644 Binary files a/res/lang/sr.bin and b/res/lang/sr.bin differ diff --git a/res/lang/tok.bin b/res/lang/tok.bin index cb34ada6..517194d1 100644 Binary files a/res/lang/tok.bin and b/res/lang/tok.bin differ diff --git a/res/lang/tr.bin b/res/lang/tr.bin index 99dc6431..e0aef190 100644 Binary files a/res/lang/tr.bin and b/res/lang/tr.bin differ diff --git a/res/lang/uk.bin b/res/lang/uk.bin index edcafb7e..0c261c00 100644 Binary files a/res/lang/uk.bin and b/res/lang/uk.bin differ diff --git a/res/lang/zh_Hans.bin b/res/lang/zh_Hans.bin index 488cc64f..d31b280b 100644 Binary files a/res/lang/zh_Hans.bin and b/res/lang/zh_Hans.bin differ diff --git a/res/lang/zh_Hant.bin b/res/lang/zh_Hant.bin index edab200b..e06f4339 100644 Binary files a/res/lang/zh_Hant.bin and b/res/lang/zh_Hant.bin differ diff --git a/src/app.c b/src/app.c index 5b2e88bf..587efd00 100644 --- a/src/app.c +++ b/src/app.c @@ -3142,6 +3142,7 @@ iBool handleCommand_App(const char *cmd) { d->certs, findIdentity_GmCerts(d->certs, collect_Block(hexDecode_Rangecc(range_Command(cmd, "ident")))), url); + postCommand_App("navigate.reload"); postCommand_App("idents.changed"); return iTrue; } @@ -3154,6 +3155,7 @@ iBool handleCommand_App(const char *cmd) { else { setUse_GmIdentity(ident, collect_String(suffix_Command(cmd, "url")), iFalse); } + postCommand_App("navigate.reload"); postCommand_App("idents.changed"); return iTrue; } @@ -3164,7 +3166,7 @@ iBool handleCommand_App(const char *cmd) { const iGmIdentity *cur = identityForUrl_GmCerts(d->certs, docUrl); iGmIdentity *dst = findIdentity_GmCerts( d->certs, collect_Block(hexDecode_Rangecc(range_Command(cmd, "fp")))); - if (cur && dst && cur != dst) { + if (dst && cur != dst) { iString *useUrl = copy_String(findUse_GmIdentity(cur, docUrl)); if (isEmpty_String(useUrl)) { useUrl = copy_String(docUrl); diff --git a/src/gmcerts.c b/src/gmcerts.c index 345c36e0..ed4759be 100644 --- a/src/gmcerts.c +++ b/src/gmcerts.c @@ -146,6 +146,7 @@ iBool isUsed_GmIdentity(const iGmIdentity *d) { } iBool isUsedOn_GmIdentity(const iGmIdentity *d, const iString *url) { +#if 0 size_t pos = iInvalidPos; locate_StringSet(d->useUrls, url, &pos); if (pos < size_StringSet(d->useUrls)) { @@ -159,6 +160,12 @@ iBool isUsedOn_GmIdentity(const iGmIdentity *d, const iString *url) { return iTrue; } } +#endif + iConstForEach(StringSet, i, d->useUrls) { + if (startsWithCase_String(url, cstr_String(i.value))) { + return iTrue; + } + } return iFalse; } @@ -193,7 +200,13 @@ void setUse_GmIdentity(iGmIdentity *d, const iString *url, iBool use) { iAssert(wasInserted); } else { - remove_StringSet(d->useUrls, url); + iForEach(Array, i, &d->useUrls->strings.values) { + iString *used = i.value; + if (startsWithCase_String(url, cstr_String(used))) { + deinit_String(used); + remove_ArrayIterator(&i); + } + } } } @@ -202,6 +215,7 @@ void clearUse_GmIdentity(iGmIdentity *d) { } const iString *findUse_GmIdentity(const iGmIdentity *d, const iString *url) { + if (!d) return NULL; iConstForEach(StringSet, using, d->useUrls) { if (startsWith_String(url, cstr_String(using.value))) { return using.value; diff --git a/src/ui/certlistwidget.c b/src/ui/certlistwidget.c index c67203e3..7c140c19 100644 --- a/src/ui/certlistwidget.c +++ b/src/ui/certlistwidget.c @@ -113,7 +113,7 @@ static void updateContextMenu_CertListWidget_(iCertListWidget *d) { iBool usedOnCurrentPage = iFalse; iConstForEach(StringSet, i, ident->useUrls) { const iString *url = i.value; - usedOnCurrentPage |= equalCase_String(docUrl, url); + usedOnCurrentPage |= startsWithCase_String(docUrl, cstr_String(url)); iRangecc urlStr = range_String(url); if (startsWith_Rangecc(urlStr, "gemini://")) { urlStr.start += 9; /* omit the default scheme */ @@ -128,6 +128,9 @@ static void updateContextMenu_CertListWidget_(iCertListWidget *d) { if (!usedOnCurrentPage) { remove_Array(items, 1); } + else { + remove_Array(items, 0); + } } destroy_Widget(d->menu); d->menu = makeMenu_Widget(as_Widget(d), data_Array(items), size_Array(items)); @@ -166,8 +169,8 @@ static iBool processEvent_CertListWidget_(iCertListWidget *d, const SDL_Event *e return iTrue; } else if (isCommand_Widget(w, ev, "ident.use")) { - iGmIdentity * ident = menuIdentity_CertListWidget_(d); - const iString *tabUrl = url_DocumentWidget(document_App()); + iGmIdentity *ident = menuIdentity_CertListWidget_(d); + const iString *tabUrl = urlQueryStripped_String(url_DocumentWidget(document_App())); if (ident) { if (argLabel_Command(cmd, "clear")) { clearUse_GmIdentity(ident); @@ -388,7 +391,6 @@ void init_CertListWidget(iCertListWidget *d) { init_ListWidget(&d->list); setId_Widget(w, "certlist"); setBackgroundColor_Widget(w, none_ColorId); - setItemHeight_ListWidget(&d->list, 3.5f * lineHeight_Text(default_FontId)); d->itemFonts[0] = uiContent_FontId; d->itemFonts[1] = uiContentBold_FontId; #if defined (iPlatformMobile) @@ -397,6 +399,7 @@ void init_CertListWidget(iCertListWidget *d) { d->itemFonts[1] = uiLabelBigBold_FontId; } #endif + updateItemHeight_CertListWidget(d); d->menu = NULL; d->contextItem = NULL; d->contextIndex = iInvalidPos; @@ -443,7 +446,7 @@ iBool updateItems_CertListWidget(iCertListWidget *d) { cstr_String(&ident->notes)); } item->listItem.isSelected = isActive; - if (isUsedOnDomain_GmIdentity(ident, tabHost)) { + if (!isActive && isUsedOnDomain_GmIdentity(ident, tabHost)) { item->indent = 1; /* will be highlighted */ } addItem_ListWidget(&d->list, item); diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 3fb8498b..95286566 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -1289,8 +1289,13 @@ static void showErrorPage_DocumentWidget_(iDocumentWidget *d, enum iGmStatusCode if (category_GmStatusCode(code) == categoryClientCertificate_GmStatus) { makeFooterButtons_DocumentWidget_( d, - (iMenuItem[]){ { leftHalf_Icon " ${menu.show.identities}", '4', KMOD_PRIMARY, "sidebar.mode arg:3 show:1" }, - { person_Icon " ${menu.identity.new}", newIdentity_KeyShortcut, "ident.new" } }, + (iMenuItem[]){ + { leftHalf_Icon " ${menu.show.identities}", + '4', + KMOD_PRIMARY, + deviceType_App() == desktop_AppDeviceType ? "sidebar.mode arg:3 show:1" + : "preferences idents:1" }, + { person_Icon " ${menu.identity.new}", newIdentity_KeyShortcut, "ident.new" } }, 2); } /* Make a new document for the error page.*/ diff --git a/src/ui/root.c b/src/ui/root.c index 5df4b36f..f722df94 100644 --- a/src/ui/root.c +++ b/src/ui/root.c @@ -344,41 +344,47 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) { if (ident) { str = copy_String(name_GmIdentity(ident)); if (!isEmpty_String(&ident->notes)) { - appendFormat_String(str, "\n%s%s", escape_Color(uiAnnotation_ColorId), - cstr_String(&ident->notes)); + appendFormat_String(str, "\n\x1b[0m" uiHeading_ColorEscape "%s", cstr_String(&ident->notes)); } } - pushBackN_Array( + pushBack_Array( &items, - (iMenuItem[]){ { format_CStr("///" uiHeading_ColorEscape "%s", - str ? cstr_String(str) : "${menu.identity.notactive}") }, - { "---" } }, - 2); + &(iMenuItem){ format_CStr("```" uiHeading_ColorEscape "\x1b[1m%s", + str ? cstr_String(str) : "${menu.identity.notactive}") }); + if (ident && isUsedOn_GmIdentity(ident, docUrl)) { + pushBack_Array(&items, + &(iMenuItem){ close_Icon " ${ident.stopuse}", + 0, + 0, + format_CStr("ident.signout ident:%s url:%s", + cstr_String(fp), + cstr_String(docUrl)) }); + } + pushBack_Array(&items, &(iMenuItem){ "---" }); delete_String(str); /* Alternate identities. */ - if (ident) { - const iString *site = collectNewRange_String(urlRoot_String(docUrl)); - iBool haveAlts = iFalse; - iConstForEach(StringArray, i, strings_SiteSpec(site, usedIdentities_SiteSpecKey)) { - if (!equal_String(i.value, fp)) { - const iBlock *otherFp = collect_Block(hexDecode_Rangecc(range_String(i.value))); - const iGmIdentity *other = findIdentity_GmCerts(certs_App(), otherFp); - if (other) { - pushBack_Array( - &items, - &(iMenuItem){ - format_CStr(translateCStr_Lang("\U0001f816 ${ident.switch}"), - cstr_String(name_GmIdentity(other))), - 0, - 0, - format_CStr("ident.switch fp:%s", cstr_String(i.value)) }); - haveAlts = iTrue; - } + const iString *site = collectNewRange_String(urlRoot_String(docUrl)); + iBool haveAlts = iFalse; + iConstForEach(StringArray, i, strings_SiteSpec(site, usedIdentities_SiteSpecKey)) { + if (!fp || !equal_String(i.value, fp)) { + const iBlock *otherFp = collect_Block(hexDecode_Rangecc(range_String(i.value))); + const iGmIdentity *other = findIdentity_GmCerts(certs_App(), otherFp); + if (other && other != ident) { + pushBack_Array( + &items, + &(iMenuItem){ + format_CStr(translateCStr_Lang("\U0001f816 ${ident.switch}"), + format_CStr("\x1b[1m%s", + cstr_String(name_GmIdentity(other)))), + 0, + 0, + format_CStr("ident.switch fp:%s", cstr_String(i.value)) }); + haveAlts = iTrue; } } - if (haveAlts) { - pushBack_Array(&items, &(iMenuItem){ "---" }); - } + } + if (haveAlts) { + pushBack_Array(&items, &(iMenuItem){ "---" }); } iSidebarWidget *sidebar = findWidget_App("sidebar"); pushBackN_Array( @@ -388,14 +394,14 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) { { "${menu.identity.import}", SDLK_i, KMOD_PRIMARY | KMOD_SHIFT, "ident.import" }, { "---" } }, 3); if (deviceType_App() == desktop_AppDeviceType) { - pushBack_Array(&items, &(iMenuItem) - { isVisible_Widget(sidebar) && mode_SidebarWidget(sidebar) == identities_SidebarMode - ? leftHalf_Icon " ${menu.hide.identities}" - : leftHalf_Icon " ${menu.show.identities}", - 0, - 0, - //deviceType_App() == phone_AppDeviceType ? "toolbar.showident" - "sidebar.mode arg:3 toggle:1" }); + pushBack_Array(&items, + &(iMenuItem){ isVisible_Widget(sidebar) && mode_SidebarWidget(sidebar) == + identities_SidebarMode + ? leftHalf_Icon " ${menu.hide.identities}" + : leftHalf_Icon " ${menu.show.identities}", + 0, + 0, + "sidebar.mode arg:3 toggle:1" }); } else { pushBack_Array(&items, &(iMenuItem){ gear_Icon " ${menu.identities}", 0, 0, diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 9b94f4d9..13fc33b1 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c @@ -591,6 +591,9 @@ iBool setMode_SidebarWidget(iSidebarWidget *d, enum iSidebarMode mode) { if (d->mode == mode) { return iFalse; } + if (mode == identities_SidebarMode && deviceType_App() != desktop_AppDeviceType) { + return iFalse; /* Identities are in Settings. */ + } if (d->mode >= 0 && d->mode < max_SidebarMode) { d->modeScroll[d->mode] = scrollPos_ListWidget(list_SidebarWidget_(d)); /* saved for later */ } @@ -705,33 +708,34 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { d->certList = NULL; d->actions = NULL; d->closedFolders = new_IntSet(); - /* On a phone, the right sidebar is used exclusively for Identities. */ + /* On a phone, the right sidebar is not used. */ const iBool isPhone = deviceType_App() == phone_AppDeviceType; - if (!isPhone || d->side == left_SidebarSide) { - iWidget *buttons = new_Widget(); - setId_Widget(buttons, "buttons"); - setDrawBufferEnabled_Widget(buttons, iTrue); - for (int i = 0; i < max_SidebarMode; i++) { - if (i == identities_SidebarMode && deviceType_App() != desktop_AppDeviceType) { - /* On mobile, identities are managed via Settings. */ - continue; - } - d->modeButtons[i] = addChildFlags_Widget( - buttons, - iClob(new_LabelWidget( - tightModeLabels_[i], - format_CStr("%s.mode arg:%d", cstr_String(id_Widget(w)), i))), - frameless_WidgetFlag | noBackground_WidgetFlag); - } - setButtonFont_SidebarWidget(d, isPhone ? uiLabelBig_FontId : uiLabel_FontId); - addChildFlags_Widget(vdiv, - iClob(buttons), - arrangeHorizontal_WidgetFlag | - resizeWidthOfChildren_WidgetFlag | - arrangeHeight_WidgetFlag | resizeToParentWidth_WidgetFlag); // | -// drawBackgroundToHorizontalSafeArea_WidgetFlag); - setBackgroundColor_Widget(buttons, uiBackgroundSidebar_ColorId); + //if (!isPhone || d->side == left_SidebarSide) { + iWidget *buttons = new_Widget(); + setId_Widget(buttons, "buttons"); + setDrawBufferEnabled_Widget(buttons, iTrue); + for (int i = 0; i < max_SidebarMode; i++) { + if (i == identities_SidebarMode && deviceType_App() != desktop_AppDeviceType) { + /* On mobile, identities are managed via Settings. */ + continue; + } + d->modeButtons[i] = addChildFlags_Widget( + buttons, + iClob(new_LabelWidget( + tightModeLabels_[i], + format_CStr("%s.mode arg:%d", cstr_String(id_Widget(w)), i))), + frameless_WidgetFlag | noBackground_WidgetFlag); } + setButtonFont_SidebarWidget(d, isPhone ? uiLabelBig_FontId : uiLabel_FontId); + addChildFlags_Widget(vdiv, + iClob(buttons), + arrangeHorizontal_WidgetFlag | + resizeWidthOfChildren_WidgetFlag | + arrangeHeight_WidgetFlag | resizeToParentWidth_WidgetFlag); // | +// drawBackgroundToHorizontalSafeArea_WidgetFlag); + setBackgroundColor_Widget(buttons, uiBackgroundSidebar_ColorId); +// } +#if 0 else { iLabelWidget *heading = new_LabelWidget(person_Icon " ${sidebar.identities}", NULL); checkIcon_LabelWidget(heading); @@ -742,6 +746,7 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { drawBackgroundToHorizontalSafeArea_WidgetFlag), uiLabelLargeBold_FontId); } +#endif iWidget *content = new_Widget(); setFlags_Widget(content, resizeChildren_WidgetFlag, iTrue); iWidget *listAndActions = makeVDiv_Widget(); @@ -771,8 +776,8 @@ void init_SidebarWidget(iSidebarWidget *d, enum iSidebarSide side) { addChildFlags_Widget(content, iClob(d->blank), resizeChildren_WidgetFlag); addChildFlags_Widget(vdiv, iClob(content), expand_WidgetFlag); setMode_SidebarWidget(d, - deviceType_App() == phone_AppDeviceType && d->side == right_SidebarSide ? - identities_SidebarMode : bookmarks_SidebarMode); + /*deviceType_App() == phone_AppDeviceType && d->side == right_SidebarSide ? + identities_SidebarMode :*/ bookmarks_SidebarMode); d->resizer = addChildFlags_Widget(w, iClob(new_Widget()), -- cgit v1.2.3