bjomarks-android: the Android client of bjomarks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Linus Björnstam 2026-11-21 21:06:11 +01:00
commit bf114513a5
11 changed files with 2526 additions and 0 deletions

13
.gitignore vendored Normal file
View 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
View 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.

101
Readme.org Normal file
View file

@ -0,0 +1,101 @@
#+TITLE: bjomarks-android
Bookmarks on an Android phone. The bookmarks are a bjomarks vault in a
folder that a file syncer, such as Syncthing, shares with your other
devices. The folder holds only encrypted files.
* Running it
#+BEGIN_SRC sh
bjo run --android # build, install, start, and show the log
bjo publish --android # the APK
bjo run src/main.bjo # on the desktop, in a window
bjo run tests/app.bjo # the tests, with no window
#+END_SRC
~bjo run --android~ needs ~ANDROID_HOME~ and ~JAVA_HOME~. See "Android" in
Bjolang's ~Docs/Projects.org~.
The app id is ~org.bjoli.bjomarks~, the same as the Android build of
bjomarks-gui. The two replace each other on a device.
* Using it
1. At the first start, tap "Choose folder…" and choose the shared folder in
the system's picker. Then allow the app to use it. The app keeps the
access and opens the folder again at each start.
2. Type the password:
- When the folder has no vault, the app makes one. Type the password two
times.
- When the folder has the vault of your other devices, this device joins
it with their password.
- After that, the password opens the vault of this device.
3. The list shows the bookmarks, the newest first.
- Tap a bookmark for its menu: Open, Open in private window, Copy
address, Share, Edit, Remove.
- Open in private window opens the page in Firefox's private browsing,
or in Firefox Focus. Chrome does not let other apps open an incognito
tab: then the address is copied, to paste in one.
- Back clears the search, when one is typed; then it leaves the app.
- "Undo" brings back the bookmarks that were removed, the last first.
4. Several vaults: each shared folder is a vault of its own, named by its
folder. The password screen has a list of the folders added, with "Add
new…" at its end; the app opens the one used last at each start.
"Remove from list" takes the one chosen off the list, and deletes
nothing: adding its folder again opens it again. "Other bookmarks…",
under "More", saves the open vault and goes back to the password screen.
- Type in "Search" to find bookmarks. A word is looked for in the title,
the address and the tags, and may have a typo. ~t:rust~ is the tag
"rust", ~d:github.com~ the domain, ~a:2011:2012-06~ the days added,
~"two words"~ exact text, and ~-~ before any of them excludes it. See
(bjomarks search).
- "New" adds a bookmark. "Fetch" beside the title gets the title of the
page. "Fetch" beside the archive link gets the latest copy of the page
in the Wayback Machine, if it has one.
- "More" has "Import a Firefox backup…", "Help", and the name of the
shared folder.
4. In a browser, share a page to "Bjomarks". The dialog of a new bookmark
opens with the address and the title of the page. When the vault is
locked, the dialog opens after the password. When a bookmark has that
address, the dialog of that bookmark opens.
To import the bookmarks of Firefox, make a backup on a computer: in
Firefox's Library (Ctrl+Shift+O), choose Import and Backup, then Backup.
Put the JSON file on the phone, then choose it under "More". Each folder of
the backup becomes a tag. A bookmark whose address is here already is not
changed.
A change is written to the folder at once, in the background. The app also
reads the changes of your other devices each minute, when it goes to the
background, and when it comes back.
* Files
- The shared folder: ~keys.bin~, and a file for each device in ~devices/~.
See bjomarks.
- This device's own files: a folder for each shared folder, in
~bjomarks/vaults~ in the app's folder for data, so that two shared folders
are two vaults (see ~device-folder~ in bjomarks). The phone keeps the
password of each behind its unlock on its own.
- The settings: ~bjomarks/settings.json~ in the app's folder for
configuration. It holds the folders added, each with its name and
bookmark, and the one used last.
* Modules
- ~src/main.bjo~: the program.
- ~src/app.bjo~, (bjomarks-android app): the model, the update and the
views.
- ~src/settings.bjo~, (bjomarks-android settings): the settings file.
The shared folder has no path on Android. The app gives bjomarks a storage
of functions (~function-storage~ in (bjomarks store)) that reads and writes
the folder through (bjogui storage).
* Not yet
- A way to start again on a device: forget this device's vault, and join
the vault in the shared folder. Now, a device whose own files are of
another vault asks for that vault's password. Clear the app's data to
start again.
- An icon, signing, and an AAB for a store.

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

