bjomarks-gui: the desktop client of bjomarks
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
0651305b87
19 changed files with 4300 additions and 0 deletions
13
.gitignore
vendored
Normal file
13
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
.bjo/
|
||||||
|
*.dll
|
||||||
|
*.exe
|
||||||
|
*.pdb
|
||||||
|
*.bjobuild
|
||||||
|
*.runtimeconfig.json
|
||||||
|
*.deps.json
|
||||||
|
# Native executables, and the output of bjo publish.
|
||||||
|
/src/main
|
||||||
|
/tests/app
|
||||||
|
/tests/screenshots
|
||||||
|
/publish/
|
||||||
|
/publish-android/
|
||||||
373
LICENSE
Normal file
373
LICENSE
Normal file
|
|
@ -0,0 +1,373 @@
|
||||||
|
Mozilla Public License Version 2.0
|
||||||
|
==================================
|
||||||
|
|
||||||
|
1. Definitions
|
||||||
|
--------------
|
||||||
|
|
||||||
|
1.1. "Contributor"
|
||||||
|
means each individual or legal entity that creates, contributes to
|
||||||
|
the creation of, or owns Covered Software.
|
||||||
|
|
||||||
|
1.2. "Contributor Version"
|
||||||
|
means the combination of the Contributions of others (if any) used
|
||||||
|
by a Contributor and that particular Contributor's Contribution.
|
||||||
|
|
||||||
|
1.3. "Contribution"
|
||||||
|
means Covered Software of a particular Contributor.
|
||||||
|
|
||||||
|
1.4. "Covered Software"
|
||||||
|
means Source Code Form to which the initial Contributor has attached
|
||||||
|
the notice in Exhibit A, the Executable Form of such Source Code
|
||||||
|
Form, and Modifications of such Source Code Form, in each case
|
||||||
|
including portions thereof.
|
||||||
|
|
||||||
|
1.5. "Incompatible With Secondary Licenses"
|
||||||
|
means
|
||||||
|
|
||||||
|
(a) that the initial Contributor has attached the notice described
|
||||||
|
in Exhibit B to the Covered Software; or
|
||||||
|
|
||||||
|
(b) that the Covered Software was made available under the terms of
|
||||||
|
version 1.1 or earlier of the License, but not also under the
|
||||||
|
terms of a Secondary License.
|
||||||
|
|
||||||
|
1.6. "Executable Form"
|
||||||
|
means any form of the work other than Source Code Form.
|
||||||
|
|
||||||
|
1.7. "Larger Work"
|
||||||
|
means a work that combines Covered Software with other material, in
|
||||||
|
a separate file or files, that is not Covered Software.
|
||||||
|
|
||||||
|
1.8. "License"
|
||||||
|
means this document.
|
||||||
|
|
||||||
|
1.9. "Licensable"
|
||||||
|
means having the right to grant, to the maximum extent possible,
|
||||||
|
whether at the time of the initial grant or subsequently, any and
|
||||||
|
all of the rights conveyed by this License.
|
||||||
|
|
||||||
|
1.10. "Modifications"
|
||||||
|
means any of the following:
|
||||||
|
|
||||||
|
(a) any file in Source Code Form that results from an addition to,
|
||||||
|
deletion from, or modification of the contents of Covered
|
||||||
|
Software; or
|
||||||
|
|
||||||
|
(b) any new file in Source Code Form that contains any Covered
|
||||||
|
Software.
|
||||||
|
|
||||||
|
1.11. "Patent Claims" of a Contributor
|
||||||
|
means any patent claim(s), including without limitation, method,
|
||||||
|
process, and apparatus claims, in any patent Licensable by such
|
||||||
|
Contributor that would be infringed, but for the grant of the
|
||||||
|
License, by the making, using, selling, offering for sale, having
|
||||||
|
made, import, or transfer of either its Contributions or its
|
||||||
|
Contributor Version.
|
||||||
|
|
||||||
|
1.12. "Secondary License"
|
||||||
|
means either the GNU General Public License, Version 2.0, the GNU
|
||||||
|
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||||
|
Public License, Version 3.0, or any later versions of those
|
||||||
|
licenses.
|
||||||
|
|
||||||
|
1.13. "Source Code Form"
|
||||||
|
means the form of the work preferred for making modifications.
|
||||||
|
|
||||||
|
1.14. "You" (or "Your")
|
||||||
|
means an individual or a legal entity exercising rights under this
|
||||||
|
License. For legal entities, "You" includes any entity that
|
||||||
|
controls, is controlled by, or is under common control with You. For
|
||||||
|
purposes of this definition, "control" means (a) the power, direct
|
||||||
|
or indirect, to cause the direction or management of such entity,
|
||||||
|
whether by contract or otherwise, or (b) ownership of more than
|
||||||
|
fifty percent (50%) of the outstanding shares or beneficial
|
||||||
|
ownership of such entity.
|
||||||
|
|
||||||
|
2. License Grants and Conditions
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
|
2.1. Grants
|
||||||
|
|
||||||
|
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||||
|
non-exclusive license:
|
||||||
|
|
||||||
|
(a) under intellectual property rights (other than patent or trademark)
|
||||||
|
Licensable by such Contributor to use, reproduce, make available,
|
||||||
|
modify, display, perform, distribute, and otherwise exploit its
|
||||||
|
Contributions, either on an unmodified basis, with Modifications, or
|
||||||
|
as part of a Larger Work; and
|
||||||
|
|
||||||
|
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||||
|
for sale, have made, import, and otherwise transfer either its
|
||||||
|
Contributions or its Contributor Version.
|
||||||
|
|
||||||
|
2.2. Effective Date
|
||||||
|
|
||||||
|
The licenses granted in Section 2.1 with respect to any Contribution
|
||||||
|
become effective for each Contribution on the date the Contributor first
|
||||||
|
distributes such Contribution.
|
||||||
|
|
||||||
|
2.3. Limitations on Grant Scope
|
||||||
|
|
||||||
|
The licenses granted in this Section 2 are the only rights granted under
|
||||||
|
this License. No additional rights or licenses will be implied from the
|
||||||
|
distribution or licensing of Covered Software under this License.
|
||||||
|
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||||
|
Contributor:
|
||||||
|
|
||||||
|
(a) for any code that a Contributor has removed from Covered Software;
|
||||||
|
or
|
||||||
|
|
||||||
|
(b) for infringements caused by: (i) Your and any other third party's
|
||||||
|
modifications of Covered Software, or (ii) the combination of its
|
||||||
|
Contributions with other software (except as part of its Contributor
|
||||||
|
Version); or
|
||||||
|
|
||||||
|
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||||
|
its Contributions.
|
||||||
|
|
||||||
|
This License does not grant any rights in the trademarks, service marks,
|
||||||
|
or logos of any Contributor (except as may be necessary to comply with
|
||||||
|
the notice requirements in Section 3.4).
|
||||||
|
|
||||||
|
2.4. Subsequent Licenses
|
||||||
|
|
||||||
|
No Contributor makes additional grants as a result of Your choice to
|
||||||
|
distribute the Covered Software under a subsequent version of this
|
||||||
|
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||||
|
permitted under the terms of Section 3.3).
|
||||||
|
|
||||||
|
2.5. Representation
|
||||||
|
|
||||||
|
Each Contributor represents that the Contributor believes its
|
||||||
|
Contributions are its original creation(s) or it has sufficient rights
|
||||||
|
to grant the rights to its Contributions conveyed by this License.
|
||||||
|
|
||||||
|
2.6. Fair Use
|
||||||
|
|
||||||
|
This License is not intended to limit any rights You have under
|
||||||
|
applicable copyright doctrines of fair use, fair dealing, or other
|
||||||
|
equivalents.
|
||||||
|
|
||||||
|
2.7. Conditions
|
||||||
|
|
||||||
|
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||||
|
in Section 2.1.
|
||||||
|
|
||||||
|
3. Responsibilities
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
3.1. Distribution of Source Form
|
||||||
|
|
||||||
|
All distribution of Covered Software in Source Code Form, including any
|
||||||
|
Modifications that You create or to which You contribute, must be under
|
||||||
|
the terms of this License. You must inform recipients that the Source
|
||||||
|
Code Form of the Covered Software is governed by the terms of this
|
||||||
|
License, and how they can obtain a copy of this License. You may not
|
||||||
|
attempt to alter or restrict the recipients' rights in the Source Code
|
||||||
|
Form.
|
||||||
|
|
||||||
|
3.2. Distribution of Executable Form
|
||||||
|
|
||||||
|
If You distribute Covered Software in Executable Form then:
|
||||||
|
|
||||||
|
(a) such Covered Software must also be made available in Source Code
|
||||||
|
Form, as described in Section 3.1, and You must inform recipients of
|
||||||
|
the Executable Form how they can obtain a copy of such Source Code
|
||||||
|
Form by reasonable means in a timely manner, at a charge no more
|
||||||
|
than the cost of distribution to the recipient; and
|
||||||
|
|
||||||
|
(b) You may distribute such Executable Form under the terms of this
|
||||||
|
License, or sublicense it under different terms, provided that the
|
||||||
|
license for the Executable Form does not attempt to limit or alter
|
||||||
|
the recipients' rights in the Source Code Form under this License.
|
||||||
|
|
||||||
|
3.3. Distribution of a Larger Work
|
||||||
|
|
||||||
|
You may create and distribute a Larger Work under terms of Your choice,
|
||||||
|
provided that You also comply with the requirements of this License for
|
||||||
|
the Covered Software. If the Larger Work is a combination of Covered
|
||||||
|
Software with a work governed by one or more Secondary Licenses, and the
|
||||||
|
Covered Software is not Incompatible With Secondary Licenses, this
|
||||||
|
License permits You to additionally distribute such Covered Software
|
||||||
|
under the terms of such Secondary License(s), so that the recipient of
|
||||||
|
the Larger Work may, at their option, further distribute the Covered
|
||||||
|
Software under the terms of either this License or such Secondary
|
||||||
|
License(s).
|
||||||
|
|
||||||
|
3.4. Notices
|
||||||
|
|
||||||
|
You may not remove or alter the substance of any license notices
|
||||||
|
(including copyright notices, patent notices, disclaimers of warranty,
|
||||||
|
or limitations of liability) contained within the Source Code Form of
|
||||||
|
the Covered Software, except that You may alter any license notices to
|
||||||
|
the extent required to remedy known factual inaccuracies.
|
||||||
|
|
||||||
|
3.5. Application of Additional Terms
|
||||||
|
|
||||||
|
You may choose to offer, and to charge a fee for, warranty, support,
|
||||||
|
indemnity or liability obligations to one or more recipients of Covered
|
||||||
|
Software. However, You may do so only on Your own behalf, and not on
|
||||||
|
behalf of any Contributor. You must make it absolutely clear that any
|
||||||
|
such warranty, support, indemnity, or liability obligation is offered by
|
||||||
|
You alone, and You hereby agree to indemnify every Contributor for any
|
||||||
|
liability incurred by such Contributor as a result of warranty, support,
|
||||||
|
indemnity or liability terms You offer. You may include additional
|
||||||
|
disclaimers of warranty and limitations of liability specific to any
|
||||||
|
jurisdiction.
|
||||||
|
|
||||||
|
4. Inability to Comply Due to Statute or Regulation
|
||||||
|
---------------------------------------------------
|
||||||
|
|
||||||
|
If it is impossible for You to comply with any of the terms of this
|
||||||
|
License with respect to some or all of the Covered Software due to
|
||||||
|
statute, judicial order, or regulation then You must: (a) comply with
|
||||||
|
the terms of this License to the maximum extent possible; and (b)
|
||||||
|
describe the limitations and the code they affect. Such description must
|
||||||
|
be placed in a text file included with all distributions of the Covered
|
||||||
|
Software under this License. Except to the extent prohibited by statute
|
||||||
|
or regulation, such description must be sufficiently detailed for a
|
||||||
|
recipient of ordinary skill to be able to understand it.
|
||||||
|
|
||||||
|
5. Termination
|
||||||
|
--------------
|
||||||
|
|
||||||
|
5.1. The rights granted under this License will terminate automatically
|
||||||
|
if You fail to comply with any of its terms. However, if You become
|
||||||
|
compliant, then the rights granted under this License from a particular
|
||||||
|
Contributor are reinstated (a) provisionally, unless and until such
|
||||||
|
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||||
|
ongoing basis, if such Contributor fails to notify You of the
|
||||||
|
non-compliance by some reasonable means prior to 60 days after You have
|
||||||
|
come back into compliance. Moreover, Your grants from a particular
|
||||||
|
Contributor are reinstated on an ongoing basis if such Contributor
|
||||||
|
notifies You of the non-compliance by some reasonable means, this is the
|
||||||
|
first time You have received notice of non-compliance with this License
|
||||||
|
from such Contributor, and You become compliant prior to 30 days after
|
||||||
|
Your receipt of the notice.
|
||||||
|
|
||||||
|
5.2. If You initiate litigation against any entity by asserting a patent
|
||||||
|
infringement claim (excluding declaratory judgment actions,
|
||||||
|
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||||
|
directly or indirectly infringes any patent, then the rights granted to
|
||||||
|
You by any and all Contributors for the Covered Software under Section
|
||||||
|
2.1 of this License shall terminate.
|
||||||
|
|
||||||
|
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||||
|
end user license agreements (excluding distributors and resellers) which
|
||||||
|
have been validly granted by You or Your distributors under this License
|
||||||
|
prior to termination shall survive termination.
|
||||||
|
|
||||||
|
************************************************************************
|
||||||
|
* *
|
||||||
|
* 6. Disclaimer of Warranty *
|
||||||
|
* ------------------------- *
|
||||||
|
* *
|
||||||
|
* Covered Software is provided under this License on an "as is" *
|
||||||
|
* basis, without warranty of any kind, either expressed, implied, or *
|
||||||
|
* statutory, including, without limitation, warranties that the *
|
||||||
|
* Covered Software is free of defects, merchantable, fit for a *
|
||||||
|
* particular purpose or non-infringing. The entire risk as to the *
|
||||||
|
* quality and performance of the Covered Software is with You. *
|
||||||
|
* Should any Covered Software prove defective in any respect, You *
|
||||||
|
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||||
|
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||||
|
* essential part of this License. No use of any Covered Software is *
|
||||||
|
* authorized under this License except under this disclaimer. *
|
||||||
|
* *
|
||||||
|
************************************************************************
|
||||||
|
|
||||||
|
************************************************************************
|
||||||
|
* *
|
||||||
|
* 7. Limitation of Liability *
|
||||||
|
* -------------------------- *
|
||||||
|
* *
|
||||||
|
* Under no circumstances and under no legal theory, whether tort *
|
||||||
|
* (including negligence), contract, or otherwise, shall any *
|
||||||
|
* Contributor, or anyone who distributes Covered Software as *
|
||||||
|
* permitted above, be liable to You for any direct, indirect, *
|
||||||
|
* special, incidental, or consequential damages of any character *
|
||||||
|
* including, without limitation, damages for lost profits, loss of *
|
||||||
|
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||||
|
* and all other commercial damages or losses, even if such party *
|
||||||
|
* shall have been informed of the possibility of such damages. This *
|
||||||
|
* limitation of liability shall not apply to liability for death or *
|
||||||
|
* personal injury resulting from such party's negligence to the *
|
||||||
|
* extent applicable law prohibits such limitation. Some *
|
||||||
|
* jurisdictions do not allow the exclusion or limitation of *
|
||||||
|
* incidental or consequential damages, so this exclusion and *
|
||||||
|
* limitation may not apply to You. *
|
||||||
|
* *
|
||||||
|
************************************************************************
|
||||||
|
|
||||||
|
8. Litigation
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Any litigation relating to this License may be brought only in the
|
||||||
|
courts of a jurisdiction where the defendant maintains its principal
|
||||||
|
place of business and such litigation shall be governed by laws of that
|
||||||
|
jurisdiction, without reference to its conflict-of-law provisions.
|
||||||
|
Nothing in this Section shall prevent a party's ability to bring
|
||||||
|
cross-claims or counter-claims.
|
||||||
|
|
||||||
|
9. Miscellaneous
|
||||||
|
----------------
|
||||||
|
|
||||||
|
This License represents the complete agreement concerning the subject
|
||||||
|
matter hereof. If any provision of this License is held to be
|
||||||
|
unenforceable, such provision shall be reformed only to the extent
|
||||||
|
necessary to make it enforceable. Any law or regulation which provides
|
||||||
|
that the language of a contract shall be construed against the drafter
|
||||||
|
shall not be used to construe this License against a Contributor.
|
||||||
|
|
||||||
|
10. Versions of the License
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
10.1. New Versions
|
||||||
|
|
||||||
|
Mozilla Foundation is the license steward. Except as provided in Section
|
||||||
|
10.3, no one other than the license steward has the right to modify or
|
||||||
|
publish new versions of this License. Each version will be given a
|
||||||
|
distinguishing version number.
|
||||||
|
|
||||||
|
10.2. Effect of New Versions
|
||||||
|
|
||||||
|
You may distribute the Covered Software under the terms of the version
|
||||||
|
of the License under which You originally received the Covered Software,
|
||||||
|
or under the terms of any subsequent version published by the license
|
||||||
|
steward.
|
||||||
|
|
||||||
|
10.3. Modified Versions
|
||||||
|
|
||||||
|
If you create software not governed by this License, and you want to
|
||||||
|
create a new license for such software, you may create and use a
|
||||||
|
modified version of this License if you rename the license and remove
|
||||||
|
any references to the name of the license steward (except to note that
|
||||||
|
such modified license differs from this License).
|
||||||
|
|
||||||
|
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||||
|
Licenses
|
||||||
|
|
||||||
|
If You choose to distribute Source Code Form that is Incompatible With
|
||||||
|
Secondary Licenses under the terms of this version of the License, the
|
||||||
|
notice described in Exhibit B of this License must be attached.
|
||||||
|
|
||||||
|
Exhibit A - Source Code Form License Notice
|
||||||
|
-------------------------------------------
|
||||||
|
|
||||||
|
This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
If it is not possible or desirable to put the notice in a particular
|
||||||
|
file, then You may include the notice in a location (such as a LICENSE
|
||||||
|
file in a relevant directory) where a recipient would be likely to look
|
||||||
|
for such a notice.
|
||||||
|
|
||||||
|
You may add additional accurate notices of copyright ownership.
|
||||||
|
|
||||||
|
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||||
|
---------------------------------------------------------
|
||||||
|
|
||||||
|
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
defined by the Mozilla Public License, v. 2.0.
|
||||||
332
Readme.org
Normal file
332
Readme.org
Normal file
|
|
@ -0,0 +1,332 @@
|
||||||
|
* bjomarks-gui — bookmarks in a window
|
||||||
|
|
||||||
|
Bjomarks on the desktop: a window for [[file:../bjomarks/Readme.org][bjomarks]], made with [[file:../bjogui/Readme.org][bjogui]] and drawn with AvaUnion, KDE's look.
|
||||||
|
|
||||||
|
[[file:docs/window.png]]
|
||||||
|
|
||||||
|
#+BEGIN_SRC sh
|
||||||
|
bjo run . [SHARED [LOCAL]]
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
- ~SHARED~ is the folder that the devices share, through a file syncer or a
|
||||||
|
mounted WebDAV share: where the vault is. Else ~$BJOMARKS_SHARED~, else
|
||||||
|
the folder chosen on the first screen the last time, else
|
||||||
|
~~/Sync/bookmarks~. The folders added on the first screen are saved in
|
||||||
|
~~/.config/bjomarks/settings.json~. The list of them is there only when
|
||||||
|
neither ~SHARED~ nor ~$BJOMARKS_SHARED~ is given.
|
||||||
|
- ~LOCAL~ is this device's own folder: ~$BJOMARKS_LOCAL~. Else each shared
|
||||||
|
folder has one of its own, in ~bjomarks/vaults~ in the user's data folder
|
||||||
|
(~~/.local/share/bjomarks/vaults~ on Linux), so that two shared folders
|
||||||
|
are two vaults. See ~device-folder~ in bjomarks.
|
||||||
|
- ~BJOMARKS_LOOK=fluent~ draws the window with Avalonia's Fluent theme
|
||||||
|
instead of AvaUnion.
|
||||||
|
|
||||||
|
** Using it
|
||||||
|
|
||||||
|
[[file:docs/unlock.png]]
|
||||||
|
|
||||||
|
The first screen asks for the password. It opens this device's bookmarks,
|
||||||
|
joins those in the shared folder when this device has none, or makes new
|
||||||
|
ones when the shared folder has none: then the password is asked twice.
|
||||||
|
Argon2id and the first sync run in the background. The password box has
|
||||||
|
the keyboard when the window opens, and ~Enter~ in it opens the vault, or
|
||||||
|
joins it. For a new vault, ~Enter~ in the first box
|
||||||
|
goes to the second, and ~Enter~ in the second makes the vault.
|
||||||
|
|
||||||
|
*More than one vault.* Each shared folder holds bookmarks of their own,
|
||||||
|
with a password of their own, as on Android. The first screen lists the
|
||||||
|
shared folders added, by the names of the folders, and the first screen is
|
||||||
|
the one for the folder chosen:
|
||||||
|
- *Add new…*, at the end of the list, asks for a folder. A folder with a
|
||||||
|
vault is joined, and in an empty one a new vault is made.
|
||||||
|
- *Remove from list* takes the folder chosen out of the list, when there
|
||||||
|
are others. Its files stay, in the shared folder and on this device:
|
||||||
|
adding the folder again opens its bookmarks again.
|
||||||
|
- *Other bookmarks…*, in the toolbar of the open vault, syncs it, closes
|
||||||
|
it, and goes back to the first screen.
|
||||||
|
- The folder used last is opened at the next start. A folder used at the
|
||||||
|
first start, before any was added, is in the list once it opens.
|
||||||
|
|
||||||
|
Each shared folder has a device folder of its own (see ~device-folder~ in
|
||||||
|
bjomarks). With ~LOCAL~ or ~$BJOMARKS_LOCAL~ given, there is one device
|
||||||
|
folder, and so one vault: it belongs to the vault it was made or joined
|
||||||
|
with, and a folder with another vault does not open. An empty folder then
|
||||||
|
moves the vault there: it opens from this device's files, and its files are
|
||||||
|
written in the new folder.
|
||||||
|
|
||||||
|
| Doing | How |
|
||||||
|
|---------------------------+---------------------------------------------------------|
|
||||||
|
| Add a bookmark | ~Ctrl+M~, or *New* in the toolbar |
|
||||||
|
| Import Firefox's bookmarks | *Import*, in the toolbar: choose Firefox's JSON backup |
|
||||||
|
| Edit the chosen bookmark | ~Ctrl+E~, or a right click on it: *Edit* |
|
||||||
|
| Open it in the browser | ~Enter~, or a right click on it: *Open* |
|
||||||
|
| Open it privately | a right click on it: *Open in private window* |
|
||||||
|
| Copy its address | a right click on it: *Copy address* |
|
||||||
|
| Remove a bookmark | a right click on it: *Remove*. No key removes |
|
||||||
|
| Bring back what was removed | ~Ctrl+Z~: the last removed first, again for the one before |
|
||||||
|
| Fetch a page's title | *Fetch title*, beside the title in the dialog |
|
||||||
|
| Fetch an archive link | *Fetch archive*, beside the archive link in the dialog |
|
||||||
|
| Search | type in the search box: the list is filtered as you type |
|
||||||
|
| Search by tag | ~t:rust~ in the search box |
|
||||||
|
| Clear the search | ~Escape~ |
|
||||||
|
| Go to the search box | ~Ctrl+S~, from anywhere in the window |
|
||||||
|
| Go to the first bookmark | ~Ctrl+N~ in the search box |
|
||||||
|
| Go to the next one | ~Ctrl+N~ in the list |
|
||||||
|
| Go to the one before | ~Ctrl+P~ in the list; on the first, back to the search box |
|
||||||
|
| Save or cancel the dialog | ~Enter~, ~Escape~, or its buttons |
|
||||||
|
| Show the help | ~F1~, or *Help* in the toolbar; ~Escape~ closes it |
|
||||||
|
| Open other bookmarks | *Other bookmarks…* in the toolbar |
|
||||||
|
|
||||||
|
No key is a single letter, so each acts in the search box too. ~Ctrl+E~
|
||||||
|
and ~Enter~ act on the chosen bookmark, and do nothing when none is chosen.
|
||||||
|
~Ctrl+Z~ in the search box brings back a bookmark when a removal (or the
|
||||||
|
bringing back of one) is the last thing done; after you type in the box, it
|
||||||
|
undoes the typing, as in any text box. So ~Ctrl+Z~ works at once after a
|
||||||
|
removal of the last bookmark that the list shows, when the keyboard goes to
|
||||||
|
the search box.
|
||||||
|
|
||||||
|
*The help* is a window of its own, with the keys and a few words on
|
||||||
|
searching, the dialog and importing:
|
||||||
|
|
||||||
|
[[file:docs/help.png]]
|
||||||
|
|
||||||
|
[[file:docs/edit.png]]
|
||||||
|
|
||||||
|
*The search* shows a bookmark when each word of it is in the bookmark's
|
||||||
|
title, its address or its tags, as a word, the start or a part of one, or
|
||||||
|
with a typo: ~rust book~ finds /The Rust Programming Language/ at
|
||||||
|
~https://doc.rust-lang.org/book/~. ~t:rust~ is the tag "rust", the whole
|
||||||
|
tag; ~d:github.com~ the domain; ~a:2011:2012-06~ the days added; ~"two
|
||||||
|
words"~ exact text; and ~-~ before any of them excludes it. The best matches
|
||||||
|
come first. Archive links are not searched. All of it is in (bjomarks
|
||||||
|
search), and in the help (F1).
|
||||||
|
|
||||||
|
*Titles.* The list shows a bookmark's title, or its address when it has
|
||||||
|
none. The line under it is as on Android: the day it was added, the
|
||||||
|
address, the tags, and "archived" when it has an archive link. A thin line
|
||||||
|
is between the bookmarks. *Fetch title*, beside the title in
|
||||||
|
the dialog, fetches the page at the address and puts its title in the
|
||||||
|
field, to keep or change before *Save*. While it fetches, the button turns:
|
||||||
|
|
||||||
|
[[file:docs/fetching.png]]
|
||||||
|
|
||||||
|
Nothing else fetches a title: not saving, not opening, not syncing. When
|
||||||
|
the page has no title, or cannot be fetched, the dialog says why. Typing in
|
||||||
|
the address or the title while a fetch runs stops waiting for it, and
|
||||||
|
closing the dialog drops it. ~(bjomarks title)~ does the fetch: only
|
||||||
|
~http~ and ~https~, at most 512 KiB, 10 seconds. A fetch tells the site
|
||||||
|
about the bookmark: the site sees a request from this machine.
|
||||||
|
|
||||||
|
*Archive links.* *Fetch archive*, beside the archive link in the dialog,
|
||||||
|
asks the Wayback Machine of the Internet Archive for the latest snapshot of
|
||||||
|
the page at the address, and puts the snapshot's address in the field, as
|
||||||
|
~https://web.archive.org/web/<time>/<address>~. The button turns while it
|
||||||
|
looks, as *Fetch title* does, and the two can run at the same time. When
|
||||||
|
the Wayback Machine has no snapshot of the page, or does not answer, the
|
||||||
|
dialog says why, and the field keeps what it had. Typing in the address or
|
||||||
|
the archive link while a lookup runs stops waiting for it, and closing the
|
||||||
|
dialog drops it. ~(bjomarks wayback)~ does the lookup, with the
|
||||||
|
availability API (~https://archive.org/wayback/available~): only ~http~ and
|
||||||
|
~https~ addresses, 20 seconds. A lookup tells the Internet Archive the
|
||||||
|
address of the bookmark; the page itself is not fetched. The button does
|
||||||
|
not make a new snapshot.
|
||||||
|
|
||||||
|
*No address twice.* When the address typed or pasted in the dialog of a
|
||||||
|
*New* bookmark is one that a bookmark has, the dialog becomes the /Edit/
|
||||||
|
dialog of that bookmark, with its title, tags and archive link, and says
|
||||||
|
so. *Save* then changes that bookmark, and adds none. When the address
|
||||||
|
changes again to one that no bookmark has, as while
|
||||||
|
~https://example.org/page~ is typed past ~https://example.org/~, the dialog
|
||||||
|
is of a new bookmark again, with what was typed in it before. Addresses are
|
||||||
|
the same when they are the same text, but for spaces at the ends: ~/~ at
|
||||||
|
the end, and the case of the scheme and the host, count. The /Edit/ dialog
|
||||||
|
of a bookmark does not check.
|
||||||
|
|
||||||
|
*Importing from Firefox.* *Import* reads the JSON backup that Firefox
|
||||||
|
writes: in Firefox's Library window (~Ctrl+Shift+O~), choose /Import and
|
||||||
|
Backup/, then /Backup…/. It is named ~bookmarks-YYYY-MM-DD.json~. The HTML
|
||||||
|
export is not read: the note says so, and which file to choose.
|
||||||
|
- Each folder that holds a bookmark becomes a tag of it, at any depth:
|
||||||
|
/Rust Docs/ → ~rust-docs~. Firefox's top folders (the menu, the toolbar,
|
||||||
|
/Other bookmarks/, /Mobile bookmarks/) do not. Firefox's tags come too.
|
||||||
|
Names are lower-cased, with ~-~ for spaces and commas.
|
||||||
|
- A bookmark keeps its title and the date it was added in Firefox.
|
||||||
|
- An address bookmarked in two folders is one bookmark with both tags.
|
||||||
|
- Addresses that are not http or https (Firefox's ~place:~ queries,
|
||||||
|
bookmarklets, ~about:~ pages) are left out. So is an http address that
|
||||||
|
is not a URL by RFC 3986, as one with two ~#~ in it: the note names it.
|
||||||
|
- An address that is here already is not imported again, and the bookmark
|
||||||
|
here is not changed. So the same backup can be imported again, or a
|
||||||
|
newer one, and only what is new comes.
|
||||||
|
- The note at the bottom says how many came in, and what was left out.
|
||||||
|
There is no undo for an import.
|
||||||
|
|
||||||
|
*Tags* are typed with spaces or commas between them, and kept sorted, each
|
||||||
|
once. The address and the archive link must be absolute URLs, with a
|
||||||
|
scheme: ~https://...~.
|
||||||
|
|
||||||
|
*Removing* does not ask: ~Ctrl+Z~ brings the bookmark back as it was,
|
||||||
|
also after the removal was synced. The list of what was removed lasts until
|
||||||
|
the window is closed. A bookmark brought back is a change like any other,
|
||||||
|
so it comes back on the other devices too.
|
||||||
|
|
||||||
|
*Opening* gives the address to the system, which opens it in the browser
|
||||||
|
the user chose: ~xdg-open~ on Linux, ~open~ on macOS, the shell on Windows.
|
||||||
|
With ~BJOMARKS_BROWSER~ set, that program is started with the address as
|
||||||
|
its one argument instead. Only ~http~ and ~https~ addresses are opened: a
|
||||||
|
bookmark can come from another device's file, and a ~file:~ address, or one
|
||||||
|
of a program's own scheme, could start a program on this one.
|
||||||
|
|
||||||
|
*Open in private window* starts the default browser with its flag for a
|
||||||
|
private window: ~--private-window~ for Firefox and those made from it
|
||||||
|
(LibreWolf, Waterfox, Floorp, Zen), ~--incognito~ for Chrome, Chromium,
|
||||||
|
Brave, Vivaldi and Opera, and ~--inprivate~ for Edge. The default browser
|
||||||
|
is the one ~xdg-settings get default-web-browser~ names (in a distrobox
|
||||||
|
container, the host's), and its command is the ~Exec~ line of its
|
||||||
|
~.desktop~ file, so a Flatpak browser is started with ~flatpak run~ as its
|
||||||
|
file says. ~BJOMARKS_PRIVATE_BROWSER~ names a program to start instead,
|
||||||
|
with the address as its one argument, such as a script that runs
|
||||||
|
~firefox --private-window "$1"~. With a browser not known, or on Windows and macOS, the
|
||||||
|
address is copied, to paste in a private window, and the line at the
|
||||||
|
bottom says so. Only ~http~ and ~https~ addresses are opened, as for *Open*.
|
||||||
|
|
||||||
|
*A page bookmarked twice*, by two devices before they synced, becomes one
|
||||||
|
bookmark, with the tags of both (see (bjomarks duplicates)). When the two
|
||||||
|
have different titles, a window asks which to keep; *Not now*, or closing
|
||||||
|
it, asks again the next time the vault opens.
|
||||||
|
|
||||||
|
*In a distrobox container*, the address is opened in the host's browser:
|
||||||
|
~host-spawn -no-pty -env DISPLAY,WAYLAND_DISPLAY,XDG_SESSION_TYPE xdg-open
|
||||||
|
ADDRESS~. distrobox's own ~xdg-open~ in the container gives the host's
|
||||||
|
~xdg-open~ none of these variables, and with no display it finds no
|
||||||
|
browser: "no method available". ~XDG_CURRENT_DESKTOP~ is not given on
|
||||||
|
purpose: with it, ~xdg-open~ uses the desktop's own opener, which needs more
|
||||||
|
of the session (KDE's needs ~KDE_SESSION_VERSION~, or it tries ~kfmclient~).
|
||||||
|
Without it, ~xdg-open~ opens the address with the user's default program for
|
||||||
|
it, as ~xdg-mime~ says, on any desktop. The window knows it runs in such a
|
||||||
|
container when podman's or docker's file for it is there
|
||||||
|
(~/run/.containerenv~, ~/.dockerenv~) and ~host-spawn~ is on the ~PATH~.
|
||||||
|
|
||||||
|
The opener is waited for, up to 5 seconds. When it ends with an error, the
|
||||||
|
line at the bottom says so ("xdg-open found no program to open it with"),
|
||||||
|
and not "Opened". One that runs longer has started a browser that it waits
|
||||||
|
for, and that is no error.
|
||||||
|
|
||||||
|
** Saving
|
||||||
|
|
||||||
|
Each change (a new bookmark, an edit, a removal) starts a sync in the
|
||||||
|
background: this device's file is written to the shared folder, and the
|
||||||
|
other devices' files are merged in. The window does not wait for it. A
|
||||||
|
change made while a sync runs is merged with what that sync did
|
||||||
|
(~vault-merge~), and the next sync writes it. A sync also runs each minute,
|
||||||
|
for the other devices' changes. The line at the bottom says how the last
|
||||||
|
one went.
|
||||||
|
|
||||||
|
Closing the window waits for the sync of the last changes. If that sync
|
||||||
|
fails, the window says so and stays open; closing it again closes it
|
||||||
|
without saving.
|
||||||
|
|
||||||
|
** The parts
|
||||||
|
|
||||||
|
| Module | What it has |
|
||||||
|
|------------------------+---------------------------------------------------------------|
|
||||||
|
| ~(bjomarks-gui app)~ | the model, the update, the views, the dialog and the keys |
|
||||||
|
| ~(bjomarks-gui inputs)~ | the search box and the password box: Avalonia ~TextBox~es |
|
||||||
|
| ~(bjomarks-gui fetch-button)~ | the buttons that fetch a title and an archive link, which turn while they work |
|
||||||
|
| ~(bjomarks-gui settings)~ | ~~/.config/bjomarks/settings.json~: the shared folders added, and the one used last |
|
||||||
|
| ~(bjomarks-gui browser)~ | opens an address in the browser, or in a private window |
|
||||||
|
| ~src/main.bjo~ | the folders, the theme, and ~run-app~ |
|
||||||
|
|
||||||
|
bjogui has no animations, so *Fetch title* and *Fetch archive* are Avalonia ~Button~s, made
|
||||||
|
with ~(bjogui native)~. Over its label is an ~Arc~, hidden until a fetch
|
||||||
|
runs. Then the label goes, and the arc goes round once in 0.9 s while it
|
||||||
|
grows and shrinks in 1.6 s, in the colour of the button's text. The two
|
||||||
|
animations are Avalonia's, in a style of the arc that applies while it has
|
||||||
|
the class ~spinning~: they run on Avalonia's render loop, not as messages
|
||||||
|
to the model, and only while a fetch runs.
|
||||||
|
|
||||||
|
The search box and the password box are made with ~(bjogui native)~, not
|
||||||
|
~text-input~. The search box must hear ~Ctrl+N~ itself: only the box knows
|
||||||
|
that it has the keyboard, and ~Ctrl+N~ means "the first bookmark" there and
|
||||||
|
"the next one" in the list. It hears the key as it tunnels down, before the
|
||||||
|
box's own handling. The password box shows dots, and hears ~Enter~.
|
||||||
|
|
||||||
|
The window's ~Ctrl+N~ and ~Ctrl+P~ are ~run-app~'s ~#:keys~: they come to
|
||||||
|
the window when the control with the keyboard does not take them. ~(focus
|
||||||
|
"list")~ gives the keyboard to the chosen bookmark, as bjogui's ~focus~ does
|
||||||
|
for a list box.
|
||||||
|
|
||||||
|
** Tests
|
||||||
|
|
||||||
|
#+BEGIN_SRC sh
|
||||||
|
bjo run tests/app.bjo # prints "bjomarks-gui ok"
|
||||||
|
bjo run tests/screenshots.bjo docs/window.png # needs a display
|
||||||
|
bjo run tests/screenshots.bjo /tmp/edit.png edit # the dialog is /tmp/edit-draft.png: docs/edit.png
|
||||||
|
bjo run tests/screenshots.bjo /tmp/fetching.png fetching # /tmp/fetching-draft.png: docs/fetching.png
|
||||||
|
bjo run tests/screenshots.bjo /tmp/help.png help # /tmp/help-help.png: docs/help.png
|
||||||
|
bjo run tests/screenshots.bjo docs/unlock.png lock
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
~tests/app.bjo~ runs the window with no screen, in Avalonia's headless
|
||||||
|
platform, and presses keys with its keyboard, so that they go where real
|
||||||
|
keys go: ~Ctrl+N~ and ~Ctrl+P~ in the search box and in the list, text typed
|
||||||
|
into the search box, ~Enter~ and ~Escape~ in the dialog and in the password
|
||||||
|
box, ~Ctrl+M~, ~Ctrl+E~, ~Enter~, ~Ctrl+S~, ~Ctrl+Z~ and ~F1~ in the list
|
||||||
|
and in the search box, and the letters ~E~, ~O~ and ~D~, which do nothing there
|
||||||
|
and are typed in the search box. It checks that the help names each key of
|
||||||
|
the window and of the dialog. It makes
|
||||||
|
a vault, adds, searches, edits, opens, removes and brings back bookmarks,
|
||||||
|
waits for the background syncs, opens the vault again with a wrong and a
|
||||||
|
right password, and joins it from a second device. Opening starts no
|
||||||
|
browser: the test sets ~BJOMARKS_BROWSER~ to a script that writes down the
|
||||||
|
address, and on Linux puts a fake ~xdg-open~ first on the ~PATH~.
|
||||||
|
|
||||||
|
Titles are fetched from a server that the test runs on the loopback: no
|
||||||
|
site on the internet is asked. The test clicks *Fetch title* in the
|
||||||
|
dialog, as the button hears a click, and checks the button while a slow
|
||||||
|
page is fetched: the label hidden, the arc shown, with the class
|
||||||
|
~spinning~, and at another angle after a tick of the render loop. It
|
||||||
|
checks that saving fetches nothing, that the server was asked once per
|
||||||
|
click, that a page with no title is said so, and that a result is dropped
|
||||||
|
when the dialog was closed or a title was typed meanwhile. The server also
|
||||||
|
answers as the Wayback Machine's API does: the app is given its address in
|
||||||
|
place of the Internet Archive's. The test clicks *Fetch archive*, and checks
|
||||||
|
the same for the archive link, and that a link fetched for a bookmark is
|
||||||
|
saved with it. The search tests include ~tag:mytag tag:nice banana~.
|
||||||
|
|
||||||
|
The import and the folder are tested with the messages that the pickers
|
||||||
|
send, as a picker answers nothing with no screen. The import reads a
|
||||||
|
made-up backup in Firefox's shape, twice, then an HTML export and a file
|
||||||
|
that is not there. The folder test keeps its settings in the temp
|
||||||
|
directory, not in ~~/.config~: it changes the folder of a device with no
|
||||||
|
vault (to an empty one, then back), chooses from the list of folders and
|
||||||
|
removes one from it, checks what is saved, that settings of an earlier
|
||||||
|
version are read, and that other fields of the settings are kept, and
|
||||||
|
opens a device's vault in a new empty folder. There another device
|
||||||
|
bookmarks a page of it with another title: the test checks the question
|
||||||
|
of which title to keep, *Not now*, and the title chosen. Then *Other
|
||||||
|
bookmarks…* closes the vault, and it opens again.
|
||||||
|
|
||||||
|
*Open in private window* is tested by its parts: the flag of each browser,
|
||||||
|
the words of ~Exec~ lines (Flatpak's, and quoted ones), and the note and
|
||||||
|
the copy when no browser opens one. The test starts no browser. ~Escape~
|
||||||
|
clearing the search, *Copy address* and the line under each bookmark are
|
||||||
|
tested too.
|
||||||
|
|
||||||
|
Not tested by a test: the right click itself, a real mouse on the
|
||||||
|
buttons, the pickers themselves, and a real browser's private window. The
|
||||||
|
test checks that each bookmark has a menu with *Open*, *Open in private
|
||||||
|
window*, *Copy address*, *Edit* and *Remove*, and bjogui's tests check that
|
||||||
|
a context menu is its control's and that its items send their messages.
|
||||||
|
|
||||||
|
** Not yet
|
||||||
|
|
||||||
|
- The list makes a control for each bookmark it shows. A few thousand are
|
||||||
|
fine; far more would want a list that makes controls only for what is on
|
||||||
|
screen, which bjogui does not have yet.
|
||||||
|
- No way to change the password from the window, or to choose this
|
||||||
|
device's own folder (~LOCAL~).
|
||||||
|
- No undo for an import, and no import of the HTML export or of other
|
||||||
|
browsers' bookmarks.
|
||||||
|
- WebDAV, as bjomarks has no WebDAV storage yet. A WebDAV share mounted as
|
||||||
|
a folder works.
|
||||||
BIN
docs/edit.png
Normal file
BIN
docs/edit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
BIN
docs/fetching.png
Normal file
BIN
docs/fetching.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
BIN
docs/help.png
Normal file
BIN
docs/help.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 248 KiB |
BIN
docs/unlock.png
Normal file
BIN
docs/unlock.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
BIN
docs/window.png
Normal file
BIN
docs/window.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 89 KiB |
21
manifest.bjodat
Normal file
21
manifest.bjodat
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
(package
|
||||||
|
(name (bjomarks-gui))
|
||||||
|
(version "0.1.0")
|
||||||
|
(description "A window for bjomarks: search, add, edit and remove bookmarks, saved in the background.")
|
||||||
|
(license "MPL-2.0")
|
||||||
|
(aot #t)
|
||||||
|
|
||||||
|
;; The Android app: bjo publish --android.
|
||||||
|
(android-id "org.bjoli.bjomarks")
|
||||||
|
(android-label "Bookmarks")
|
||||||
|
(android-aot #t)
|
||||||
|
;; Fetching titles and archive links.
|
||||||
|
(android-permissions "INTERNET")
|
||||||
|
|
||||||
|
(depends
|
||||||
|
(package (name (bjomarks)) (source (path (dir "../bjomarks"))))
|
||||||
|
(package (name (bjogui)) (source (path (dir "../bjogui")))))
|
||||||
|
|
||||||
|
;; The window's look: KDE's Union, with its Breeze style. See src/main.bjo.
|
||||||
|
(packages
|
||||||
|
(nuget (id "AvaUnion.Theme") (version "6.8.0.6"))))
|
||||||
254
packages.lock.json
Normal file
254
packages.lock.json
Normal file
|
|
@ -0,0 +1,254 @@
|
||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"dependencies": {
|
||||||
|
"net11.0": {
|
||||||
|
"AvaUnion.Theme": {
|
||||||
|
"type": "Direct",
|
||||||
|
"requested": "[6.8.0.6, )",
|
||||||
|
"resolved": "6.8.0.6",
|
||||||
|
"contentHash": "whOcY2MohWg2s7hSmoHgcrpMpTytfpeAXgfcVdERzYtzYHZeMY7xhN2C3ESC/s716hM5PvlpNMtOE8kG0vzt5w==",
|
||||||
|
"dependencies": {
|
||||||
|
"AvaUnion.Native": "6.8.0.6",
|
||||||
|
"Avalonia": "12.1.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Avalonia": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "12.1.5",
|
||||||
|
"contentHash": "Vw+gNvv4RXK5hLeVI9PfalhxPai6hrQjIElfoCDQK1fXTpk+vRyfhuhprrh+EIeuJtoYCy+AsSrqR1wgU28zeQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"Avalonia.BuildServices": "11.3.2",
|
||||||
|
"Avalonia.Remote.Protocol": "12.1.5",
|
||||||
|
"MicroCom.Runtime": "0.11.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Avalonia.Angle.Windows.Natives": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "2.1.27548.20260419",
|
||||||
|
"contentHash": "l17nI3XVDN3oMnpjf2pnmJg0YTwK4m6NLsn/itAjDMdObTFxN77D5F1M9sRMSfViSY3KKcse1ROczwgoWLJsnA=="
|
||||||
|
},
|
||||||
|
"Avalonia.BuildServices": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "11.3.2",
|
||||||
|
"contentHash": "qHDToxto1e3hci5YqbG9n0Ty8mlp3zBUN5wT66wKqaDVzXyQ0do3EnRILd4Ke9jpvsktaPpgE0YjEk7hornryQ=="
|
||||||
|
},
|
||||||
|
"Avalonia.Desktop": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "12.1.5",
|
||||||
|
"contentHash": "l1jo9qKJjJ68gcuUwHgNgpsHV6STcvqfYTFvFPprOf949gmE506X/d7Mox/y36tU2BSWBqLGZ1M3mh8Ggl2g/Q==",
|
||||||
|
"dependencies": {
|
||||||
|
"Avalonia": "12.1.5",
|
||||||
|
"Avalonia.HarfBuzz": "12.1.5",
|
||||||
|
"Avalonia.Native": "12.1.5",
|
||||||
|
"Avalonia.Skia": "12.1.5",
|
||||||
|
"Avalonia.Win32": "12.1.5",
|
||||||
|
"Avalonia.X11": "12.1.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Avalonia.Fonts.Inter": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "12.1.5",
|
||||||
|
"contentHash": "SeFNLktbuxrHxUzPjYubzWB1O9HVCNo3IezZZ9SgkFBAcKcSYrY2KcD8lfP7QWMGxPUvqdLyn0TmioR9d3nZUg==",
|
||||||
|
"dependencies": {
|
||||||
|
"Avalonia": "12.1.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Avalonia.FreeDesktop": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "12.1.5",
|
||||||
|
"contentHash": "XqLCj3V2PJsIaNANnFwolEv9Ng8LT7XM//dG39wPv/oeVTijjLNbayWAkeQlpKxi6RtAkjfnXjK+xK/S1caQLA==",
|
||||||
|
"dependencies": {
|
||||||
|
"Avalonia": "12.1.5",
|
||||||
|
"Tmds.DBus.Protocol": "0.94.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Avalonia.FreeDesktop.AtSpi": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "12.1.5",
|
||||||
|
"contentHash": "MTqCBRv1+nkUHPUeMtbh4/dA3AaCEA6LpIT+ZtCnWO4QSxEQFIdlyMZa/d4y6qBBIcxw2DhdY3+JzdhCn6DpUg==",
|
||||||
|
"dependencies": {
|
||||||
|
"Avalonia": "12.1.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Avalonia.HarfBuzz": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "12.1.5",
|
||||||
|
"contentHash": "3kspGPaRVrCzgMi4Rv4N33VNbQNN4wcY4NoCufYxKF/kvYqPbrAnGD2Mjm6Kmc3IA3QrLbj5UJpg8WDTAd4cPw==",
|
||||||
|
"dependencies": {
|
||||||
|
"Avalonia": "12.1.5",
|
||||||
|
"HarfBuzzSharp": "8.3.1.3",
|
||||||
|
"HarfBuzzSharp.NativeAssets.Linux": "8.3.1.3",
|
||||||
|
"HarfBuzzSharp.NativeAssets.WebAssembly": "8.3.1.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Avalonia.Headless": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "12.1.5",
|
||||||
|
"contentHash": "0s3+IiZ/lP7A2R80OOFc3YiSK3qnWOLO9KVsMBGjLX/kg4JSsU2YJiAMNTZIihDmIOYV0VHECJCzsSNKCTMXww==",
|
||||||
|
"dependencies": {
|
||||||
|
"Avalonia": "12.1.5",
|
||||||
|
"Avalonia.Fonts.Inter": "12.1.5",
|
||||||
|
"Avalonia.HarfBuzz": "12.1.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Avalonia.Native": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "12.1.5",
|
||||||
|
"contentHash": "LsC92ialAyccwXiqSjSHVlYGbASfB8XHbGT0XB3zqERF7PM7M3KjSnMgGc1HkzvwtGX+GgTYap6PV8N9H6un8Q==",
|
||||||
|
"dependencies": {
|
||||||
|
"Avalonia": "12.1.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Avalonia.Remote.Protocol": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "12.1.5",
|
||||||
|
"contentHash": "yNSke7MNKxJrgcTOQJk70QhPU568dxwRMeQCSmq9N7IGbpPS4zpbr4o6e8rLF/8UfASBQN/yuTgqUfa2nwf6Iw=="
|
||||||
|
},
|
||||||
|
"Avalonia.Skia": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "12.1.5",
|
||||||
|
"contentHash": "irfPBtb4UoAT0qfRviYsALBwo0JwXnziRNOTQLzzAQt3eoNPyKFLBsgyj5hE4+6vgunQ7hltEHlvTHPkCoreIg==",
|
||||||
|
"dependencies": {
|
||||||
|
"Avalonia": "12.1.5",
|
||||||
|
"HarfBuzzSharp": "8.3.1.3",
|
||||||
|
"HarfBuzzSharp.NativeAssets.Linux": "8.3.1.3",
|
||||||
|
"HarfBuzzSharp.NativeAssets.WebAssembly": "8.3.1.3",
|
||||||
|
"SkiaSharp": "3.119.4",
|
||||||
|
"SkiaSharp.NativeAssets.Linux": "3.119.4",
|
||||||
|
"SkiaSharp.NativeAssets.WebAssembly": "3.119.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Avalonia.Themes.Fluent": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "12.1.5",
|
||||||
|
"contentHash": "FGjtJEpeVIbth+u4r507c9nbm1NQWLTvT3RC4e/yqDceRC4crAl37zVUloElA6rexDz69y0WvDfMLGX+t12yBQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"Avalonia": "12.1.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Avalonia.Win32": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "12.1.5",
|
||||||
|
"contentHash": "QHfRLCyvVzj74AMCohS5a08Jz5f7VAeRgZ0SJsDTSfqxRzdbw9DXpKsncu21YmEvRWxMPkwyoB9cx9dvS1Bwmg==",
|
||||||
|
"dependencies": {
|
||||||
|
"Avalonia": "12.1.5",
|
||||||
|
"Avalonia.Angle.Windows.Natives": "2.1.27548.20260419"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Avalonia.X11": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "12.1.5",
|
||||||
|
"contentHash": "5EK2QrM9I3Lm3Aq/ZSpJjg1ZzBXl7YE9PxaB/mLxF9ysZz8qgFaJ5Zj+A9NdtAszupA+81Z3B9EmZP++2Xs4Ug==",
|
||||||
|
"dependencies": {
|
||||||
|
"Avalonia": "12.1.5",
|
||||||
|
"Avalonia.FreeDesktop": "12.1.5",
|
||||||
|
"Avalonia.FreeDesktop.AtSpi": "12.1.5",
|
||||||
|
"Avalonia.Skia": "12.1.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AvaUnion.Native": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "6.8.0.6",
|
||||||
|
"contentHash": "+1EE2j5/spse2KMwXjncYAZ5KdGtE139azgz4JG2XrYzgzIn0Ur36ieMwYKj6fXwYIhDot4YjnE2mZNbo7nujA=="
|
||||||
|
},
|
||||||
|
"HarfBuzzSharp": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "8.3.1.3",
|
||||||
|
"contentHash": "NGZ2+ZVNPM+NdHB/asW0/ykWngyHWwcqjrbN2nDeH1B/aptPGlCUl8wkQ2cSJxw5fdWgdmIPmNuTPWpLwNVXWg==",
|
||||||
|
"dependencies": {
|
||||||
|
"HarfBuzzSharp.NativeAssets.Win32": "8.3.1.3",
|
||||||
|
"HarfBuzzSharp.NativeAssets.macOS": "8.3.1.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"HarfBuzzSharp.NativeAssets.Linux": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "8.3.1.3",
|
||||||
|
"contentHash": "RI6A1LgmooU30+4QIyFt5rmBCzP0VzTR+587IJSGvYIsHHWlahFufihYxtraLfsIhW7I8dn6+xX+DZGygOPKWQ=="
|
||||||
|
},
|
||||||
|
"HarfBuzzSharp.NativeAssets.macOS": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "8.3.1.3",
|
||||||
|
"contentHash": "KPTq0xnslkI6nAo0jh3ptcQPJvZZr7MWYXa2jUe4SnHc9q+JlHElmNXp0sfFoiTgoCX7WOYpYsurypuH9Gehxw=="
|
||||||
|
},
|
||||||
|
"HarfBuzzSharp.NativeAssets.WebAssembly": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "8.3.1.3",
|
||||||
|
"contentHash": "w2QfdNm9Uz/sUa0B5D+OnVQhyq3G/fBq6ibQMdWBlQqqwh0g0/5j3RFvYqZAmRZ5+RzvjVe8o8SFFnWYUSkuxA=="
|
||||||
|
},
|
||||||
|
"HarfBuzzSharp.NativeAssets.Win32": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "8.3.1.3",
|
||||||
|
"contentHash": "bx8CE8Js+XGX8PUxAHCBDEORt5aaBYtMN4Hr9QFs57Xithh6yjUyYqksizH6eRDhJkwsGI+SXWmPmMm8lZC9Pw=="
|
||||||
|
},
|
||||||
|
"libsodium": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "1.0.20.2",
|
||||||
|
"contentHash": "FButtPK6HZvOewaE20F1HXNJn4qOoGAf7FEDm0VbWJ+xBX9pN9+2nkQQnfaLz+Ae5KuEzRoe1GHO00UpabgNxA=="
|
||||||
|
},
|
||||||
|
"LibSodium.Net": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "0.16.0-alpha",
|
||||||
|
"contentHash": "uNW5uuT2QEu5zUSDAbNyXM/RPZjnLjMEp88uYMCkH2yr9+jX7LpZsV9JZimdIABKiHivfGqSJAXmj3Bd2tmJUQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"libsodium": "1.0.20.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"MicroCom.Runtime": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "0.11.6",
|
||||||
|
"contentHash": "NdNWGDiZ6eS/Mf/9+QHR91cj1K7Hy+PX9yrHI/zM7xFYuj9IWT2uxtB6sCHjrnxAeLV9fut1R6zHDUGKX6f9lQ=="
|
||||||
|
},
|
||||||
|
"SkiaSharp": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "3.119.4",
|
||||||
|
"contentHash": "53NOSUZ1Us+91Sm0uCkIivh/k7jOowRErZT2sIWwPFN9mLUvdxnE6rS4sWo4255+Rd2MWUSF+j0NMZHD6Cke+Q==",
|
||||||
|
"dependencies": {
|
||||||
|
"SkiaSharp.NativeAssets.Win32": "3.119.4",
|
||||||
|
"SkiaSharp.NativeAssets.macOS": "3.119.4"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"SkiaSharp.NativeAssets.Linux": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "3.119.4",
|
||||||
|
"contentHash": "UAyVzbqNfZsZbKbzj68zXLyUyF/SbTKmzTfOO6qDu++dtIUMMTzPBe8oOuzU/DiewpfKoUUlOSsJmqWc6blxBw=="
|
||||||
|
},
|
||||||
|
"SkiaSharp.NativeAssets.macOS": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "3.119.4",
|
||||||
|
"contentHash": "fgBOWEqbY012x7gMfJU4ezgz6dfhJb30Z6YdW35h85Zoe39+a8YNbAAwL29ihPfWoppg5AjvyKNzD1oCvlqWwA=="
|
||||||
|
},
|
||||||
|
"SkiaSharp.NativeAssets.WebAssembly": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "3.119.4",
|
||||||
|
"contentHash": "S1HOxtBbD4bYDtA2e9WH5TX+lxqRrTPvKjrjttRhxnHNNu7YY8VFo/LeCP7tNqoTA6PV+8vsvNbmRUEC2ip8RQ=="
|
||||||
|
},
|
||||||
|
"SkiaSharp.NativeAssets.Win32": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "3.119.4",
|
||||||
|
"contentHash": "XOpbx/4CReO2wYsq2s6rbvdauc6dntG4Zv499sHGTJ87bwZaFXszFkwql3+FIZMc8kUPeaj3Mx2ezIJmo8a1Kg=="
|
||||||
|
},
|
||||||
|
"Tmds.DBus.Protocol": {
|
||||||
|
"type": "Transitive",
|
||||||
|
"resolved": "0.94.1",
|
||||||
|
"contentHash": "11YMr7FnAbL83bQmVxlhbIKHvSLxjO81D12Ej0QMSGXMDTxNA9MTOa4MQxx43nv5el/efuPHwzyrj6a5ha2gug=="
|
||||||
|
},
|
||||||
|
"bjopackage.bjogui": {
|
||||||
|
"type": "Project",
|
||||||
|
"dependencies": {
|
||||||
|
"Avalonia": "[12.1.5, )",
|
||||||
|
"Avalonia.Desktop": "[12.1.5, )",
|
||||||
|
"Avalonia.Headless": "[12.1.5, )",
|
||||||
|
"Avalonia.Skia": "[12.1.5, )",
|
||||||
|
"Avalonia.Themes.Fluent": "[12.1.5, )"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"bjopackage.bjosodium": {
|
||||||
|
"type": "Project",
|
||||||
|
"dependencies": {
|
||||||
|
"LibSodium.Net": "[0.16.0-alpha, 0.16.0-alpha]",
|
||||||
|
"libsodium": "[1.0.20.2, 1.0.21)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1151
src/app.bjo
Normal file
1151
src/app.bjo
Normal file
File diff suppressed because it is too large
Load diff
287
src/browser.bjo
Normal file
287
src/browser.bjo
Normal file
|
|
@ -0,0 +1,287 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
;; bjomarks-gui/src/browser.bjo — the module (bjomarks-gui browser): opens
|
||||||
|
;; an address in the user's browser.
|
||||||
|
;;
|
||||||
|
;; - With BJOMARKS_BROWSER set, that program is started with the address as
|
||||||
|
;; its one argument, with no shell between.
|
||||||
|
;; - In a distrobox container, host-spawn runs xdg-open on the host, with the
|
||||||
|
;; variables that tell it the display. distrobox's own xdg-open gives the
|
||||||
|
;; host none of them, and the host's xdg-open then finds no browser: "no
|
||||||
|
;; method available".
|
||||||
|
;; - Else the system opens it, as a click on a link does: xdg-open on Linux
|
||||||
|
;; and the BSDs, open on macOS, and the shell on Windows. That opens the
|
||||||
|
;; browser the user chose.
|
||||||
|
;; - The opener is waited for, up to 5 seconds. When it ends with an error,
|
||||||
|
;; the address was not opened, and the text says so. One that runs longer
|
||||||
|
;; has started a browser that it waits for: that is no error.
|
||||||
|
;; - Only http and https addresses are opened. A bookmark comes from the
|
||||||
|
;; files of other devices, and a `file:` address or one of a program's own
|
||||||
|
;; scheme can start a program on this one.
|
||||||
|
;;
|
||||||
|
;; A private window: the user's default browser, as `xdg-settings` names it,
|
||||||
|
;; is started as its .desktop file says, with its own flag for a private
|
||||||
|
;; window: --private-window for Firefox and those made from it, --incognito
|
||||||
|
;; for Chrome and those made from Chromium, and --inprivate for Edge. With
|
||||||
|
;; BJOMARKS_PRIVATE_BROWSER set, that program is started with the address
|
||||||
|
;; instead. Another browser, or another system than Linux, has no private
|
||||||
|
;; window here: `open-private-in-browser` says so, and the app copies the
|
||||||
|
;; address.
|
||||||
|
|
||||||
|
(export Opener opener-for distrobox-host-spawn open-in-browser browser-scheme?
|
||||||
|
private-flag exec-words private-command open-private-in-browser)
|
||||||
|
|
||||||
|
(import (std prelude))
|
||||||
|
(import (std interop))
|
||||||
|
(import (std os))
|
||||||
|
(import (std url))
|
||||||
|
|
||||||
|
(import/class
|
||||||
|
(ProcessStartInfo (: System.Diagnostics.ProcessStartInfo (-> string ProcessStartInfo)))
|
||||||
|
(Process (: System.Diagnostics.Process))
|
||||||
|
(Object (: System.Object)))
|
||||||
|
|
||||||
|
(import/extern
|
||||||
|
(shell-execute! (: System.Diagnostics.ProcessStartInfo.UseShellExecute (-> ProcessStartInfo bool void) #:set))
|
||||||
|
(redirect-output! (: System.Diagnostics.ProcessStartInfo.RedirectStandardOutput
|
||||||
|
(-> ProcessStartInfo bool void) #:set))
|
||||||
|
(output-of (: System.Diagnostics.Process.StandardOutput (-> Process System.IO.StreamReader) #:get))
|
||||||
|
(read-to-end (: System.IO.StreamReader.ReadToEnd (-> System.IO.StreamReader string)))
|
||||||
|
;; .NET strings, not Bjolang's.
|
||||||
|
(arguments-of (: System.Diagnostics.ProcessStartInfo.ArgumentList
|
||||||
|
(-> ProcessStartInfo (System.Collections.ObjectModel.Collection System.String)) #:get))
|
||||||
|
(add-argument! (: System.Collections.ObjectModel.Collection.Add
|
||||||
|
(-> (System.Collections.ObjectModel.Collection System.String) System.String void)))
|
||||||
|
(start-process (: System.Diagnostics.Process.Start (-> ProcessStartInfo Process)))
|
||||||
|
(wait-for-exit (: System.Diagnostics.Process.WaitForExit (-> Process int bool)))
|
||||||
|
(exit-code-of (: System.Diagnostics.Process.ExitCode (-> Process int) #:get))
|
||||||
|
(dispose-process (: System.Diagnostics.Process.Dispose (-> Process void))))
|
||||||
|
|
||||||
|
;; True for an http or https address, in any case.
|
||||||
|
(: (-> string bool))
|
||||||
|
(defun (browser-scheme? address)
|
||||||
|
(match (parse-url address)
|
||||||
|
((Ok u) (match (url-scheme u)
|
||||||
|
((Some s) (let ((scheme (string-downcase s))) (or (= scheme "http") (= scheme "https"))))
|
||||||
|
(None #f)))
|
||||||
|
((Err _) #f)))
|
||||||
|
|
||||||
|
;; How an address is opened: a program, with its arguments, or the shell of
|
||||||
|
;; Windows, which takes the address itself.
|
||||||
|
(type (: Opener (Union (: Run string (Vec string))
|
||||||
|
WindowsShell)))
|
||||||
|
|
||||||
|
;; The variables that host-spawn gives the host's xdg-open.
|
||||||
|
;; - With no display, xdg-open tries only browsers that run in a terminal.
|
||||||
|
;; - Not XDG_CURRENT_DESKTOP: with it, xdg-open uses the desktop's own
|
||||||
|
;; opener, which needs more of the session's variables, as KDE's needs
|
||||||
|
;; KDE_SESSION_VERSION. Without it, xdg-open opens the address with the
|
||||||
|
;; program that is the user's default for it, as xdg-mime says, on any
|
||||||
|
;; desktop.
|
||||||
|
(: string)
|
||||||
|
(def host-variables "DISPLAY,WAYLAND_DISPLAY,XDG_SESSION_TYPE")
|
||||||
|
|
||||||
|
;; The opener of `address`. `browser` is BJOMARKS_BROWSER, if it is set, and
|
||||||
|
;; `host-spawn` is host-spawn, when this program runs in a distrobox
|
||||||
|
;; container.
|
||||||
|
(: (-> string (Option string) (Option string) Opener))
|
||||||
|
(defun (opener-for address browser host-spawn)
|
||||||
|
(match (Tuple browser host-spawn)
|
||||||
|
((Tuple (Some program) _) (Run program [address]))
|
||||||
|
((Tuple None (Some spawn)) (Run spawn ["-no-pty" "-env" host-variables "xdg-open" address]))
|
||||||
|
(_ (cond
|
||||||
|
((windows?) WindowsShell)
|
||||||
|
((macos?) (Run "open" [address]))
|
||||||
|
(else (Run "xdg-open" [address]))))))
|
||||||
|
|
||||||
|
;; The first `name` on the PATH, if there is one.
|
||||||
|
(: (-> string (Option string)))
|
||||||
|
(defun (on-path name)
|
||||||
|
(match (get-environment-variable "PATH")
|
||||||
|
((Some path)
|
||||||
|
(def found (vec-filter (fun (dir) (and (not (string-empty? dir)) (file-exists? (path-combine dir name))))
|
||||||
|
(string-split path ":")))
|
||||||
|
(if (vec-empty? found) None (Some (path-combine (vec-ref found 0) name))))
|
||||||
|
(None None)))
|
||||||
|
|
||||||
|
;; host-spawn, when this program runs in a container that distrobox made:
|
||||||
|
;; the file that podman or docker puts in each container is there, and
|
||||||
|
;; host-spawn is on the PATH. `None` anywhere else.
|
||||||
|
(: (-> (Option string)))
|
||||||
|
(defun (distrobox-host-spawn)
|
||||||
|
(if (or (file-exists? "/run/.containerenv") (file-exists? "/.dockerenv"))
|
||||||
|
(on-path "host-spawn")
|
||||||
|
None))
|
||||||
|
|
||||||
|
;; How long the opener is waited for, in milliseconds.
|
||||||
|
(: int)
|
||||||
|
(def wait-ms 5000)
|
||||||
|
|
||||||
|
;; Why the opener `program` that ended with `code` did not open the address.
|
||||||
|
;; xdg-open ends with 3 when it found no program for the address, and
|
||||||
|
;; host-spawn ends as the host's xdg-open did.
|
||||||
|
(: (-> string int string))
|
||||||
|
(defun (opener-failure program code)
|
||||||
|
(def name (option-ref-or (path-filename program) program))
|
||||||
|
(if (and (= code 3) (or (= name "xdg-open") (= name "host-spawn")))
|
||||||
|
"xdg-open found no program to open it with."
|
||||||
|
(str name " ended with code " (int->string code) ".")))
|
||||||
|
|
||||||
|
;; Starts `program` with `args`, and waits for it a while.
|
||||||
|
(: (-> string (Vec string) string (Result string string)))
|
||||||
|
(defun (run-opener program args address)
|
||||||
|
(def info (ProcessStartInfo. program))
|
||||||
|
(shell-execute! info #f)
|
||||||
|
(loop (:for a args) (:do (add-argument! (arguments-of info) (string->clr-string a))))
|
||||||
|
(def p (start-process info))
|
||||||
|
(def ended (wait-for-exit p wait-ms))
|
||||||
|
(def code (if ended (exit-code-of p) 0))
|
||||||
|
(dispose-process p)
|
||||||
|
(if (= code 0)
|
||||||
|
(Ok (str "Opened " address))
|
||||||
|
(Err (str "Could not open " address ": " (opener-failure program code)))))
|
||||||
|
|
||||||
|
;; Gives `address` to the shell of Windows.
|
||||||
|
(: (-> string (Result string string)))
|
||||||
|
(defun (shell-open address)
|
||||||
|
(def info (ProcessStartInfo. address))
|
||||||
|
(shell-execute! info #t)
|
||||||
|
(def p (start-process info))
|
||||||
|
;; Start returns no process when the shell gave the address to one that
|
||||||
|
;; was already running.
|
||||||
|
(unless (eq? (cast Object p) (clr-default)) (dispose-process p))
|
||||||
|
(Ok (str "Opened " address)))
|
||||||
|
|
||||||
|
;; Opens `address`, and returns what was done, for the status line: the
|
||||||
|
;; text says it was opened, or why not. Raises what starting the program
|
||||||
|
;; raises, such as when BJOMARKS_BROWSER names no program. `#:host-spawn` is
|
||||||
|
;; host-spawn in a distrobox container: see `distrobox-host-spawn`.
|
||||||
|
(: (-> string (#:host-spawn (Option string)) (Result string string)))
|
||||||
|
(defun (open-in-browser address #:host-spawn (distrobox-host-spawn))
|
||||||
|
(if (not (browser-scheme? address))
|
||||||
|
(Err (str "Only http and https addresses are opened: " address))
|
||||||
|
(match (opener-for address (get-environment-variable "BJOMARKS_BROWSER") host-spawn)
|
||||||
|
((Run program args) (run-opener program args address))
|
||||||
|
(WindowsShell (shell-open address)))))
|
||||||
|
|
||||||
|
;; ---------------------------------------------------------------------------
|
||||||
|
;; A private window
|
||||||
|
;; ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
;; The flag that opens a private window in the browser of the .desktop file
|
||||||
|
;; `id`, such as "org.mozilla.firefox.desktop". None for one not known.
|
||||||
|
(: (-> string (Option string)))
|
||||||
|
(defun (private-flag id)
|
||||||
|
(def name (string-downcase id))
|
||||||
|
(defun (has? words) (not (vec-empty? (vec-filter (fun (w) (string-contains? name w)) words))))
|
||||||
|
(cond
|
||||||
|
((has? ["firefox" "librewolf" "waterfox" "floorp" "zen"]) (Some "--private-window"))
|
||||||
|
((has? ["edge"]) (Some "--inprivate"))
|
||||||
|
((has? ["chrome" "chromium" "brave" "vivaldi" "opera"]) (Some "--incognito"))
|
||||||
|
(else None)))
|
||||||
|
|
||||||
|
;; The words of the Exec line `exec` of a .desktop file, without its field
|
||||||
|
;; codes (%u, %U and the others) and flatpak's @@ marks. A word in double
|
||||||
|
;; quotes is one word.
|
||||||
|
(: (-> string (Vec string)))
|
||||||
|
(defun (exec-words exec)
|
||||||
|
(def chars (string->list exec))
|
||||||
|
(def words
|
||||||
|
(let go ((cs chars) (word "") (quoted #f) (started #f) (out []))
|
||||||
|
(match cs
|
||||||
|
((List c rest ...)
|
||||||
|
(cond
|
||||||
|
((char=? c #\") (go rest word (not quoted) #t out))
|
||||||
|
((and (char=? c #\space) (not quoted)) (if started (go rest "" #f #f (vec-add out word)) (go rest "" #f #f out)))
|
||||||
|
(else (go rest (str word (char->string c)) quoted #t out))))
|
||||||
|
(_ (if started (vec-add out word) out)))))
|
||||||
|
(vec-filter (fun (w) (not (or (string-starts-with? w "%") (string-starts-with? w "@@")))) words))
|
||||||
|
|
||||||
|
;; The program and its arguments that open `address` in a private window of
|
||||||
|
;; the browser of the .desktop file `id`, whose Exec line is `exec`.
|
||||||
|
(: (-> string string string (Option (Tuple string (Vec string)))))
|
||||||
|
(defun (private-command id exec address)
|
||||||
|
(def words (exec-words exec))
|
||||||
|
(match (private-flag id)
|
||||||
|
((Some flag) #:when (not (vec-empty? words))
|
||||||
|
(Some (Tuple (vec-ref words 0) (vec-append (vec-drop words 1) [flag address]))))
|
||||||
|
(_ None)))
|
||||||
|
|
||||||
|
;; What `program` with `args` writes, when it ends with 0 within the wait.
|
||||||
|
(: (-> string (Vec string) (Option string)))
|
||||||
|
(defun (output-of-program program args)
|
||||||
|
(: (-> (Option string)))
|
||||||
|
(defun (run)
|
||||||
|
(def info (ProcessStartInfo. program))
|
||||||
|
(shell-execute! info #f)
|
||||||
|
(redirect-output! info #t)
|
||||||
|
(loop (:for a args) (:do (add-argument! (arguments-of info) (string->clr-string a))))
|
||||||
|
(def p (start-process info))
|
||||||
|
(def text (read-to-end (output-of p)))
|
||||||
|
(def ended (wait-for-exit p wait-ms))
|
||||||
|
(def ok (and ended (= (exit-code-of p) 0)))
|
||||||
|
(dispose-process p)
|
||||||
|
(if ok (Some (string-trim text)) None))
|
||||||
|
(match (try (run) #:catch (System.Exception))
|
||||||
|
((Ok r) r)
|
||||||
|
((Err _) None)))
|
||||||
|
|
||||||
|
;; The folders of .desktop files: the user's, the system's, and flatpak's.
|
||||||
|
;; In a container, the host's system folders are under /run/host.
|
||||||
|
(: (-> bool (Vec string)))
|
||||||
|
(defun (application-folders in-container)
|
||||||
|
(def home (option-ref-or (get-environment-variable "XDG_DATA_HOME")
|
||||||
|
(path-combine (home-directory) ".local" "share")))
|
||||||
|
(def system (vec-filter (fun (d) (not (string-empty? d)))
|
||||||
|
(string-split (option-ref-or (get-environment-variable "XDG_DATA_DIRS")
|
||||||
|
"/usr/local/share:/usr/share")
|
||||||
|
":")))
|
||||||
|
(def systems (vec-append (if in-container
|
||||||
|
(vec-append ["/usr/local/share" "/usr/share"] system)
|
||||||
|
system)
|
||||||
|
["/var/lib/flatpak/exports/share"]))
|
||||||
|
(vec-append [(path-combine home "applications")
|
||||||
|
(path-combine home "flatpak" "exports" "share" "applications")]
|
||||||
|
(vec-map (fun (d) (path-combine (if in-container (str "/run/host" d) d) "applications")) systems)))
|
||||||
|
|
||||||
|
;; The first Exec line of the .desktop file `id`, in `folders`.
|
||||||
|
(: (-> string (Vec string) (Option string)))
|
||||||
|
(defun (desktop-exec id folders)
|
||||||
|
(def found (vec-filter file-exists? (vec-map (fun (d) (path-combine d id)) folders)))
|
||||||
|
(if (vec-empty? found)
|
||||||
|
None
|
||||||
|
(let ((lines (string-split (file-read-text (vec-ref found 0)) "\n")))
|
||||||
|
(def execs (vec-filter (fun (l) (string-starts-with? l "Exec=")) lines))
|
||||||
|
(if (vec-empty? execs) None (Some (string-drop (vec-ref execs 0) 5))))))
|
||||||
|
|
||||||
|
;; Opens `address` in a private window, and returns what was done, for the
|
||||||
|
;; status line. `Err` when there is no private window to open it in: see the
|
||||||
|
;; top of this module.
|
||||||
|
(: (-> string (#:host-spawn (Option string)) (Result string string)))
|
||||||
|
(defun (open-private-in-browser address #:host-spawn (distrobox-host-spawn))
|
||||||
|
(def none (str "No private window here: the browser is not one this app knows how to ask for one."))
|
||||||
|
(cond
|
||||||
|
((not (browser-scheme? address)) (Err (str "Only http and https addresses are opened: " address)))
|
||||||
|
(else
|
||||||
|
(match (get-environment-variable "BJOMARKS_PRIVATE_BROWSER")
|
||||||
|
((Some program) (run-opener program [address] address))
|
||||||
|
(None
|
||||||
|
(if (or (windows?) (macos?))
|
||||||
|
(Err none)
|
||||||
|
(let ((id (match host-spawn
|
||||||
|
((Some spawn) (output-of-program spawn ["-no-pty" "xdg-settings" "get" "default-web-browser"]))
|
||||||
|
(None (output-of-program "xdg-settings" ["get" "default-web-browser"])))))
|
||||||
|
(match (match id
|
||||||
|
((Some i) (match (desktop-exec i (application-folders (some? host-spawn)))
|
||||||
|
((Some exec) (private-command i exec address))
|
||||||
|
(None None)))
|
||||||
|
(None None))
|
||||||
|
((Some (Tuple program args))
|
||||||
|
(match host-spawn
|
||||||
|
((Some spawn)
|
||||||
|
(run-opener spawn (vec-append ["-no-pty" "-env" host-variables program] args) address))
|
||||||
|
(None (run-opener program args address))))
|
||||||
|
(None (Err none))))))))))
|
||||||
|
|
||||||
207
src/fetch-button.bjo
Normal file
207
src/fetch-button.bjo
Normal file
|
|
@ -0,0 +1,207 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
;; bjomarks-gui/src/fetch-button.bjo — the module (bjomarks-gui fetch-button):
|
||||||
|
;; the buttons that fetch a title and an archive link, with a spinner while
|
||||||
|
;; they work.
|
||||||
|
;;
|
||||||
|
;; - `fetch-button` is beside the title, and `archive-button` beside the
|
||||||
|
;; archive link. Both are made by `spinner-button`.
|
||||||
|
;; - The value of a button is true while its fetch runs. Then the label is hidden, and an
|
||||||
|
;; arc turns in its place, longer and shorter as it turns. The button
|
||||||
|
;; keeps its size.
|
||||||
|
;; - The animation is Avalonia's, in a style of the arc that applies while
|
||||||
|
;; the arc has the class "spinning". So it runs on the render loop, and
|
||||||
|
;; only while a fetch runs.
|
||||||
|
;; - A click sends `FetchPressed`, also while a fetch runs: the program
|
||||||
|
;; decides what that does.
|
||||||
|
;;
|
||||||
|
;; bjogui has no animations, so the button is an Avalonia `Button`, made
|
||||||
|
;; with (bjogui native).
|
||||||
|
|
||||||
|
(export FetchOut fetch-button archive-button)
|
||||||
|
|
||||||
|
(import (std prelude))
|
||||||
|
(import (std interop))
|
||||||
|
(import (bjogui native))
|
||||||
|
|
||||||
|
(import/class
|
||||||
|
(Object (: System.Object))
|
||||||
|
(TimeSpan (: System.TimeSpan))
|
||||||
|
(Control (: Avalonia.Controls.Control))
|
||||||
|
(Button (: Avalonia.Controls.Button (-> Button)))
|
||||||
|
(ContentControl (: Avalonia.Controls.ContentControl))
|
||||||
|
(Grid (: Avalonia.Controls.Grid (-> Grid)))
|
||||||
|
(Panel (: Avalonia.Controls.Panel))
|
||||||
|
(Controls (: Avalonia.Controls.Controls))
|
||||||
|
(TextBlock (: Avalonia.Controls.TextBlock (-> TextBlock)))
|
||||||
|
(Arc (: Avalonia.Controls.Shapes.Arc (-> Arc)))
|
||||||
|
(Shape (: Avalonia.Controls.Shapes.Shape))
|
||||||
|
(IBrush (: Avalonia.Media.IBrush))
|
||||||
|
(PenLineCap (: Avalonia.Media.PenLineCap))
|
||||||
|
(Layoutable (: Avalonia.Layout.Layoutable))
|
||||||
|
(HAlign (: Avalonia.Layout.HorizontalAlignment))
|
||||||
|
(VAlign (: Avalonia.Layout.VerticalAlignment))
|
||||||
|
(Visual (: Avalonia.Visual))
|
||||||
|
(StyledElement (: Avalonia.StyledElement))
|
||||||
|
(AvaloniaObject (: Avalonia.AvaloniaObject))
|
||||||
|
(AvaloniaProperty (: Avalonia.AvaloniaProperty))
|
||||||
|
(Classes (: Avalonia.Controls.Classes))
|
||||||
|
(Styles (: Avalonia.Styling.Styles))
|
||||||
|
(IStyle (: Avalonia.Styling.IStyle))
|
||||||
|
(Style (: Avalonia.Styling.Style (-> Style)))
|
||||||
|
(StyleBase (: Avalonia.Styling.StyleBase))
|
||||||
|
(Selector (: Avalonia.Styling.Selector))
|
||||||
|
(Setter (: Avalonia.Styling.Setter (-> AvaloniaProperty Object Setter)))
|
||||||
|
(Animation (: Avalonia.Animation.Animation (-> Animation)))
|
||||||
|
(IAnimation (: Avalonia.Animation.IAnimation))
|
||||||
|
(KeyFrame (: Avalonia.Animation.KeyFrame (-> KeyFrame)))
|
||||||
|
(KeyFrames (: Avalonia.Animation.KeyFrames))
|
||||||
|
(IAnimationSetter (: Avalonia.Animation.IAnimationSetter))
|
||||||
|
(Cue (: Avalonia.Animation.Cue (-> double Cue)))
|
||||||
|
(IterationCount (: Avalonia.Animation.IterationCount))
|
||||||
|
(Easing (: Avalonia.Animation.Easings.Easing))
|
||||||
|
(SineEaseInOut (: Avalonia.Animation.Easings.SineEaseInOut (-> SineEaseInOut)))
|
||||||
|
((ICollection %a) (: System.Collections.Generic.ICollection))
|
||||||
|
((IList %a) (: System.Collections.Generic.IList))
|
||||||
|
((AvaloniaList %a) (: Avalonia.Collections.AvaloniaList)))
|
||||||
|
|
||||||
|
(import/extern
|
||||||
|
;; Typed, so that a Native AOT build keeps the event.
|
||||||
|
(on-click! (: Avalonia.Controls.Button.Click #:event)))
|
||||||
|
|
||||||
|
(import/extern
|
||||||
|
(from-ms (: System.TimeSpan.FromMilliseconds (-> double TimeSpan)))
|
||||||
|
(content! (: Avalonia.Controls.ContentControl.Content (-> ContentControl Object void) #:set))
|
||||||
|
(children-of (: Avalonia.Controls.Panel.Children (-> Panel Controls) #:get))
|
||||||
|
(child-at (: Avalonia.Controls.Controls.get_Item (-> Controls int Control)))
|
||||||
|
(text! (: Avalonia.Controls.TextBlock.Text (-> TextBlock string void) #:set))
|
||||||
|
(width! (: Avalonia.Layout.Layoutable.Width (-> Layoutable double void) #:set))
|
||||||
|
(height! (: Avalonia.Layout.Layoutable.Height (-> Layoutable double void) #:set))
|
||||||
|
(horizontal! (: Avalonia.Layout.Layoutable.HorizontalAlignment (-> Layoutable HAlign void) #:set))
|
||||||
|
(vertical! (: Avalonia.Layout.Layoutable.VerticalAlignment (-> Layoutable VAlign void) #:set))
|
||||||
|
(visible! (: Avalonia.Visual.IsVisible (-> Visual bool void) #:set))
|
||||||
|
(opacity! (: Avalonia.Visual.Opacity (-> Visual double void) #:set))
|
||||||
|
(start-angle! (: Avalonia.Controls.Shapes.Arc.StartAngle (-> Arc double void) #:set))
|
||||||
|
(sweep-angle! (: Avalonia.Controls.Shapes.Arc.SweepAngle (-> Arc double void) #:set))
|
||||||
|
(start-angle-property (: Avalonia.Controls.Shapes.Arc.StartAngleProperty #:get))
|
||||||
|
(sweep-angle-property (: Avalonia.Controls.Shapes.Arc.SweepAngleProperty #:get))
|
||||||
|
(stroke! (: Avalonia.Controls.Shapes.Shape.Stroke (-> Shape IBrush void) #:set))
|
||||||
|
(stroke-thickness! (: Avalonia.Controls.Shapes.Shape.StrokeThickness (-> Shape double void) #:set))
|
||||||
|
(stroke-cap! (: Avalonia.Controls.Shapes.Shape.StrokeLineCap (-> Shape PenLineCap void) #:set))
|
||||||
|
(foreground-property (: Avalonia.Controls.Primitives.TemplatedControl.ForegroundProperty #:get))
|
||||||
|
(get-value (: Avalonia.AvaloniaObject.GetValue (-> AvaloniaObject AvaloniaProperty Object)))
|
||||||
|
(classes-of (: Avalonia.StyledElement.Classes (-> StyledElement Classes) #:get))
|
||||||
|
(class-set! (: Avalonia.Controls.Classes.Set (-> Classes string bool void)))
|
||||||
|
(styles-of (: Avalonia.StyledElement.Styles (-> StyledElement Styles) #:get))
|
||||||
|
(styles-add! (: Avalonia.Styling.Styles.Add (-> Styles IStyle void)))
|
||||||
|
(selector! (: Avalonia.Styling.Style.Selector (-> Style Selector void) #:set))
|
||||||
|
(class-selector (: Avalonia.Styling.Selectors.Class (-> Selector string Selector)))
|
||||||
|
(animations-of (: Avalonia.Styling.StyleBase.Animations (-> StyleBase (IList IAnimation)) #:get))
|
||||||
|
(duration! (: Avalonia.Animation.Animation.Duration (-> Animation TimeSpan void) #:set))
|
||||||
|
(iterations! (: Avalonia.Animation.Animation.IterationCount (-> Animation IterationCount void) #:set))
|
||||||
|
(easing! (: Avalonia.Animation.Animation.Easing (-> Animation Easing void) #:set))
|
||||||
|
(forever (: Avalonia.Animation.IterationCount.Infinite #:get))
|
||||||
|
(key-frames-of (: Avalonia.Animation.Animation.Children (-> Animation KeyFrames) #:get))
|
||||||
|
(setters-of (: Avalonia.Animation.KeyFrame.Setters (-> KeyFrame (AvaloniaList IAnimationSetter)) #:get))
|
||||||
|
(cue! (: Avalonia.Animation.KeyFrame.Cue (-> KeyFrame Cue void) #:set))
|
||||||
|
(add-to! (: System.Collections.Generic.ICollection.Add (-> (ICollection %a) %a void))))
|
||||||
|
|
||||||
|
;; What the button sends: it was clicked.
|
||||||
|
(type (: FetchOut (Union FetchPressed)))
|
||||||
|
|
||||||
|
;; The class that makes the arc turn.
|
||||||
|
(: string)
|
||||||
|
(def spinning "spinning")
|
||||||
|
|
||||||
|
;; An animation of `property` through `values`, evenly spaced, in `ms`
|
||||||
|
;; milliseconds, again and again.
|
||||||
|
(: (-> AvaloniaProperty (Vec double) double Animation))
|
||||||
|
(defun (looping property values ms)
|
||||||
|
(def a (Animation.))
|
||||||
|
(duration! a (from-ms ms))
|
||||||
|
(iterations! a forever)
|
||||||
|
(def n (vec-length values))
|
||||||
|
(loop (:for i (range 0 n))
|
||||||
|
(:do (def k (KeyFrame.))
|
||||||
|
(cue! k (Cue. (/ (cast double i) (cast double (- n 1)))))
|
||||||
|
(add-to! (cast (ICollection IAnimationSetter) (setters-of k))
|
||||||
|
(cast IAnimationSetter (Setter. property (cast Object (vec-ref values i)))))
|
||||||
|
(add-to! (cast (ICollection KeyFrame) (key-frames-of a)) k)))
|
||||||
|
a)
|
||||||
|
|
||||||
|
;; The style that turns an arc while it has the class "spinning": its start
|
||||||
|
;; goes round once in 0.9 s, and its length grows and shrinks in 1.6 s, so
|
||||||
|
;; that the two do not keep step.
|
||||||
|
(: (-> Style))
|
||||||
|
(defun (spin-style)
|
||||||
|
(def s (Style.))
|
||||||
|
(selector! s (class-selector (clr-default) spinning))
|
||||||
|
(def turn (looping (cast AvaloniaProperty start-angle-property) [0.0 360.0] 900.0))
|
||||||
|
(def breathe (looping (cast AvaloniaProperty sweep-angle-property) [60.0 270.0 60.0] 1600.0))
|
||||||
|
(easing! breathe (cast Easing (SineEaseInOut.)))
|
||||||
|
(def animations (cast (ICollection IAnimation) (animations-of s)))
|
||||||
|
(add-to! animations (cast IAnimation turn))
|
||||||
|
(add-to! animations (cast IAnimation breathe))
|
||||||
|
s)
|
||||||
|
|
||||||
|
(: (-> Control Grid))
|
||||||
|
(defun (face-of button) (cast Grid (.-Content (cast ContentControl button))))
|
||||||
|
|
||||||
|
;; The label and the arc, in the button.
|
||||||
|
(: (-> Control (Tuple TextBlock Arc)))
|
||||||
|
(defun (parts-of button)
|
||||||
|
(def kids (children-of (cast Panel (face-of button))))
|
||||||
|
(Tuple (cast TextBlock (child-at kids 0)) (cast Arc (child-at kids 1))))
|
||||||
|
|
||||||
|
;; The arc is drawn in the colour of the button's text, when the button has
|
||||||
|
;; one.
|
||||||
|
(: (-> Control Arc void))
|
||||||
|
(defun (colour-arc! button arc)
|
||||||
|
(match (get-value (cast AvaloniaObject button) (cast AvaloniaProperty foreground-property))
|
||||||
|
((:is Avalonia.Media.IBrush brush) (stroke! (cast Shape arc) brush))
|
||||||
|
(_ unit)))
|
||||||
|
|
||||||
|
;; A button labelled `label`, with a spinner while its value is true.
|
||||||
|
(: (-> string (Native bool FetchOut)))
|
||||||
|
(defun (spinner-button label)
|
||||||
|
(native (fun (send)
|
||||||
|
(def text (TextBlock.))
|
||||||
|
(text! text label)
|
||||||
|
(horizontal! (cast Layoutable text) HAlign.Center)
|
||||||
|
(vertical! (cast Layoutable text) VAlign.Center)
|
||||||
|
(def arc (Arc.))
|
||||||
|
(width! (cast Layoutable arc) 16.0)
|
||||||
|
(height! (cast Layoutable arc) 16.0)
|
||||||
|
(horizontal! (cast Layoutable arc) HAlign.Center)
|
||||||
|
(vertical! (cast Layoutable arc) VAlign.Center)
|
||||||
|
(start-angle! arc 0.0)
|
||||||
|
(sweep-angle! arc 270.0)
|
||||||
|
(stroke-thickness! (cast Shape arc) 2.0)
|
||||||
|
(stroke-cap! (cast Shape arc) PenLineCap.Round)
|
||||||
|
(visible! (cast Visual arc) #f)
|
||||||
|
(styles-add! (styles-of (cast StyledElement arc)) (cast IStyle (spin-style)))
|
||||||
|
;; One cell: the arc is over the label, and the label gives the
|
||||||
|
;; button its size.
|
||||||
|
(def face (Grid.))
|
||||||
|
(.Add (children-of (cast Panel face)) (cast Control text))
|
||||||
|
(.Add (children-of (cast Panel face)) (cast Control arc))
|
||||||
|
(def button (Button.))
|
||||||
|
(content! (cast ContentControl button) (cast Object face))
|
||||||
|
(ignore (on-click! button (fun (s e) (send FetchPressed))))
|
||||||
|
(cast Control button))
|
||||||
|
(fun (control busy)
|
||||||
|
(def (Tuple text arc) (parts-of control))
|
||||||
|
(when busy (colour-arc! control arc))
|
||||||
|
(opacity! (cast Visual text) (if busy 0.0 1.0))
|
||||||
|
(visible! (cast Visual arc) busy)
|
||||||
|
(class-set! (classes-of (cast StyledElement arc)) spinning busy))))
|
||||||
|
|
||||||
|
;; The button beside the title of the dialog.
|
||||||
|
(: fetch-button (Native bool FetchOut))
|
||||||
|
(def fetch-button (spinner-button "Fetch title"))
|
||||||
|
|
||||||
|
;; The button beside the archive link of the dialog.
|
||||||
|
(: archive-button (Native bool FetchOut))
|
||||||
|
(def archive-button (spinner-button "Fetch archive"))
|
||||||
172
src/inputs.bjo
Normal file
172
src/inputs.bjo
Normal file
|
|
@ -0,0 +1,172 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
;; bjomarks-gui/src/inputs.bjo — the module (bjomarks-gui inputs): the two
|
||||||
|
;; text inputs that bjogui's `text-input` cannot be.
|
||||||
|
;;
|
||||||
|
;; - The search box hears Ctrl+N itself. Only the box knows that it has the
|
||||||
|
;; keyboard, and "Ctrl+N in the search box" goes to the first bookmark,
|
||||||
|
;; while Ctrl+N elsewhere goes to the next one.
|
||||||
|
;; - The search box hears Ctrl+Z too, when its value says that Ctrl+Z is
|
||||||
|
;; the window's. Else the box undoes its typing, and a TextBox takes
|
||||||
|
;; Ctrl+Z also when it has nothing to undo: the window would never hear it.
|
||||||
|
;; - The password box shows dots, and hears Enter. The first of a screen
|
||||||
|
;; takes the keyboard when it is shown.
|
||||||
|
;;
|
||||||
|
;; Both are Avalonia `TextBox`es, made with (bjogui native). The keys are
|
||||||
|
;; heard as they tunnel down to the box, before the box's own handling, so
|
||||||
|
;; that no key binding of the theme's or the box's can take them first. A
|
||||||
|
;; key the box hears is handled, and does not reach the window's keys.
|
||||||
|
|
||||||
|
(export SearchOut search-box PasswordOut password-box first-password-box)
|
||||||
|
|
||||||
|
(import (std prelude))
|
||||||
|
(import (std interop))
|
||||||
|
(import (bjogui native))
|
||||||
|
|
||||||
|
(import/class
|
||||||
|
(Object (: System.Object))
|
||||||
|
(Control (: Avalonia.Controls.Control))
|
||||||
|
(TextBox (: Avalonia.Controls.TextBox (-> TextBox)))
|
||||||
|
(Layoutable (: Avalonia.Layout.Layoutable))
|
||||||
|
(Alignment (: Avalonia.Layout.HorizontalAlignment))
|
||||||
|
(Interactive (: Avalonia.Interactivity.Interactive))
|
||||||
|
(RoutedEvent (: Avalonia.Interactivity.RoutedEvent))
|
||||||
|
(RoutedEventArgs (: Avalonia.Interactivity.RoutedEventArgs))
|
||||||
|
(Routes (: Avalonia.Interactivity.RoutingStrategies))
|
||||||
|
(KeyEventArgs (: Avalonia.Input.KeyEventArgs))
|
||||||
|
(KeyCode (: Avalonia.Input.Key))
|
||||||
|
(KeyModifiers (: Avalonia.Input.KeyModifiers))
|
||||||
|
(KeyGesture (: Avalonia.Input.KeyGesture (-> KeyCode KeyModifiers KeyGesture)))
|
||||||
|
(InputElement (: Avalonia.Input.InputElement))
|
||||||
|
(NavMethod (: Avalonia.Input.NavigationMethod))
|
||||||
|
((EventHandler %a) (: System.EventHandler)))
|
||||||
|
|
||||||
|
(import/extern
|
||||||
|
;; Typed, so that a Native AOT build keeps the event.
|
||||||
|
(on-loaded! (: Avalonia.Controls.Control.Loaded #:event)))
|
||||||
|
|
||||||
|
(import/extern
|
||||||
|
(text-of (: Avalonia.Controls.TextBox.Text (-> TextBox string) #:get))
|
||||||
|
(text! (: Avalonia.Controls.TextBox.Text (-> TextBox string void) #:set))
|
||||||
|
(placeholder! (: Avalonia.Controls.TextBox.PlaceholderText (-> TextBox string void) #:set))
|
||||||
|
(horizontal! (: Avalonia.Layout.Layoutable.HorizontalAlignment (-> Layoutable Alignment void) #:set))
|
||||||
|
(password-char! (: Avalonia.Controls.TextBox.PasswordChar (-> TextBox System.Char void) #:set))
|
||||||
|
(text-changing (: Avalonia.Controls.TextBox.TextChangingEvent #:get))
|
||||||
|
(key-down-event (: Avalonia.Input.InputElement.KeyDownEvent #:get))
|
||||||
|
(got-focus-event (: Avalonia.Input.InputElement.GotFocusEvent #:get))
|
||||||
|
(lost-focus-event (: Avalonia.Input.InputElement.LostFocusEvent #:get))
|
||||||
|
(add-handler (: Avalonia.Interactivity.Interactive.AddHandler
|
||||||
|
(-> Interactive RoutedEvent Delegate Routes bool void)))
|
||||||
|
(handled! (: Avalonia.Interactivity.RoutedEventArgs.Handled (-> RoutedEventArgs bool void) #:set))
|
||||||
|
(key-of (: Avalonia.Input.KeyEventArgs.Key (-> KeyEventArgs KeyCode) #:get))
|
||||||
|
(modifiers-of (: Avalonia.Input.KeyEventArgs.KeyModifiers (-> KeyEventArgs KeyModifiers) #:get))
|
||||||
|
(gesture-text (: Avalonia.Input.KeyGesture.ToString (-> KeyGesture string)))
|
||||||
|
(tag-of (: Avalonia.Controls.Control.Tag (-> Control Object) #:get))
|
||||||
|
(tag! (: Avalonia.Controls.Control.Tag (-> Control Object void) #:set))
|
||||||
|
;; Both arguments, as Bjolang does not fill in .NET's optional ones.
|
||||||
|
(focus! (: Avalonia.Input.InputElement.Focus (-> InputElement NavMethod KeyModifiers bool))))
|
||||||
|
|
||||||
|
(: (-> TextBox RoutedEvent Routes (-> RoutedEventArgs void) void))
|
||||||
|
(defun (listen! box event routes f)
|
||||||
|
(add-handler (cast Interactive box) event
|
||||||
|
(cast Delegate (cast Object (: (as-delegate (: (fun (s e) (f e)) (-> Object RoutedEventArgs void)))
|
||||||
|
(EventHandler RoutedEventArgs))))
|
||||||
|
routes #f))
|
||||||
|
|
||||||
|
;; Calls `(f keys)` for each key pressed in the box, with the keys written as
|
||||||
|
;; "Ctrl+N" is. When it returns true, the key is handled.
|
||||||
|
(: (-> TextBox (-> string bool) void))
|
||||||
|
(defun (on-keys! box f)
|
||||||
|
(listen! box (cast RoutedEvent key-down-event) Routes.Tunnel
|
||||||
|
(fun (e)
|
||||||
|
(def k (cast KeyEventArgs e))
|
||||||
|
(when (f (gesture-text (KeyGesture. (key-of k) (modifiers-of k))))
|
||||||
|
(handled! e #t)))))
|
||||||
|
|
||||||
|
;; Calls `(f text)` for each change of the text.
|
||||||
|
(: (-> TextBox (-> string void) void))
|
||||||
|
(defun (on-text! box f)
|
||||||
|
(listen! box (cast RoutedEvent text-changing) Routes.Bubble (fun (e) (f (text-of box)))))
|
||||||
|
|
||||||
|
;; Sets the text, if it is another: setting the same text moves the caret.
|
||||||
|
(: (-> Control string void))
|
||||||
|
(defun (show-text! control value)
|
||||||
|
(def box (cast TextBox control))
|
||||||
|
(unless (= (text-of box) value) (text! box value)))
|
||||||
|
|
||||||
|
;; What the search box sends: the text, at each change; Ctrl+N; Ctrl+Z, when
|
||||||
|
;; it is not the box's; and whether it has the keyboard, each time that
|
||||||
|
;; changes: a removal then leaves the keyboard in the box.
|
||||||
|
(type (: SearchOut (Union (: SearchTyped string) SearchNext SearchUndo (: SearchFocus bool))))
|
||||||
|
|
||||||
|
;; True when Ctrl+Z is the window's, as the box's value last said. It is kept
|
||||||
|
;; in the box's `Tag`, as the key is heard when no value is at hand.
|
||||||
|
(: (-> Control bool))
|
||||||
|
(defun (window-undo? control)
|
||||||
|
(match (tag-of control)
|
||||||
|
((:is System.Boolean b) b)
|
||||||
|
(_ #f)))
|
||||||
|
|
||||||
|
;; A search box's value is its text, and whether Ctrl+Z in it is the
|
||||||
|
;; window's: then the box sends `SearchUndo` and does not undo its typing.
|
||||||
|
;; The program says so when the last thing done is one that Ctrl+Z undoes,
|
||||||
|
;; and nothing was typed in the box after it.
|
||||||
|
(: search-box (Native (Tuple string bool) SearchOut))
|
||||||
|
(def search-box
|
||||||
|
(native (fun (send)
|
||||||
|
(def box (TextBox.))
|
||||||
|
(placeholder! box "Search: words, t:tag, d:site, a:2024")
|
||||||
|
(listen! box (cast RoutedEvent got-focus-event) Routes.Bubble (fun (e) (send (SearchFocus #t))))
|
||||||
|
(listen! box (cast RoutedEvent lost-focus-event) Routes.Bubble (fun (e) (send (SearchFocus #f))))
|
||||||
|
(on-text! box (fun (s) (send (SearchTyped s))))
|
||||||
|
(on-keys! box (fun (keys)
|
||||||
|
(cond
|
||||||
|
((= keys "Ctrl+N") (send SearchNext) #t)
|
||||||
|
((and (= keys "Ctrl+Z") (window-undo? (cast Control box)))
|
||||||
|
(send SearchUndo)
|
||||||
|
#t)
|
||||||
|
(else #f))))
|
||||||
|
(cast Control box))
|
||||||
|
(fun (control value)
|
||||||
|
(def (Tuple text window-undo) value)
|
||||||
|
(tag! control (cast Object window-undo))
|
||||||
|
(show-text! control text))))
|
||||||
|
|
||||||
|
;; What the password box sends: the text, at each change, and Enter.
|
||||||
|
(type (: PasswordOut (Union (: PasswordTyped string) PasswordEnter)))
|
||||||
|
|
||||||
|
;; A password box's value is its placeholder and its text. It stands at the
|
||||||
|
;; left of the space it is given, as wide as its view says. With
|
||||||
|
;; `focus-when-shown`, it takes the keyboard when Avalonia has loaded it:
|
||||||
|
;; bjogui has no command that runs when the window opens.
|
||||||
|
(: (-> bool (Native (Tuple string string) PasswordOut)))
|
||||||
|
(defun (password-box-kind focus-when-shown)
|
||||||
|
(native (fun (send)
|
||||||
|
(def box (TextBox.))
|
||||||
|
(password-char! box (cast System.Char 8226))
|
||||||
|
(horizontal! (cast Layoutable box) Alignment.Left)
|
||||||
|
(when focus-when-shown
|
||||||
|
(ignore (on-loaded! (cast Control box)
|
||||||
|
(fun (s e) (ignore (focus! (cast InputElement box) NavMethod.Unspecified KeyModifiers.None))))))
|
||||||
|
(on-text! box (fun (s) (send (PasswordTyped s))))
|
||||||
|
(on-keys! box (fun (keys)
|
||||||
|
;; Avalonia's Key.Enter and Key.Return are one
|
||||||
|
;; value, which a gesture writes as "Return".
|
||||||
|
(if (or (= keys "Enter") (= keys "Return"))
|
||||||
|
(begin (send PasswordEnter) #t)
|
||||||
|
#f)))
|
||||||
|
(cast Control box))
|
||||||
|
(fun (control value)
|
||||||
|
(def (Tuple placeholder text) value)
|
||||||
|
(placeholder! (cast TextBox control) placeholder)
|
||||||
|
(show-text! control text))))
|
||||||
|
|
||||||
|
(: password-box (Native (Tuple string string) PasswordOut))
|
||||||
|
(def password-box (password-box-kind #f))
|
||||||
|
|
||||||
|
;; The first password box of a screen: it has the keyboard when the screen
|
||||||
|
;; is shown.
|
||||||
|
(: first-password-box (Native (Tuple string string) PasswordOut))
|
||||||
|
(def first-password-box (password-box-kind #t))
|
||||||
73
src/main.bjo
Normal file
73
src/main.bjo
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
;; (bjomarks-gui) — bookmarks in a window.
|
||||||
|
;;
|
||||||
|
;; bjo run . [SHARED [LOCAL]]
|
||||||
|
;;
|
||||||
|
;; SHARED is the folder that the devices share, through a file syncer or a
|
||||||
|
;; mounted WebDAV share: BJOMARKS_SHARED unless given, else the folder chosen
|
||||||
|
;; on the first screen, else ~/Sync/bookmarks. The first screen lists the
|
||||||
|
;; folders added, saved in ~/.config/bjomarks/settings.json, with "Add
|
||||||
|
;; new…" after them; it is there only when neither SHARED nor
|
||||||
|
;; BJOMARKS_SHARED is given.
|
||||||
|
;; LOCAL is this device's own folder: BJOMARKS_LOCAL, or "bjomarks" in the
|
||||||
|
;; user's data folder, unless given. See (bjomarks-gui app) for the window.
|
||||||
|
;;
|
||||||
|
;; Enter opens a bookmark with the system's opener (xdg-open on Linux; in a
|
||||||
|
;; distrobox container, the host's, through host-spawn), or with the program
|
||||||
|
;; BJOMARKS_BROWSER names: see (bjomarks-gui browser).
|
||||||
|
;;
|
||||||
|
;; A title is fetched from the site only when the button beside the title,
|
||||||
|
;; in the dialog, is clicked.
|
||||||
|
;;
|
||||||
|
;; The window has KDE's look: AvaUnion draws it with the session's Union
|
||||||
|
;; style, colours and fonts, or with the Breeze snapshot it carries when
|
||||||
|
;; there is no KDE session. BJOMARKS_LOOK=fluent draws it with Avalonia's
|
||||||
|
;; Fluent theme instead.
|
||||||
|
|
||||||
|
(import (std prelude))
|
||||||
|
(import (std os))
|
||||||
|
(import (bjogui app))
|
||||||
|
(import (bjomarks store))
|
||||||
|
(import (bjomarks-gui app))
|
||||||
|
(import (bjomarks-gui settings))
|
||||||
|
|
||||||
|
(import/class
|
||||||
|
(UnionTheme (: AvaUnion.UnionTheme (-> UnionTheme))))
|
||||||
|
|
||||||
|
(: (-> string (List IStyle)))
|
||||||
|
(defun (themes look)
|
||||||
|
(match look
|
||||||
|
("fluent" (list (fluent-theme)))
|
||||||
|
(_ (list (cast IStyle (UnionTheme.))))))
|
||||||
|
|
||||||
|
(: (-> (Vec string) int string string string))
|
||||||
|
(defun (arg-or args i variable fallback)
|
||||||
|
(if (> (vec-length args) i)
|
||||||
|
(vec-ref args i)
|
||||||
|
(option-ref-or (get-environment-variable variable) fallback)))
|
||||||
|
|
||||||
|
(: (-> (Vec string) int))
|
||||||
|
(defun (main args)
|
||||||
|
(def settings (settings-folder))
|
||||||
|
;; An argument or BJOMARKS_SHARED fixes the shared folder. Else it is the
|
||||||
|
;; one saved in the settings, which the first screen can change.
|
||||||
|
(def fixed (or (> (vec-length args) 0) (some? (get-environment-variable "BJOMARKS_SHARED"))))
|
||||||
|
(def shared (arg-or args 0 "BJOMARKS_SHARED"
|
||||||
|
(option-ref-or (read-shared-folder settings)
|
||||||
|
(path-combine (home-directory) "Sync" "bookmarks"))))
|
||||||
|
;; An argument or BJOMARKS_LOCAL fixes this device's folder. Else each
|
||||||
|
;; shared folder has one of its own, in the app's data folder.
|
||||||
|
(def root (path-combine (data-directory) "bjomarks"))
|
||||||
|
(def local (arg-or args 1 "BJOMARKS_LOCAL" ""))
|
||||||
|
(def look (option-ref-or (get-environment-variable "BJOMARKS_LOOK") ""))
|
||||||
|
(run-app (initial-model (folder-storage shared) local #:settings (if fixed "" settings)
|
||||||
|
#:root (if (string-empty? local) (Some root) None)
|
||||||
|
#:vaults (if fixed [] (read-vaults settings))) gui-update view
|
||||||
|
#:windows windows #:keys keys #:subscriptions subscriptions
|
||||||
|
#:on-close (Some CloseAsked)
|
||||||
|
#:themes (fun () (themes look))
|
||||||
|
#:title "Bjomarks" #:width 640.0 #:height 520.0)
|
||||||
|
0)
|
||||||
105
src/settings.bjo
Normal file
105
src/settings.bjo
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
;; bjomarks-gui/src/settings.bjo — the module (bjomarks-gui settings): what
|
||||||
|
;; the window keeps between runs, in settings.json in a folder of its own.
|
||||||
|
;;
|
||||||
|
;; {"shared": "/home/me/Sync/bookmarks",
|
||||||
|
;; "vaults": ["/home/me/Sync/bookmarks", "/home/me/Sync/work"]}
|
||||||
|
;;
|
||||||
|
;; - The folder is "bjomarks" in the user's folder for configuration:
|
||||||
|
;; ~/.config/bjomarks on Linux, as XDG_CONFIG_HOME says.
|
||||||
|
;; - "shared" is the shared folder used last: where the vault is.
|
||||||
|
;; - "vaults" is the shared folders that the user added, in the order they
|
||||||
|
;; were added. The first screen shows them by the name of the folder.
|
||||||
|
;; Settings of an earlier version, with "shared" only, have that one.
|
||||||
|
;; - The fields that this version does not know are kept when it writes.
|
||||||
|
;; - The file is written whole and then renamed over the old one, so that it
|
||||||
|
;; is never half written.
|
||||||
|
|
||||||
|
(export settings-folder read-shared-folder save-shared-folder! read-vaults save-vaults!)
|
||||||
|
|
||||||
|
(import (std prelude))
|
||||||
|
(import (std os))
|
||||||
|
(import (text json))
|
||||||
|
|
||||||
|
(: string)
|
||||||
|
(def file-name "settings.json")
|
||||||
|
|
||||||
|
;; The folder of the settings: "bjomarks" in the user's folder for
|
||||||
|
;; configuration.
|
||||||
|
(: (-> string))
|
||||||
|
(defun (settings-folder) (path-combine (config-directory) "bjomarks"))
|
||||||
|
|
||||||
|
;; The fields of the settings in `folder`, in their order. None when there
|
||||||
|
;; is no settings file, or it is not a JSON object.
|
||||||
|
(: (-> string (Option (IArray (Tuple string Json)))))
|
||||||
|
(defun (read-fields folder)
|
||||||
|
(def file (path-combine folder file-name))
|
||||||
|
(if (not (file-exists? file))
|
||||||
|
None
|
||||||
|
(match (parse-json (file-read-text file) #:objects 'fields)
|
||||||
|
((Ok (JsonFields fields)) (Some fields))
|
||||||
|
(_ None))))
|
||||||
|
|
||||||
|
;; The shared folder saved in the settings in `folder`. None when none is
|
||||||
|
;; saved, or the file cannot be read as settings.
|
||||||
|
(: (-> string (Option string)))
|
||||||
|
(defun (read-shared-folder folder)
|
||||||
|
(match (read-fields folder)
|
||||||
|
((Some fields)
|
||||||
|
(match (json-object-ref (JsonFields fields) "shared")
|
||||||
|
((Some (JsonStr s)) (if (string-empty? (string-trim s)) None (Some s)))
|
||||||
|
(_ None)))
|
||||||
|
(None None)))
|
||||||
|
|
||||||
|
;; Saves `shared` as the shared folder in the settings in `folder`, and
|
||||||
|
;; keeps their other fields. Makes `folder` when it is not there. Raises
|
||||||
|
;; what the file system raises.
|
||||||
|
(: (-> string string void))
|
||||||
|
(defun (save-shared-folder! folder shared)
|
||||||
|
(save-fields! folder [(Tuple "shared" (JsonStr shared))]))
|
||||||
|
|
||||||
|
;; The shared folders saved in the settings in `folder`, in their order.
|
||||||
|
;; Settings with a "shared" and no "vaults" have that one.
|
||||||
|
(: (-> string (Vec string)))
|
||||||
|
(defun (read-vaults folder)
|
||||||
|
(match (read-fields folder)
|
||||||
|
((Some fields)
|
||||||
|
(match (json-object-ref (JsonFields fields) "vaults")
|
||||||
|
((Some (JsonArr items))
|
||||||
|
(vec-fold (fun (j acc)
|
||||||
|
(match j
|
||||||
|
((JsonStr path) (if (or (string-empty? (string-trim path)) (vec-contains? acc path))
|
||||||
|
acc
|
||||||
|
(vec-add acc path)))
|
||||||
|
(_ acc)))
|
||||||
|
[] (iarray->vec items)))
|
||||||
|
(_ (match (read-shared-folder folder)
|
||||||
|
((Some path) [path])
|
||||||
|
(None [])))))
|
||||||
|
(None [])))
|
||||||
|
|
||||||
|
;; Saves `vaults` in the settings in `folder`, and `last` as the one used
|
||||||
|
;; last, and keeps their other fields.
|
||||||
|
(: (-> string (Vec string) string void))
|
||||||
|
(defun (save-vaults! folder vaults last)
|
||||||
|
(save-fields! folder [(Tuple "shared" (JsonStr last))
|
||||||
|
(Tuple "vaults" (JsonArr (vec->iarray (vec-map (fun (p) (JsonStr p)) vaults))))]))
|
||||||
|
|
||||||
|
;; Saves `fields` in the settings in `folder`, in place of those of their
|
||||||
|
;; names, and keeps the others. Makes `folder` when it is not there. Raises
|
||||||
|
;; what the file system raises.
|
||||||
|
(: (-> string (Vec (Tuple string Json)) void))
|
||||||
|
(defun (save-fields! folder fields)
|
||||||
|
(def names (vec-map fst fields))
|
||||||
|
(def others (match (read-fields folder)
|
||||||
|
((Some old) (vec-filter (fun (f) (not (vec-contains? names (fst f)))) (iarray->vec old)))
|
||||||
|
(None [])))
|
||||||
|
(def text (json->string (JsonFields (vec->iarray (vec-append others fields)))))
|
||||||
|
(directory-create folder)
|
||||||
|
(def file (path-combine folder file-name))
|
||||||
|
(def partial (str file ".new"))
|
||||||
|
(file-write-text partial text)
|
||||||
|
(file-move partial file #:mode MoveReplace))
|
||||||
1227
tests/app.bjo
Normal file
1227
tests/app.bjo
Normal file
File diff suppressed because it is too large
Load diff
85
tests/screenshots.bjo
Normal file
85
tests/screenshots.bjo
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
;; bjomarks-gui/tests/screenshots.bjo — the pictures of the Readme.
|
||||||
|
;;
|
||||||
|
;; bjo run tests/screenshots.bjo docs/window.png
|
||||||
|
;; bjo run tests/screenshots.bjo docs/edit.png edit
|
||||||
|
;; bjo run tests/screenshots.bjo /tmp/fetching.png fetching
|
||||||
|
;; bjo run tests/screenshots.bjo docs/unlock.png lock
|
||||||
|
;; bjo run tests/screenshots.bjo /tmp/help.png help # /tmp/help-help.png: docs/help.png
|
||||||
|
;;
|
||||||
|
;; Makes a vault of examples in the temp directory, and shows the window
|
||||||
|
;; already open on it, with the second bookmark chosen, or with the dialog
|
||||||
|
;; that edits it. The window saves a PNG of itself and closes, as
|
||||||
|
;; BJOGUI_SCREENSHOT makes it do; the dialog is saved beside it. Needs a
|
||||||
|
;; display.
|
||||||
|
|
||||||
|
(import (std prelude))
|
||||||
|
(import (std os))
|
||||||
|
(import (std datetime))
|
||||||
|
(import (bjogui app))
|
||||||
|
(import (bjomarks bookmark))
|
||||||
|
(import (bjomarks keys))
|
||||||
|
(import (bjomarks store))
|
||||||
|
(import (bjomarks-gui app))
|
||||||
|
|
||||||
|
(import/class
|
||||||
|
(UnionTheme (: AvaUnion.UnionTheme (-> UnionTheme))))
|
||||||
|
|
||||||
|
;; The last has no title, as a bookmark has before its title is fetched.
|
||||||
|
(: examples (Vec (Tuple string string (Option string) (Vec string) (Option string))))
|
||||||
|
(def examples
|
||||||
|
[(Tuple "2026-11-11T09:12:00Z" "https://doc.rust-lang.org/book/" (Some "The Rust Programming Language")
|
||||||
|
["rust" "docs"] (Some "https://web.archive.org/web/20261111/https://doc.rust-lang.org/book/"))
|
||||||
|
(Tuple "2026-11-10T18:40:00Z" "https://www.gnu.org/software/emacs/manual/" (Some "GNU Emacs Manuals Online")
|
||||||
|
["emacs" "docs"] None)
|
||||||
|
(Tuple "2026-11-09T07:05:00Z" "https://avaloniaui.net/" (Some "Avalonia UI") ["gui" "dotnet"] None)
|
||||||
|
(Tuple "2026-11-02T21:30:00Z" "https://libsodium.org/" (Some "libsodium") ["crypto"]
|
||||||
|
(Some "https://web.archive.org/web/20261102/https://libsodium.org/"))
|
||||||
|
(Tuple "2026-10-28T12:00:00Z" "https://syncthing.net/" None ["sync"] None)])
|
||||||
|
|
||||||
|
(: (-> Vault (Tuple string string (Option string) (Vec string) (Option string)) Vault))
|
||||||
|
(defun (add-example v example)
|
||||||
|
(def (Tuple added url title tags archive) example)
|
||||||
|
(def at (match (iso8601->instant added) ((Some i) i) (None (now))))
|
||||||
|
(match (vault-add v url #:title title #:tags tags #:archive archive #:added at)
|
||||||
|
((Ok (Tuple v2 _)) v2)
|
||||||
|
((Err why) (panic! why))))
|
||||||
|
|
||||||
|
(: (-> (Vec string) int))
|
||||||
|
(defun (main args)
|
||||||
|
(def shot (if (> (vec-length args) 0) (vec-ref args 0) "window.png"))
|
||||||
|
;; "edit": the dialog. "fetching": the dialog, as its title is fetched.
|
||||||
|
(def mode (if (> (vec-length args) 1) (vec-ref args 1) ""))
|
||||||
|
(def root (make-temp-directory #:prefix "bjomarks-shots-"))
|
||||||
|
(def storage (folder-storage (path-combine root "shared")))
|
||||||
|
(def local (path-combine root "local"))
|
||||||
|
(def made (match (create-vault storage local "pw" #:cost (KeyCost (iterations 1) (memory-kib 8)))
|
||||||
|
((Ok v) v)
|
||||||
|
((Err _) (panic! "the vault was not made"))))
|
||||||
|
(def v (vault-save (vec-fold (fun (e v) (add-example v e)) made examples)))
|
||||||
|
(def fresh (initial-model storage local))
|
||||||
|
(def start (record-set fresh (phase Open) (vault (Some v)) (selected 1) (status "Saved.")))
|
||||||
|
(def editing (fst (gui-update (Edit (.id (vec-ref (visible-bookmarks start) 1))) start)))
|
||||||
|
;; No fetch runs: the dialog is only told that one does.
|
||||||
|
(def model (match (Tuple mode (.draft editing))
|
||||||
|
((Tuple "edit" _) editing)
|
||||||
|
((Tuple "fetching" (Some d)) (record-set editing (draft (Some (record-set d (fetching (Some 1)))))))
|
||||||
|
;; The first screen of a device with no vault, and an empty
|
||||||
|
;; shared folder: a new vault. With settings, so that the
|
||||||
|
;; folder can be changed.
|
||||||
|
((Tuple "lock" _) (initial-model (folder-storage (path-combine root "new")) (path-combine root "device")
|
||||||
|
#:settings (path-combine root "config")))
|
||||||
|
;; The help window, beside the main one.
|
||||||
|
((Tuple "help" _) (record-set start (help #t)))
|
||||||
|
(_ start)))
|
||||||
|
(run-app model gui-update view
|
||||||
|
#:windows windows #:keys keys
|
||||||
|
#:themes (fun () (list (cast IStyle (UnionTheme.))))
|
||||||
|
#:title "Bjomarks" #:width 640.0 #:height 420.0
|
||||||
|
#:screenshot shot)
|
||||||
|
(vault-close v)
|
||||||
|
(directory-delete-tree root)
|
||||||
|
0)
|
||||||
BIN
window.png
Normal file
BIN
window.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 89 KiB |
Loading…
Add table
Add a link
Reference in a new issue