50
icon.svg Normal file
View file

@ -0,0 +1,50 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<title>bjomarks bear</title>
<defs>
<clipPath id="tile"><rect width="512" height="512"/></clipPath>
</defs>
<g clip-path="url(#tile)">
<rect width="512" height="512" fill="#2f5d50"/>
<rect y="398" width="512" height="114" fill="#264c42"/>
<!-- far legs -->
<g fill="#432a17">
<path d="M214 290 L262 290 L264 384 C264 394 258 400 248 400 L220 400 C210 400 206 394 208 384 Z"/>
<path d="M380 300 L444 300 L444 384 C444 394 438 400 428 400 L390 400 C380 400 376 394 378 384 Z"/>
</g>
<g fill="#5a3a22">
<!-- torso: slim front, big round rump -->
<path d="
M 360 150
C 424 150 468 196 468 252
C 468 308 426 348 370 348
C 310 348 262 318 210 312
C 180 309 158 300 150 284
C 138 258 142 222 158 200
C 174 178 202 168 236 166
C 282 163 316 150 360 150 Z"/>
<!-- head with tapered muzzle -->
<path d="
M 196 200
C 192 172 164 160 138 166
C 112 172 98 192 86 210
C 74 226 56 232 50 244
C 46 256 56 266 72 268
C 94 272 112 278 132 284
C 168 294 200 266 204 240 Z"/>
<!-- ear -->
<circle cx="160" cy="166" r="20"/>
<!-- near legs -->
<path d="M152 280 L204 280 L206 384 C206 394 200 400 190 400 L164 400 C154 400 150 394 152 384 Z"/>
<path d="M326 300 L396 300 L398 384 C398 394 392 400 382 400 L340 400 C330 400 326 394 328 384 Z"/>
</g>
<!-- inner ear -->
<circle cx="160" cy="167" r="9" fill="#432a17"/>
<!-- eye -->
<circle cx="124" cy="206" r="6.5" fill="#1d120a"/>
<!-- nose -->
<ellipse cx="54" cy="243" rx="11" ry="9" fill="#1d120a"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

20
manifest.bjodat Normal file
View file

@ -0,0 +1,20 @@
(package
(name (bjomarks-android))
(version "0.1.0")
(description "Bookmarks on an Android phone: a bjomarks vault in a folder that a file syncer shares, and the Share menu.")
(license "MPL-2.0")
;; The Android app: bjo run --android, bjo publish --android.
(android-id "org.bjoli.bjomarks")
(android-label "Bjomarks")
(android-aot #t)
;; Fetching titles.
(android-permissions "INTERNET")
;; "Bjomarks" in the Share menu of a browser.
(android-share-target #t)
;; The bear. icon.svg is its source.
(android-icon "icon.png")
(depends
(package (name (bjomarks)) (source (path (dir "../bjomarks"))))
(package (name (bjogui)) (source (path (dir "../bjogui"))))))

239
packages.lock.json Normal file
View file

@ -0,0 +1,239 @@
{
"version": 1,
"dependencies": {
"net11.0": {
"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"
}
},
"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)"
}
}
}
}
}

1166
src/app.bjo Normal file

File diff suppressed because it is too large Load diff

30
src/main.bjo Normal file
View file

@ -0,0 +1,30 @@
;; 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-android) — bookmarks on an Android phone.
;;
;; bjo run --android
;;
;; - The shared folder is chosen with the system's folder picker, and opened
;; again at each start: see (bjomarks-android settings).
;; - This device's own folder is "bjomarks" in the app's folder for data.
;; - See (bjomarks-android app) for the screens.
;;
;; It runs on the desktop too, in a window, for trying it out: the picker is
;; then the desktop's.
(import (std prelude))
(import (std os))
(import (bjogui app))
(import (bjomarks-android app))
(import (bjomarks-android settings))
(: (-> (Vec string) int))
(defun (main args)
(def settings (settings-folder))
(def local (path-combine (data-directory) "bjomarks"))
(run-app (initial-model local settings (read-folder-mark settings) #:vaults (read-vaults settings)) gui-update view
#:windows windows #:subscriptions subscriptions #:on-back back-message
#:title "Bjomarks" #:width 420.0 #:height 760.0)
0)

120
src/settings.bjo Normal file
View file

@ -0,0 +1,120 @@
;; 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-android/src/settings.bjo — the module (bjomarks-android
;; settings): what the app keeps between runs, in settings.json in a folder
;; of its own.
;;
;; {"folder": "<bookmark of the shared folder>",
;; "vaults": [{"name": "Bookmarks", "folder": "<bookmark>"}, ...]}
;;
;; - The folder is "bjomarks" in the app's folder for configuration.
;; - "folder" is the bookmark of the shared folder used last, from bjogui's
;; `folder-bookmark`. It opens the folder again, and on Android it keeps
;; the app's access to it.
;; - "vaults" is the shared folders that the user added, each with the name
;; of its folder, in the order they were added. Settings of an earlier
;; version, with "folder" 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-folder-mark save-folder-mark!
VaultEntry vault-entry-name vault-entry-mark 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 app'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 bookmark of 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-folder-mark folder)
(match (read-fields folder)
((Some fields)
(match (json-object-ref (JsonFields fields) "folder")
((Some (JsonStr s)) (if (string-empty? (string-trim s)) None (Some s)))
(_ None)))
(None None)))
;; Saves `mark` as the bookmark of 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-folder-mark! folder mark)
(save-fields! folder [(Tuple "folder" (JsonStr mark))]))
;; A shared folder that the user added: the name to show, and its bookmark.
(type (: VaultEntry (Record (: name string) (: mark string))))
(: (-> VaultEntry string))
(defun (vault-entry-name e) (.name e))
(: (-> VaultEntry string))
(defun (vault-entry-mark e) (.mark e))
;; The shared folders saved in the settings in `folder`, in their order.
;; Settings with a "folder" and no "vaults" have that one, with no name yet.
(: (-> string (Vec VaultEntry)))
(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 (Tuple (json-object-ref j "name") (json-object-ref j "folder"))
((Tuple (Some (JsonStr name)) (Some (JsonStr mark)))
(if (string-empty? mark) acc (vec-add acc (VaultEntry (name name) (mark mark)))))
(_ acc)))
[] (iarray->vec items)))
(_ (match (read-folder-mark folder)
((Some mark) [(VaultEntry (name "") (mark mark))])
(None [])))))
(None [])))
;; Saves `vaults` in the settings in `folder`, and `last` as the one used
;; last, or none, and keeps their other fields.
(: (-> string (Vec VaultEntry) (Option string) void))
(defun (save-vaults! folder vaults last)
(def items (vec-map (fun (e) (JsonFields (vec->iarray [(Tuple "name" (JsonStr (.name e)))
(Tuple "folder" (JsonStr (.mark e)))])))
vaults))
(def list-field (Tuple "vaults" (JsonArr (vec->iarray items))))
;; "" is no folder: `read-folder-mark` reads it as none.
(save-fields! folder [(Tuple "folder" (JsonStr (option-ref-or last ""))) list-field]))
;; 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))

414
tests/app.bjo Normal file
View file

@ -0,0 +1,414 @@
;; 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-android/tests/app.bjo — the phone app without a phone.
;;
;; bjo run tests/app.bjo
;;
;; - The shared folder is a storage of functions over a map in memory.
;; - The test is the host: it posts shared texts, as the Android app's C#
;; does, and keeps the password as the phone's unlock does. No window is
;; opened.
(import (std prelude))
(import (std simpletest))
(import (std os))
(import (std uuid))
(import (bjogui view))
(import (except (bjogui app) Live))
(import (bjogui platform))
(import (bjomarks bookmark))
(import (bjomarks store))
(import (bjomarks import))
(import (bjomarks draft))
(import (bjomarks duplicates))
(import (bjomarks-android app))
(import (bjomarks-android settings))
(import/class
(ClrString (: System.String)))
(import/extern
(host-post (: Bjolang.Runtime.Host.Post (-> string string void)))
(host-offer (: Bjolang.Runtime.Host.SetHandler (-> string (-> ClrString bool) void)))
(sleep-ms (: System.Threading.Thread.Sleep (-> int void) #:blocking)))
(: (-> (Box (Map string (Array byte))) Storage))
(defun (memory-storage files)
(: (-> string (Option (Array byte))))
(defun (read name) (map-try-ref (box-ref files) name))
(: (-> string (Array byte) void))
(defun (write name bytes) (box-set! files (map-set (box-ref files) name bytes)))
(: (-> string (Vec string)))
(defun (list-names dir)
(def prefix (str dir "/"))
(vec-map (fun (k) (string-drop k (string-count prefix)))
(vec-filter (fun (k) (string-starts-with? k prefix)) (->vec (map-keys (box-ref files))))))
(function-storage "memory" read write list-names))
;; The phone's unlock, as the test plays it: what it keeps, its name, a
;; newline and the secret.
(: (Box string))
(def phone-kept (make-box ""))
(: phone-can (-> ClrString bool) #:sync)
(defun (phone-can s) #t)
(: phone-has (-> ClrString bool) #:sync)
(defun (phone-has name) (not (string-empty? (box-ref phone-kept))))
(: phone-keep (-> ClrString bool) #:sync)
(defun (phone-keep s) (box-set! phone-kept (.ToString s)) #t)
(: phone-forget (-> ClrString bool) #:sync)
(defun (phone-forget name) (box-set! phone-kept "") #t)
(: (-> Model (Vec string)))
(defun (urls m)
(match (.vault m)
((Some v) (vec-sort (vec-map (fun (b) (.url b)) (vault-bookmarks v))))
(None [])))
(: (-> Model (Option Draft)))
(defun (draft-in m) (.draft m))
;; A Firefox backup with two bookmarks in a folder "Reading", and one that
;; the vault has already.
(: string)
(def backup-json
"""
{"guid":"root________","title":"","index":0,"dateAdded":1500000000000000,"lastModified":1500000000000000,
"id":1,"typeCode":2,"type":"text/x-moz-place-container","root":"placesRoot","children":[
{"guid":"menu________","title":"menu","index":0,"dateAdded":1500000000000000,"lastModified":1500000000000000,
"id":2,"typeCode":2,"type":"text/x-moz-place-container","root":"bookmarksMenuFolder","children":[
{"guid":"folderA00001","title":"Reading","index":0,"dateAdded":1700000000000000,"lastModified":1700000000000000,
"id":7,"typeCode":2,"type":"text/x-moz-place-container","children":[
{"guid":"bookmark0001","title":"The Book","index":0,"dateAdded":1700000100000000,"lastModified":1700000100000000,
"id":8,"typeCode":1,"type":"text/x-moz-place","uri":"https://doc.rust-lang.org/book/"},
{"guid":"bookmark0002","title":"Old","index":1,"dateAdded":1700000100000000,"lastModified":1700000100000000,
"id":9,"typeCode":1,"type":"text/x-moz-place","uri":"https://example.org/b"}]}]}]}
""")
(defun (main)
;; shared-url, without an app.
(expect "an address after words" (shared-url "A page\nhttps://example.org/a b") (Some "https://example.org/a"))
(expect "http too" (shared-url "see http://example.org") (Some "http://example.org"))
(expect "no address" (shared-url "just words") None)
(def root (make-temp-directory #:prefix "bjomarks-android-test-"))
(def files (make-box (: (map-empty) (Map string (Array byte)))))
(def storage (memory-storage files))
;; Shared before the vault is open: it waits for it.
(start-headless!)
(host-post "share-text" "A page\nhttps://example.org/a")
(def app (start-app (initial-model (path-combine root "one") (path-combine root "settings") None
#:storage (Some storage) #:start CreateNew
;; No server listens there: a lookup fails at once.
#:wayback "http://127.0.0.1:9/wayback")
gui-update view (fun (c) unit)
#:windows windows #:subscriptions subscriptions))
;; Runs what the fibers posted until `done?` holds, for 30 seconds at most:
;; Argon2id is slow.
(: (-> (-> Model bool) bool))
(defun (wait-for done?)
(let go ((tries 0))
(app-run-pending! app)
(cond ((done? (app-model app)) #t)
((> tries 3000) #f)
(else (sleep-ms 10) (go (+ tries 1))))))
(defun (send msg)
(app-dispatch! app msg)
(app-run-pending! app))
(expect "the share waits"
(wait-for (fun (m) (some? (.shared m)))) #t)
(expect "a storage given is locked at once" (= (.phase (app-model app)) Locked) #t)
(expect "the label of the storage" (.folder-label (app-model app)) "memory")
;; The phone can keep the password, and the user chooses it.
(host-offer "device-secret-available" phone-can)
(host-offer "device-secret-stored" phone-has)
(host-offer "device-secret-keep" phone-keep)
(host-offer "device-secret-unlock" phone-has)
(host-offer "device-secret-forget" phone-forget)
(send (DeviceChecked (Ok (Tuple #t #f))))
(expect "the phone can keep it" (Tuple (.device (app-model app)) (.kept (app-model app))) (Tuple #t #f))
(send (KeepWithDevice #t))
(send Unlock)
(expect "no password" (.problem (app-model app)) "Type the password.")
(send (Password "hunter2"))
(send (Again "hunter3"))
(send Unlock)
(expect "two passwords" (.problem (app-model app)) "The two passwords are not the same.")
(send (Again "hunter2"))
(send Unlock)
(expect "unlocking" (= (.phase (app-model app)) Unlocking) #t)
(expect "the vault is made" (wait-for (fun (m) (= (.phase m) Open))) #t)
(expect "keys.bin is in the folder" (some? (map-try-ref (box-ref files) "keys.bin")) #t)
(expect "the phone keeps the password" (wait-for (fun (m) (.kept m))) #t)
(expect "under its name" (box-ref phone-kept) (str password-secret "\nhunter2"))
;; The share that waited is the dialog of a new bookmark.
(match (draft-in (app-model app))
((Some d)
(expect "the shared address" (.url d) "https://example.org/a")
(expect "the subject is the title" (.title d) "A page")
(expect "a new bookmark" (none? (.editing d)) #t))
(None (expect "a dialog after the share" #f #t)))
(expect "the share is used" (none? (.shared (app-model app))) #t)
(send (DraftTags "web, test"))
(send SaveDraft)
(expect "saved" (urls (app-model app)) ["https://example.org/a"])
(expect "what Share sends"
(share-text-of (vec-ref (visible-bookmarks (app-model app)) 0))
"A page\nhttps://example.org/a\nTags: test web")
(expect "the dialog is closed" (none? (draft-in (app-model app))) #t)
(expect "the sync ends" (wait-for (fun (m) (not (.saving m)))) #t)
(expect "no sync failed" (.failed (app-model app)) #f)
(expect "the device's file is in the folder"
(vec-length (vec-filter (fun (k) (string-starts-with? k "devices/")) (->vec (map-keys (box-ref files))))) 1)
;; The same address again: the dialog of its bookmark.
(host-post "share-text" "Again\nhttps://example.org/a")
(expect "a share while open"
(wait-for (fun (m) (some? (draft-in m)))) #t)
(match (draft-in (app-model app))
((Some d)
(expect "the bookmark there" (some? (.editing d)) #t)
(expect "with a problem" (string-empty? (.problem d)) #f)
(expect "its tags, sorted" (.tags d) "test web"))
(None unit))
(send CancelDraft)
;; A new bookmark that is not an address, and one with an address that a
;; bookmark has: it loads that bookmark, and another address brings back
;; what was typed.
(send New)
(send (DraftUrl "not an address"))
(send SaveDraft)
(expect "not an address"
(match (draft-in (app-model app)) ((Some d) (string-empty? (.problem d))) (None #t)) #f)
(send (DraftTitle "Bee"))
(send (DraftUrl "https://example.org/a"))
(expect "an address there already loads its bookmark"
(match (draft-in (app-model app)) ((Some d) (Tuple (.problem d) (.title d))) (None (Tuple "" "")))
(Tuple address-here "A page"))
(send (DraftUrl "https://example.org/b"))
(expect "another address brings back what was typed"
(match (draft-in (app-model app)) ((Some d) (Tuple (none? (.editing d)) (.title d))) (None (Tuple #f "")))
(Tuple #t "Bee"))
;; The archive link: a lookup that fails says so; a link typed is kept.
(send DraftFetchArchive)
(expect "an archive lookup that fails"
(wait-for (fun (m) (match (draft-in m)
((Some d) (string-starts-with? (.problem d) "No archive"))
(None #f))))
#t)
(send (DraftArchive "https://web.archive.org/web/2026/https://example.org/b"))
(send SaveDraft)
(expect "two bookmarks" (urls (app-model app)) ["https://example.org/a" "https://example.org/b"])
(expect "with the archive link"
(vec-map (fun (b) (.archive b))
(vec-filter (fun (b) (= (.url b) "https://example.org/b"))
(match (.vault (app-model app)) ((Some v) (vault-bookmarks v)) (None []))))
[(Some "https://web.archive.org/web/2026/https://example.org/b")])
;; Searching.
(send (Search "tag:web"))
(expect "a search by tag" (vec-map (fun (b) (.url b)) (visible-bookmarks (app-model app)))
["https://example.org/a"])
(send (Search "bee"))
(expect "a search by title" (vec-map (fun (b) (.url b)) (visible-bookmarks (app-model app)))
["https://example.org/b"])
;; Back clears the search, and with none it is not taken.
(expect "Back with a search" (some? (back-message (app-model app))) #t)
(send (match (back-message (app-model app)) ((Some msg) msg) (None (Search "not taken"))))
(expect "clears it" (.query (app-model app)) "")
(expect "and shows all" (vec-length (visible-bookmarks (app-model app))) 2)
(expect "Back without a search is not taken" (none? (back-message (app-model app))) #t)
;; Copy address: the note says what was copied.
(send (CopyAddress (.id (vec-ref (visible-bookmarks (app-model app)) 0))))
(expect "Copy address" (string-starts-with? (.note (app-model app)) "Copied https://example.org/") #t)
;; Open in private window, with no host that can: the address is copied.
(def first-id (.id (vec-ref (visible-bookmarks (app-model app)) 0)))
(send (OpenPrivately first-id))
(expect "no private window without a host"
(wait-for (fun (m) (string-contains? (.note m) "The address is copied"))) #t)
(send (OpenBookmark first-id))
(expect "Open asks the system" (string-starts-with? (.note (app-model app)) "Opening https://example.org/") #t)
(expect "and without a window, it cannot"
(wait-for (fun (m) (string-starts-with? (.note m) "Could not open"))) #t)
;; Edit, remove and undo.
(def a-id (.id (vec-ref (vec-filter (fun (b) (= (.url b) "https://example.org/a"))
(visible-bookmarks (app-model app))) 0)))
(send (Edit a-id))
(send (DraftTitle "Ay"))
(send (DraftTags "x"))
(send SaveDraft)
(def edited (vec-filter (fun (b) (= (.id b) a-id)) (visible-bookmarks (app-model app))))
(expect "the title edited" (.title (vec-ref edited 0)) (Some "Ay"))
(expect "the tags edited" (.tags (vec-ref edited 0)) ["x"])
(send (Remove a-id))
(expect "removed" (urls (app-model app)) ["https://example.org/b"])
(expect "the note" (.note (app-model app)) "Removed Ay.")
(send Undo)
(expect "brought back" (urls (app-model app)) ["https://example.org/a" "https://example.org/b"])
(expect "nothing more to undo" (empty? (.removed (app-model app))) #t)
(expect "the syncs end" (wait-for (fun (m) (not (.saving m)))) #t)
;; More, Help, and an import: the file's text is read as the picker's
;; file would be.
(send ShowMore)
(expect "the More layer" (app-windows app) (list "more"))
(send ShowHelp)
(expect "Help closes More" (Tuple (.more (app-model app)) (.help (app-model app))) (Tuple #f #t))
(send HideHelp)
(expect "no layers" (app-windows app) (list))
(send (BackupRead "bookmarks.json" (Ok (read-firefox-backup backup-json))))
(expect "imported" (urls (app-model app))
["https://doc.rust-lang.org/book/" "https://example.org/a" "https://example.org/b"])
(expect "the note of the import" (.note (app-model app))
"Imported 1 bookmark from bookmarks.json. 1 was here already.")
(send (BackupRead "bad.json" (Ok (read-firefox-backup "not json"))))
(expect "a file that is not a backup"
(string-starts-with? (.note (app-model app)) "Could not import bad.json") #t)
(expect "the syncs end again" (wait-for (fun (m) (not (.saving m)))) #t)
;; "Other bookmarks…": saved, closed, and back to the password screen.
(send ShowMore)
(send SwitchVault)
(expect "back to the password screen"
(wait-for (fun (m) (and (= (.phase m) Locked) (none? (.vault m))))) #t)
(expect "with nothing of the vault"
(Tuple (.query (app-model app)) (list-length (.removed (app-model app))) (.start (app-model app)))
(Tuple "" 0 OpenExisting))
(app-stop! app)
;; This device again: the phone gives the password after its unlock.
(def again (start-app (initial-model (path-combine root "one") (path-combine root "settings") None
#:storage (Some storage) #:start OpenExisting)
gui-update view (fun (c) unit)
#:windows windows #:subscriptions subscriptions))
(app-dispatch! again (DeviceChecked (Ok (Tuple #t #t))))
(app-run-pending! again)
(expect "the phone asks at once" (.asking (app-model again)) #t)
(host-post "device-secret" "cancelled\n")
(let go ((tries 0))
(app-run-pending! again)
(when (and (.asking (app-model again)) (< tries 300)) (sleep-ms 10) (go (+ tries 1))))
(expect "cancelled: the password screen" (Tuple (.asking (app-model again)) (= (.phase (app-model again)) Locked))
(Tuple #f #t))
(app-dispatch! again AskDevice)
(host-post "device-secret" "ok\nhunter2")
(let go ((tries 0))
(app-run-pending! again)
(unless (or (= (.phase (app-model again)) Open) (> tries 3000)) (sleep-ms 10) (go (+ tries 1))))
(expect "the phone's password opens it" (= (.phase (app-model again)) Open) #t)
(app-stop! again)
;; A kept password that is wrong is forgotten.
(def wrong (start-app (initial-model (path-combine root "one") (path-combine root "settings") None
#:storage (Some storage) #:start OpenExisting)
gui-update view (fun (c) unit)
#:windows windows #:subscriptions subscriptions))
(app-dispatch! wrong (DeviceChecked (Ok (Tuple #t #t))))
(host-post "device-secret" "ok\nhunter3")
(let go ((tries 0))
(app-run-pending! wrong)
(unless (or (string-empty? (box-ref phone-kept)) (> tries 3000)) (sleep-ms 10) (go (+ tries 1))))
(expect "a wrong kept password is forgotten"
(Tuple (box-ref phone-kept) (.kept (app-model wrong)) (= (.phase (app-model wrong)) Locked))
(Tuple "" #f #t))
(app-stop! wrong)
;; Another device joins through the same folder, and sees both.
(def two (start-app (initial-model (path-combine root "two") (path-combine root "settings") None
#:storage (Some storage) #:start JoinShared)
gui-update view (fun (c) unit)
#:windows windows #:subscriptions subscriptions))
(app-dispatch! two (Password "hunter2"))
(app-dispatch! two Unlock)
(let go ((tries 0))
(app-run-pending! two)
(unless (or (= (.phase (app-model two)) Open) (> tries 3000))
(sleep-ms 10)
(go (+ tries 1))))
(expect "the other device opens" (= (.phase (app-model two)) Open) #t)
(expect "and has all" (urls (app-model two))
["https://doc.rust-lang.org/book/" "https://example.org/a" "https://example.org/b"])
;; A third device, not yet synced, bookmarked example.org/a with a title
;; of its own: after a sync, the app asks which title to keep.
(def three (match (join-vault storage (path-combine root "three") "hunter2")
((Ok (Tuple v _)) v)
((Err _) (panic! "the third device did not join"))))
(def three2 (match (vault-add three "https://example.org/a" #:title (Some "Another title") #:tags ["other"])
((Ok (Tuple v _)) v)
((Err why) (panic! why))))
(ignore (vault-sync three2))
(defun (sync-two)
(app-dispatch! two SyncTick)
(let go ((tries 0))
(app-run-pending! two)
(when (and (.saving (app-model two)) (< tries 3000)) (sleep-ms 10) (go (+ tries 1)))))
(sync-two)
(def asked (.duplicates (app-model two)))
(expect "a page bookmarked twice" (vec-length asked) 1)
(expect "its titles" (vec-length (duplicate-titles (vec-ref asked 0))) 2)
(expect "the question shows" (list-length (windows (app-model two))) 1)
(app-dispatch! two (ChooseTitle "https://example.org/a" "Another title"))
(sync-two)
(def kept (vec-filter (fun (b) (= (.url b) "https://example.org/a"))
(vault-bookmarks (option-ref-or (.vault (app-model two)) three2))))
(expect "one bookmark of it" (vec-length kept) 1)
(expect "with the title chosen" (.title (vec-ref kept 0)) (Some "Another title"))
(expect "and the tags of both" (vec-contains? (.tags (vec-ref kept 0)) "other") #t)
(expect "no question" (Tuple (vec-length (.duplicates (app-model two))) (list-length (windows (app-model two))))
(Tuple 0 0))
(app-stop! two)
;; The settings keep the folder's bookmark, and other fields.
(def settings (path-combine root "settings"))
(expect "no settings yet" (read-folder-mark settings) None)
(save-folder-mark! settings "mark-1")
(save-folder-mark! settings "mark-2")
(expect "the last mark" (read-folder-mark settings) (Some "mark-2"))
;; The list of folders. Settings of an earlier version have their one
;; folder, with no name yet.
(expect "the folder of an earlier version" (vec-map vault-entry-mark (read-vaults settings)) ["mark-2"])
(def home (VaultEntry (name "Home") (mark "mark-a")))
(def work (VaultEntry (name "Work") (mark "mark-b")))
(save-vaults! settings [home work] (Some "mark-b"))
(expect "the list is kept" (vec-map vault-entry-name (read-vaults settings)) ["Home" "Work"])
(expect "and the one used last" (read-folder-mark settings) (Some "mark-b"))
(save-vaults! settings [home] None)
(expect "none used last" (read-folder-mark settings) None)
(expect "a shorter list" (vec-map vault-entry-name (read-vaults settings)) ["Home"])
;; Choosing among them.
(def listed (initial-model (path-combine root "four") settings (Some "mark-a") #:vaults [home work]))
(expect "the one used last opens at the start" (Tuple (.phase listed) (.current listed))
(Tuple Checking (Some "mark-a")))
(def locked (record-set listed (phase Locked)))
(def (Tuple chose _) (gui-update (ChooseVault 1) locked))
(expect "another one is opened" (Tuple (.phase chose) (.mark chose) (.current chose))
(Tuple Checking (Some "mark-b") (Some "mark-b")))
(def (Tuple same _) (gui-update (ChooseVault 0) locked))
(expect "the one in use again changes nothing" (.phase same) Locked)
(def (Tuple adding _) (gui-update (ChooseVault 2) locked))
(expect "Add new asks for a folder, and keeps the one in use"
(Tuple (.phase adding) (.current adding)) (Tuple Locked (Some "mark-a")))
(def (Tuple forgot _) (gui-update ForgetVault locked))
(expect "Remove from list" (Tuple (vec-map vault-entry-name (.vaults forgot)) (.current forgot) (.phase forgot))
(Tuple ["Work"] None NoFolder))
(directory-delete-tree root)
(println "bjomarks-android app ok"))