Initial import of LogDarioSeq baseline
Establishes version control for the personal Logseq DB fork before starting the server-client architecture migration and domain features described in docs/agent-guide and the approved implementation plan. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
50
.gitignore
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
# Dependencies
|
||||
node_modules/
|
||||
.pnpm-store/
|
||||
|
||||
# Clojure/ClojureScript build
|
||||
.cpcache/
|
||||
.clj-kondo/.cache/
|
||||
.shadow-cljs/
|
||||
target/
|
||||
out/
|
||||
.nrepl-port
|
||||
.lsp/.cache/
|
||||
|
||||
# Build output
|
||||
static/js/
|
||||
static/out/
|
||||
static/mobile/js/
|
||||
static/db-worker-node.js
|
||||
static/db-worker-node-assets.json
|
||||
static/electron.js
|
||||
dist/
|
||||
cli/_build/
|
||||
cli/**/*.install
|
||||
resources/.cache/
|
||||
|
||||
# OCaml/Dune
|
||||
cli/_opam/
|
||||
|
||||
# Env / secrets
|
||||
.env
|
||||
.env.*
|
||||
*.pem
|
||||
*.key
|
||||
|
||||
# OS / editor
|
||||
.DS_Store
|
||||
*.log
|
||||
.vscode/
|
||||
.idea/
|
||||
|
||||
# Python sidecar
|
||||
sidecar/.venv/
|
||||
sidecar/__pycache__/
|
||||
**/__pycache__/
|
||||
|
||||
# Mobile build artifacts
|
||||
android/app/build/
|
||||
android/.gradle/
|
||||
ios/App/Pods/
|
||||
ios/App/build/
|
||||
56
AGENTS.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Repository Guidelines
|
||||
|
||||
## Build, Test, and Development Commands
|
||||
- `bb dev:lint-and-test` runs linters and unit tests.
|
||||
- `bb dev:test -v <namespace/testcase-name>` runs a single unit test (example: `bb dev:test -v logseq.some-test/foo`).
|
||||
- App E2E tests live in `clj-e2e/`; run from that directory with `bb test` (or `bb -f clj-e2e/bb.edn test` from repo root).
|
||||
- CLI E2E tests live in `cli-e2e/`; run with `bb -f cli-e2e/bb.edn test --skip-build` (or `bb -f cli-e2e/bb.edn build` first when needed).
|
||||
- If a request says only “e2e”, clarify whether it targets `clj-e2e/` or `cli-e2e/` before planning changes.
|
||||
|
||||
## Error handling and compatibility
|
||||
- When modifying code, first consider removing compatibility layers rather than extending them.
|
||||
- Prefer fail-fast over fallback.
|
||||
- Do not add backward compatibility unless explicitly requested.
|
||||
- Do not introduce default values to mask invalid state.
|
||||
- Do not silently recover from programmer errors.
|
||||
- Keep one clear code path whenever possible.
|
||||
- Internal code may assume well-formed inputs from controlled callers.
|
||||
|
||||
## Coding Style & Naming Conventions
|
||||
- ClojureScript keywords are defined via `logseq.common.defkeywords/defkeyword`; use existing keywords and add new ones in the shared definitions.
|
||||
- Follow existing namespace and file layout; keep related workers and RTC code in their dedicated directories.
|
||||
- Prefer concise, imperative commit subjects aligned with existing history (examples: `fix: download`, `enhance(rtc): ...`).
|
||||
- Clojure map keyword name should prefer `-` instead of `_`, e.g. `:user-id` instead of `:user_id`.
|
||||
- For i18n work, use `.i18n-lint.toml` as the source of truth for lint scope and exceptions. Inside that scope, shipped UI text must use helpers from `frontend.context.i18n`; console text is exempt. Keep out-of-scope developer-only `(Dev)` labels inline in code/config, not in translation dictionaries.
|
||||
- Reuse `src/resources/dicts/en.edn` keys only on exact semantic owner + textual role match. Follow `docs/i18n-key-naming.md` for new or renamed keys. Add English source text in `en.edn`; add non-English entries only when providing real translations; keep complete sentences whole; use placeholders for plain dynamic text; run `bb lang:validate-translations`, `bb lang:lint-hardcoded`, and `bb lang:format-dicts` as needed.
|
||||
|
||||
## Testing Guidelines
|
||||
- Unit tests live in `src/test/` and should be runnable via `bb dev:lint-and-test`.
|
||||
- Name tests after their namespaces; use `-v` to target a specific test case.
|
||||
- For CLJS tests, avoid recompiling when source files have not changed since the last successful `cljs:test`; run against the existing compiled test artifact instead.
|
||||
- Run lint/tests before submitting PRs; keep changes green.
|
||||
|
||||
## *IMPORTANT*: Always respect directory-specific AGENTS.md based on file path
|
||||
- when editing code in a specific directory, you must recursively read `AGENTS.md` files up the directory tree, and `AGENTS.md` in subdirectories takes precedence over the root-level one
|
||||
|
||||
## Commit & Pull Request Guidelines
|
||||
- Commit subjects are short and imperative; optional scope prefixes appear (e.g., `fix:` or `enhance(rtc):`).
|
||||
- PRs should describe the behavior change, link relevant issues, and note any test coverage added or skipped.
|
||||
- Never include the word "Codex" or any agent name in commit subjects, commit bodies, trailers, branch names, PR titles, or PR descriptions.
|
||||
- PR titles must describe the code change only.
|
||||
- Before creating or updating commits or PRs, verify that the generated metadata does not contain "Codex" or any agent name in any casing.
|
||||
|
||||
## Agent-Specific Notes
|
||||
- Use repo-local skills discovered under `.agents/skills/`; load the matching `SKILL.md` before editing files or proposing changes.
|
||||
- **i18n (mandatory)**: Always load `.agents/skills/logseq-i18n/SKILL.md` before any change that adds, edits, or removes user-facing UI text, regardless of whether other skills also apply.
|
||||
- Review notes live in `prompts/review.md`; check them when preparing changes.
|
||||
- Runtime, sync, CLI, rendering, search, and Graph View engineering guidance is consolidated in `docs/agent-guide/implemented/architecture/2026-08-24-logseq-runtime-and-engineering-guide.md`; current source and tests remain authoritative.
|
||||
- For db-sync D1 schema changes, add or update a Cloudflare worker SQL migration under `deps/db-sync/worker/migrations/`; do not rely on ad hoc runtime-only schema migration code.
|
||||
- New properties should be added to `logseq.db.frontend.property/built-in-properties`.
|
||||
- Avoid creating new class or property unless you have to.
|
||||
- Avoid shadow var, e.g. `bytes` should be named as `payload`.
|
||||
- Avoid using `js/Buffer` in browser related code.
|
||||
- Git commits should include a concise summary.
|
||||
- When deleting properties in db migration, those properties should be added to `logseq.db-sync.tx-sanitize/migration-deleted-attrs`
|
||||
- Use spec-dev-tool to manage agent decision documents; run `spec-dev-tool --help` and follow its AGENT WORKFLOW.
|
||||
- When asked to find simplifications, run `spec-dev-tool guide find-simplifications` from inside this Git worktree and follow the emitted workflow.
|
||||
88
CODEBASE_OVERVIEW.md
Normal file
@@ -0,0 +1,88 @@
|
||||
# Logseq Codebase Overview
|
||||
|
||||
This document helps you understand more about how Logseq works. To contribute, read the [README](https://github.com/logseq/logseq) first.
|
||||
|
||||
## Tech Stack
|
||||
|
||||
### Clojure/ClojureScript
|
||||
|
||||
Nowadays compile-to-js are common practice. With the advent of web assembly, you can use almost any language to write browser apps. The Logseq app mostly uses Clojure.
|
||||
|
||||
Simply put, Clojure is a dynamic typing functional programming language, with Lisp's syntax, running on the JVM. ClojureScript is just Clojure compiling to JavaScript.
|
||||
|
||||
Clojure is easy to learn, you can pick it up pretty quickly following the [official guide](https://clojure.org/guides/learn/syntax).
|
||||
|
||||
Logseq chose ClojureScript not only because of all the [benefits](https://clojure.org/about/rationale) of the language itself but also because of its awesome ecosystem, such as the [DataScript](https://github.com/tonsky/datascript) library. More on that later.
|
||||
|
||||
### Build Tools
|
||||
|
||||
Shadow-cljs is a tool that helps compiling the ClojureScript code to JavaScript. In addition, it supports more handy features like live reload, code splitting, REPL, etc.
|
||||
|
||||
For other tasks like bundling static resources and building the desktop app, which is not covered by shadow-cljs, Logseq uses the good old [Gulp](https://gulpjs.com).
|
||||
|
||||
### React & Rum
|
||||
|
||||
[React](https://reactjs.org/) is a library for building data-driven UI declaratively. Comparing to the imperative ways (such as DOM manipulation or using jQuery), it's simpler and easier to code correctly.
|
||||
|
||||
[Rum](https://github.com/tonsky/rum) is a React wrapper in ClojureScript. More than just providing the familiar React APIs, Rum adds many Clojure flavors to React, especially on the state management part. As a result, if you have experience with React, read Rum's [README](https://github.com/tonsky/rum) before diving into the code.
|
||||
|
||||
### DataScript
|
||||
|
||||
[DataScript](https://github.com/tonsky/datascript) is an in-memory database that implements the [Datalog](https://en.wikipedia.org/wiki/Datalog) logic programming language. Datalog is very different from and much more expressive than the more common SQL and NoSQL query languages. Many users have implemented interesting features on top of Logseq just by utilizing the rich query language. Get started with Datalog with this [tutorial](http://www.learndatalogtoday.org/)
|
||||
|
||||
## Important Directories and Files
|
||||
|
||||
This is overview of this repository's most important directories and files.
|
||||
|
||||
- Config files are located at the root directory. `package.json` contains the JavaScript dependencies while `deps.edn` contains their ClojureScript counterparts. `shadow-cljs.edn` and `gulpfile.js` contain all the build scripts.
|
||||
|
||||
- `resources/` and `public` contain all the static assets
|
||||
|
||||
- `src/` is where most of the code is located.
|
||||
|
||||
- `src/electron/` contains code specific to the Electron desktop app.
|
||||
|
||||
- `src/test/` contains all the cljs tests.
|
||||
|
||||
- `src/resources/` is a directory and Clojure(Script) resource classpath and includes language translations.
|
||||
|
||||
- `src/main/frontend/` contains code that powers the Logseq editor. Directories and files inside are organized by features or functions. Some notable directories:
|
||||
- `src/main/frontend/components/` contains all the UI components.
|
||||
- `src/main/frontend/handler/` contains system component like code.
|
||||
- `src/main/frontend/worker/` contains code for the separate worker asset.
|
||||
- `src/main/frontend/common/` contains common code shared by the worker asset and the frontend.
|
||||
- `src/main/logseq/` contains the api used by plugins.
|
||||
- `src/main/mobile/` contains code for new mobile app.
|
||||
- `src/dev-cljs/` contains some development utilities.
|
||||
|
||||
- `deps/` contains ClojureScript dependencies or libraries used by the frontend.
|
||||
- `deps/graph-parser/` is a library that parses a Logseq graph and saves it to a database.
|
||||
|
||||
- `scripts` - Dev scripts
|
||||
- `clj-e2e/` - end to end clj frontend tests
|
||||
- `android/` - Android app
|
||||
- `ios/` - iOS app
|
||||
|
||||
## Data Flow
|
||||
|
||||
### Application State
|
||||
|
||||
Most of Logseq's application state is divided into two parts. Document-related state (all your pages, blocks, and contents) is stored in DataScript. UI-related state (such as the current editing block) is kept in Clojure's [atom](https://clojure.org/reference/atoms). We then use Rum's reactive component to subscribe to these states. React efficiently re-renders after state changes.
|
||||
|
||||
### When the App Starts
|
||||
|
||||
Logseq loads files from your computer or the cloud, depending on your usage. The files are then parsed (and might be decrypted) and stored in DataScript. Other UI-related states are initialized. React components render for the first time. Event handlers are registered.
|
||||
|
||||
### When you Type Something in the Document
|
||||
|
||||
It's the typical flow of an event-driven GUI application. Various handlers (which are just functions) are listening for events like drag and drop, edit, format, and so on. When you start typing, the handler for editing blocks is called. It does three things:
|
||||
|
||||
- Save your work to the disk or the cloud, so you won't lose them in case of an emergent power off.
|
||||
- Update the UI state.
|
||||
- Run transactions to update the DataScript database. Since other parts of the app may use data that are affected by the change, we need to rebuild the database query cache.
|
||||
|
||||
After the change changes, React will dutifully refresh the screen.
|
||||
|
||||
## Architecture
|
||||
|
||||
Logseq has undergone a heavy refactoring, results in a much more robust and clear architecture. Read [this article](https://docs.logseq.com/#/page/The%20Refactoring%20Of%20Logseq) written by the main contributor to the refactoring for a detailed tour.
|
||||
140
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,140 @@
|
||||
# Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering a safe and welcoming environment, we as
|
||||
the Logseq team pledge to make participation in our
|
||||
community a harassment-free experience for everyone, regardless of age, body
|
||||
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||
identity and expression, level of experience, education, socio-economic status,
|
||||
nationality, personal appearance, race, caste, color, religion, or sexual
|
||||
identity and orientation.
|
||||
|
||||
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||
diverse, inclusive, and healthy community. Logseq is not merely a note-taking tool, but can potentially become a community for collaboration and learning.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to a positive environment for our
|
||||
community include:
|
||||
|
||||
* Demonstrating empathy and kindness toward other people
|
||||
* Being respectful of differing opinions, viewpoints, and experiences
|
||||
* Giving and gracefully accepting constructive feedback
|
||||
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||
and learning from the experience
|
||||
* Focusing on what is best not just for us as individuals, but for the overall
|
||||
community
|
||||
|
||||
Examples of unacceptable behavior include:
|
||||
|
||||
* The use of sexualized language or imagery, and sexual attention or advances of
|
||||
any kind
|
||||
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or email address,
|
||||
without their explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Enforcement Responsibilities
|
||||
|
||||
Logseq team is responsible for clarifying and enforcing our standards of
|
||||
acceptable behavior and will take appropriate and fair corrective action in
|
||||
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||
or harmful.
|
||||
|
||||
Logseq team has the right and responsibility to remove, edit, or reject
|
||||
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||
decisions when appropriate.
|
||||
|
||||
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies to all Logseq communication channels - online or in person,
|
||||
and it also applies when an individual is representing the project or its community in
|
||||
public spaces. Examples of representing a project or community include using an official
|
||||
project e-mail address, posting via an official social media account, or acting
|
||||
as an appointed representative at an online or offline event. Representation of
|
||||
a project may be further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the moderators on the [Forum](https://discuss.logseq.com), [Discord](https://discord.gg/KpN4eHY) channel, Tienson Qin (@tiensonqin) on GitHub, or the official [Twitter](https://twitter.com/logseq). We will work with you to resolve the issue promptly. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The Logseq team
|
||||
will maintain confidentiality with regard to the reporter of an incident.
|
||||
Enforcement may result in an indefinite ban from all official Logseq communication
|
||||
channels, or other actions as deemed appropriate by the Logseq team.
|
||||
|
||||
Logseq maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Enforcement Guidelines
|
||||
|
||||
Logseq team and community leaders will follow these Community Impact Guidelines in determining
|
||||
the consequences for any action they deem in violation of this Code of Conduct:
|
||||
|
||||
### 1. Correction
|
||||
|
||||
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||
unprofessional or unwelcome in the community.
|
||||
|
||||
**Consequence**: A private, written warning from community leaders, providing
|
||||
clarity around the nature of the violation and an explanation of why the
|
||||
behavior was inappropriate. A public apology may be requested.
|
||||
|
||||
### 2. Warning
|
||||
|
||||
**Community Impact**: A violation through a single incident or series of
|
||||
actions.
|
||||
|
||||
**Consequence**: A warning with consequences for continued behavior. No
|
||||
interaction with the people involved, including unsolicited interaction with
|
||||
those enforcing the Code of Conduct, for a specified period of time. This
|
||||
includes avoiding interactions in community spaces as well as external channels
|
||||
like social media. Violating these terms may lead to a temporary or permanent
|
||||
ban.
|
||||
|
||||
### 3. Temporary Ban
|
||||
|
||||
**Community Impact**: A serious violation of community standards, including
|
||||
sustained inappropriate behavior.
|
||||
|
||||
**Consequence**: A temporary ban from any sort of interaction or public
|
||||
communication with the community for a specified period of time. No public or
|
||||
private interaction with the people involved, including unsolicited interaction
|
||||
with those enforcing the Code of Conduct, is allowed during this period.
|
||||
Violating these terms may lead to a permanent ban.
|
||||
|
||||
### 4. Permanent Ban
|
||||
|
||||
**Community Impact**: Demonstrating a pattern of violation of community
|
||||
standards, including sustained inappropriate behavior, harassment of an
|
||||
individual, or aggression toward or disparagement of classes of individuals.
|
||||
|
||||
**Consequence**: A permanent ban from any sort of public interaction within the
|
||||
community.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||
version 2.1, available at
|
||||
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
||||
|
||||
Community Impact Guidelines were inspired by
|
||||
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
||||
|
||||
For answers to common questions about this code of conduct, see the FAQ at
|
||||
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
||||
[https://www.contributor-covenant.org/translations][translations].
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
||||
[Mozilla CoC]: https://github.com/mozilla/diversity
|
||||
[FAQ]: https://www.contributor-covenant.org/faq
|
||||
[translations]: https://www.contributor-covenant.org/translations
|
||||
173
CONTRIBUTING.md
Normal file
@@ -0,0 +1,173 @@
|
||||
# Contributing to Logseq
|
||||
|
||||
Thanks for your interest! :heart: :man_dancing: :woman_dancing: We would love
|
||||
for you to contribute to Logseq and help make it even better than it is today!
|
||||
|
||||
As a contributor, here is an overview of things to learn about and ways to get involved:
|
||||
|
||||
- [Code of Conduct](#coc)
|
||||
- [How can I help?](#how-can-i-help)
|
||||
- [Question or Problem?](#question)
|
||||
- [Issues and Bugs](#issue)
|
||||
- [Feature Requests](#feature)
|
||||
- [Submit an Issue](#submit-issue)
|
||||
- [Submit a Pull Request](#submit-pr)
|
||||
|
||||
## <a name="coc"></a> Code of Conduct
|
||||
|
||||
Help us keep Logseq open and inclusive.
|
||||
Please read and follow our [Code of Conduct][coc].
|
||||
|
||||
## <a name="how-can-i-help"></a> How can I help?
|
||||
|
||||
There are many ways you can help. Here are some ways to help without coding:
|
||||
|
||||
- You can help others on [Discord][discord] or [Reddit](https://www.reddit.com/r/logseq).
|
||||
- You can [contribute to the official docs](https://github.com/logseq/docs/blob/master/CONTRIBUTING.md).
|
||||
- You can confirm bugs on the [issue tracker][issue-tracker] and mention reproducible steps. It helps the core team to get more reports so we can fix the highest priority bugs.
|
||||
- You can contribute [translations][translations] with a [pull request](#submit-pr).
|
||||
|
||||
For ways to help with coding, read the next section.
|
||||
|
||||
### <a name="code-contributions"></a> Code Contributions
|
||||
|
||||
For contributors who want to help with coding, we have a list of [good first
|
||||
issues](https://github.com/logseq/db-test/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22)
|
||||
to help you get started. These are issues that are beginner-friendly and do not
|
||||
require advanced knowledge of the codebase. We encourage new contributors to
|
||||
start with these issues and gradually work their way up to more challenging
|
||||
tasks. Another way to help with coding is by extending Logseq with
|
||||
[plugins](https://docs.logseq.com/#/page/Plugins) and submitting them to the [marketplace](https://github.com/logseq/marketplace) so that the
|
||||
whole community can benefit.
|
||||
|
||||
## <a name="question"></a> Got a Question or a Problem?
|
||||
|
||||
Please do not open issues for general support questions or feature requests as we want to keep GitHub issues for bug reports.
|
||||
Instead, we recommend using [Logseq forum][forum] to ask support-related questions.
|
||||
|
||||
The Logseq forum is a much better place to ask questions since:
|
||||
|
||||
- there are more people willing to help on the forum
|
||||
- questions and answers stay available for public viewing so your question/answer might help someone else
|
||||
- The forum's voting system assures that the best answers are prominently visible.
|
||||
|
||||
To save your and our time, we will systematically close all issues that are requests for general support and redirect people to the forum.
|
||||
|
||||
If you would like to chat about the question in real-time, you can reach out via [our Discord server][discord].
|
||||
|
||||
## <a name="issue"></a> Found a Bug?
|
||||
|
||||
If you find a bug, you can help us by [submitting an issue](#submit-issue) to our [GitHub Repository][github].
|
||||
Even better, you can [submit a Pull Request](#submit-pr) with a fix.
|
||||
|
||||
## <a name="feature"></a> Missing a Feature?
|
||||
|
||||
You can *request* a new feature by [Creating a thread][feature-request] in our forum.
|
||||
If you would like to *implement* a new feature, please open an issue and outline your proposal so that it can be discussed.
|
||||
|
||||
## <a name="submit-issue"></a> Submit an Issue
|
||||
|
||||
Before you submit an issue, please search the [issue tracker][issue-tracker]. An issue for your problem might already exist and the discussion might inform you of workarounds readily available.
|
||||
|
||||
To submit an issue, [fill out the bug report template][new-issue]. Please file a
|
||||
single issue per problem and do not enumerate multiple bugs in the same issue.
|
||||
|
||||
The template will ask you to include the following with each issue:
|
||||
|
||||
- Version of Logseq
|
||||
- Your operating system
|
||||
- List of extensions that you have installed. Attempt to recreate the issue after disabling all extensions.
|
||||
- Reproducible steps (1... 2... 3...) that cause the issue
|
||||
- What you expected to see, versus what you actually saw
|
||||
- Images, animations, or a link to a video showing the issue occurring
|
||||
- A code snippet that demonstrates the issue or a link to a code repository the developers can easily pull down to recreate the issue locally
|
||||
- **Note:** Because the developers need to copy and paste the code snippet, including a code snippet as a media file (i.e. .gif) is not sufficient.
|
||||
- Errors from the Dev Tools Console (open from the menu: View > Toggle Developer Tools or press CTRL + Shift + i)
|
||||
|
||||
## <a name="submit-pr"></a> Submit a Pull Request (PR)
|
||||
|
||||
Before working on your pull request, please check the following:
|
||||
|
||||
1. Search [GitHub][search-pr] for related PRs that may affect your submission.
|
||||
|
||||
2. Be sure that an issue describes the problem you're fixing or the feature
|
||||
behavior and design you'd like to add.
|
||||
|
||||
3. Please sign our [Contributor License Agreement (CLA)](#cla). We cannot accept
|
||||
code without a signed CLA.
|
||||
|
||||
After doing the above, you are ready to work on your PR! To create a PR, fork
|
||||
this repository and then create a branch for the fix. If contributing to the [database version](/README.md#-database-version), create a branch from master. If contributing to the file (text-only) version e.g. any version up to `0.10.X`, create a branch from [version/file](https://github.com/logseq/logseq/tree/version/file/).
|
||||
Once you push your code to
|
||||
your fork, you'll be able to open a PR to the Logseq repository. For more info,
|
||||
you can follow this [GitHub
|
||||
guide](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork).
|
||||
For more github PR guides, see [these
|
||||
guides](https://docs.github.com/en/pull-requests).
|
||||
|
||||
### PR Guidelines
|
||||
|
||||
When submitting a Pull Request (PR) or expecting a subsequent review, please follow these guidelines:
|
||||
|
||||
1. The PR is ready for review. If you have work you know how to do, then please keep your changes local until they are ready. If you need help with your PR, feel free to submit with questions.
|
||||
|
||||
2. The PR checks which include tests and [lint checks](https://github.com/logseq/logseq/blob/master/docs/dev-practices.md#linting) are passing.
|
||||
|
||||
3. The PR has no merge conflicts.
|
||||
|
||||
4. The PR has [test(s)](https://github.com/logseq/logseq/blob/master/docs/dev-practices.md#testing) for features or enhancements. Tests for bug fixes are also appreciated as they help prevent regressions.
|
||||
|
||||
5. The PR has a descriptive title that a user can understand. We use these titles to generate changelogs for the user. Most titles use one of these prefixes to categorize the PR e.g. `PREFIX: DESCRIPTION ...`:
|
||||
* `chore` - Misc changes that aren't dev, feat or fix
|
||||
* `dev` - Developer related changes
|
||||
* `enhance` - Enhancements i.e. changes to existing features
|
||||
* `feat` or `feature` - New features
|
||||
* `fix` - Bug fixes
|
||||
* `test` - Test only changes
|
||||
|
||||
6. The PR having "allow edits from maintainers" enabled would be appreciated. Helps us help your contribution.
|
||||
|
||||
7. The PR avoids the following changes that are not helpful to the core team:
|
||||
* Unrelated refactoring or heavy refactoring
|
||||
* Code or doc formatting changes including whitespace changes
|
||||
* Dependency updates e.g. in `package.json`
|
||||
* Changes that contain multiple unverified resources. This is risky for our users and is a lot of work to verify. A change with one resource that can be verified is acceptable.
|
||||
|
||||
### PR Additional Links
|
||||
|
||||
* To run Logseq locally, see [this doc](https://github.com/logseq/logseq/blob/master/docs/develop-logseq.md) or [this doc for Windows](https://github.com/logseq/logseq/blob/master/docs/develop-logseq-on-windows.md).
|
||||
* To contribute to translations, please read our [translation contribution guidelines][translations].
|
||||
* See [our development practices doc](https://github.com/logseq/logseq/blob/master/docs/dev-practices.md) to learn how we develop.
|
||||
* See [the overview doc](CODEBASE_OVERVIEW.md) to get an overview of the codebase.
|
||||
|
||||
### <a name="cla"></a> Sign the CLA
|
||||
|
||||
Please sign our Contributor License Agreement (CLA) before sending pull requests. For any code
|
||||
changes to be accepted, the CLA must be signed. It's a quick process, we promise!
|
||||
|
||||
- For individuals, we have a [simple click-through form][individual-cla].
|
||||
- For corporations, please contact us.
|
||||
|
||||
If you have more than one GitHub account or multiple email addresses associated with a single GitHub account, you must sign the CLA using the primary email address of the GitHub account used to author Git commits and send pull requests.
|
||||
|
||||
The following documents can help you sort out issues with GitHub accounts and multiple email addresses:
|
||||
|
||||
- <https://help.github.com/articles/setting-your-commit-email-address-in-git/>
|
||||
- <https://stackoverflow.com/questions/37245303/what-does-usera-committed-with-userb-13-days-ago-on-github-mean>
|
||||
- <https://help.github.com/articles/about-commit-email-addresses/>
|
||||
- <https://help.github.com/articles/blocking-command-line-pushes-that-expose-your-personal-email-address/>
|
||||
|
||||
## Thank You
|
||||
|
||||
Your contributions to open source, large or small, make great projects like this possible. Thank you for taking the time to contribute.
|
||||
|
||||
[coc]: https://github.com/logseq/logseq/blob/master/CODE_OF_CONDUCT.md "Logseq Code Of Conduct"
|
||||
[translations]: https://github.com/logseq/logseq/blob/master/docs/contributing-to-translations.md "contributing to translations"
|
||||
[github]: https://github.com/logseq/logseq "Logseq Repo"
|
||||
[discord]: https://discord.gg/KpN4eHY "Logseq Discord Server"
|
||||
[individual-cla]: https://cla-assistant.io/logseq/logseq "Individual CLA"
|
||||
[feature-request]: https://discuss.logseq.com/c/feedback/feature-requests/ "Submit Feature Request"
|
||||
[forum]: https://discuss.logseq.com "Logseq Forum"
|
||||
[search-pr]: https://github.com/logseq/logseq/pulls "Search open PRs"
|
||||
[new-issue]: https://github.com/logseq/db-test/issues/new?assignees=&labels=&template=bug_report.yaml "Submit a New issue"
|
||||
[issue-tracker]: https://github.com/logseq/db-test/issues "Logseq Issue Tracker"
|
||||
36
Dockerfile
Normal file
@@ -0,0 +1,36 @@
|
||||
# NOTE: please keep it in sync with .github pipelines
|
||||
# NOTE: during testing make sure to change the branch below
|
||||
# NOTE: before running the build-docker GH action edit
|
||||
# build-docker.yml and change the release channel from :latest to :testing
|
||||
|
||||
# Builder image
|
||||
FROM clojure:temurin-11-tools-deps-1.11.1.1208-bullseye-slim as builder
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Install reqs
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
curl \
|
||||
ca-certificates \
|
||||
apt-transport-https \
|
||||
gpg \
|
||||
build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
|
||||
|
||||
# install NodeJS & pnpm
|
||||
RUN curl -fsSL https://deb.nodesource.com/setup_24.x | bash - && \
|
||||
apt-get update && apt-get install -y nodejs && \
|
||||
corepack enable && corepack prepare pnpm@10.33.0 --activate
|
||||
|
||||
WORKDIR /data
|
||||
|
||||
# build Logseq static resources
|
||||
RUN git clone -b master https://github.com/logseq/logseq.git .
|
||||
|
||||
RUN pnpm install --config.network-timeout=240000
|
||||
|
||||
RUN pnpm release
|
||||
|
||||
# Web App Runner image
|
||||
FROM nginx:1.24.0-alpine3.17
|
||||
|
||||
COPY --from=builder /data/static /usr/share/nginx/html
|
||||
697
LICENSE.md
Normal file
@@ -0,0 +1,697 @@
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
Additional permission under GNU GPL version 3 section 7
|
||||
|
||||
If you modify this Program, or any covered work, by linking or combining it with any of the below libraries (or a modified version of that library), containing parts covered by the terms of any of the below libraries, the licensors of this Program grant you additional permission to convey the resulting work.
|
||||
|
||||
* cider/cider-nrepl
|
||||
* clojure-complete
|
||||
* com.cemerick/friend
|
||||
* compojure
|
||||
* environ
|
||||
* hiccup
|
||||
* medley
|
||||
* org.clojure/clojure
|
||||
* org.clojure/clojurescript
|
||||
* org.clojure/core.async
|
||||
* org.clojure/core.cache
|
||||
* org.clojure/core.incubator
|
||||
* org.clojure/core.logic
|
||||
* org.clojure/core.match
|
||||
* org.clojure/core.memoize
|
||||
* org.clojure/data.csv
|
||||
* org.clojure/data.json
|
||||
* org.clojure/data.priority-map
|
||||
* org.clojure/java.classpath
|
||||
* org.clojure/java.jdbc
|
||||
* org.clojure/math.numeric-tower
|
||||
* org.clojure/tools.analyzer
|
||||
* org.clojure/tools.analyzer.jvm
|
||||
* org.clojure/tools.logging
|
||||
* org.clojure/tools.macro
|
||||
* org.clojure/tools.namespace
|
||||
* org.clojure/tools.nrepl
|
||||
* org.clojure/tools.reader
|
||||
* org.tcrawley/dynapath
|
||||
* refactor-nrepl
|
||||
* slingshot
|
||||
228
README.md
Normal file
@@ -0,0 +1,228 @@
|
||||
<!-- logo -->
|
||||
<p align="center">
|
||||
<a href="https://logseq.com" alt="Logseq Logo">
|
||||
<img src="https://user-images.githubusercontent.com/25513724/220608753-f33db466-af72-4611-b603-411440c15ed0.png?sanatize=true" height="173"/></a>
|
||||
</p>
|
||||
|
||||
<h1 align="center"> Logseq </h1>
|
||||
|
||||
<h4 align="center">
|
||||
A privacy-first, open-source platform for knowledge management and collaboration
|
||||
</h4>
|
||||
|
||||
<div align="center">
|
||||
<a href="https://logseq.com">Home Page</a> |
|
||||
<a href="https://blog.logseq.com/">Blog</a> |
|
||||
<a href="https://docs.logseq.com/">Documentation</a> |
|
||||
<a href="https://logseq.io/p/NX4mc_ggEV">Roadmap</a>
|
||||
</div>
|
||||
<br></br>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/logseq/logseq/releases/latest/">
|
||||
<img src="https://img.shields.io/badge/Download_Logseq-100000?style=for-the-badge&logo=flatpak&logoColor=white&labelColor=002b36&color=85c8c8"
|
||||
alt="Download Logseq"/></a>
|
||||
</p>
|
||||
|
||||
<!-- social badges -->
|
||||
<p align="center">
|
||||
<a href="https://discuss.logseq.com">
|
||||
<img src="https://img.shields.io/badge/forum-Logseq-blue.svg?&color=%2385c8c8&logo=discourse&style=for-the-badge"
|
||||
alt="forum"></a>
|
||||
<a href="https://discord.gg/KpN4eHY">
|
||||
<img src="https://img.shields.io/discord/725182569297215569?color=%2385c8c8&label=Discord&logo=discord&style=for-the-badge"
|
||||
alt="chat on Discord"></a>
|
||||
<a href="https://twitter.com/intent/follow?screen_name=logseq">
|
||||
<img src="https://img.shields.io/badge/twitter-%40logseq-blue.svg?&color=%2385c8c8&logo=twitter&style=for-the-badge"
|
||||
alt="follow on Twitter"></a>
|
||||
</p>
|
||||
|
||||
<!-- dev badges -->
|
||||
<p align="center">
|
||||
<a href="https://github.com/logseq/logseq/graphs/contributors" alt="Contributors">
|
||||
<img src="https://img.shields.io/github/contributors/logseq/logseq?color=%2385c8c8&style=for-the-badge"/></a>
|
||||
<a href="#-backers" alt="Backers on Open Collective">
|
||||
<img src="https://img.shields.io/opencollective/backers/logseq?color=%2385c8c8&style=for-the-badge"/></a>
|
||||
<a href="#-sponsors" alt="Sponsors on Open Collective">
|
||||
<img src="https://img.shields.io/opencollective/sponsors/logseq?color=%2385c8c8&style=for-the-badge"/></a>
|
||||
<a href="https://github.com/logseq/logseq/blob/master/LICENSE.md" alt="Activity">
|
||||
<img src="https://img.shields.io/github/license/logseq/logseq?color=%2385c8c8&style=for-the-badge"/></a>
|
||||
<a href="https://github.com/logseq/logseq/releases">
|
||||
<img src="https://img.shields.io/github/v/release/logseq/logseq?color=%2385c8c8&style=for-the-badge"
|
||||
alt="latest release version"></a>
|
||||
</p>
|
||||
|
||||
## Table of Contents
|
||||
|
||||
* [<g-emoji class="g-emoji" alias="database" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f680.png">🚀</g-emoji> Database Version](#-database-version)
|
||||
* [<g-emoji class="g-emoji" alias="thinking" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f914.png">🤔</g-emoji> Why Logseq?](#-why-logseq)
|
||||
* [<g-emoji class="g-emoji" alias="eyes" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f440.png">👀</g-emoji> How can I use it?](#-how-can-i-use-it)
|
||||
* [<g-emoji class="g-emoji" alias="books" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f4da.png">📚</g-emoji> Learn more](#-learn-more)
|
||||
* [🫶 Support Logseq Development](#-support-logseq-development)
|
||||
* [<g-emoji class="g-emoji" alias="bulb" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f4a1.png">💡</g-emoji> Feature requests](#-feature-requests)
|
||||
* [<g-emoji class="g-emoji" alias="electric_plug" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f50c.png">🔌</g-emoji> Plugin API](#-plugin-api)
|
||||
* [<g-emoji class="g-emoji" alias="star2" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f31f.png">🌟</g-emoji> Contributing to Logseq](#-contributing-to-logseq)
|
||||
* [<g-emoji class="g-emoji" alias="hammer_and_wrench" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f6e0.png">🛠️</g-emoji> Setting Up a Development Environment](#️-setting-up-a-development-environment)
|
||||
* [<g-emoji class="g-emoji" alias="sparkles" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2728.png">✨</g-emoji> Inspiration](#-inspiration)
|
||||
* [<g-emoji class="g-emoji" alias="pray" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f64f.png">🙏</g-emoji> Thank You](#-thank-you)
|
||||
|
||||
## 🚀 Database Version
|
||||
|
||||
The Database version (DB version) of Logseq introduces DB graphs. [See this page](https://github.com/logseq/docs/blob/master/db-version.md) to get an overview of the main features for DB graphs. If you are an existing user, [see changes with the DB version](https://github.com/logseq/docs/blob/master/db-version-changes.md). The DB version has its own new mobile app (on iOS, with Android coming soon)! To participate in the mobile app alpha, [please complete this brief form](https://forms.gle/nfefJv51jUuULbFB9). The DB version also has a new sync approach, RTC (Real Time Collaboration)! You can use it to sync graphs between multiple devices or collaborate with others. To participate in the RTC alpha, [please fill out this form](https://forms.gle/YSyF4WfKPSDuwyjH6).
|
||||
|
||||
The DB version is in beta status while the new mobile app and RTC is in alpha. This means that **data loss is possible** so we recommend [automated backups](https://github.com/logseq/docs/blob/master/db-version.md#automated-backup) or [regular SQLite DB backups](https://github.com/logseq/docs/blob/master/db-version.md#graph-export). We recommend you create a dedicated test graph and choose one project that’s not crucial for you.
|
||||
|
||||
To get started with the DB version:
|
||||
* To try the latest web version, go to https://app.logseq.com/.
|
||||
* To try the latest desktop version, go to https://github.com/logseq/logseq/releases/tag/nightly and download the artifact for your operating system.
|
||||
* To try the latest by building from the source code
|
||||
* Use `test/db` for stable releases. Fewer bugs and slower updates. Update frequency: days or weeks.
|
||||
* Use `master` for the latest updates as they are developed. Expect more bugs and faster changes. Update frequency: hours or days.
|
||||
* To report bugs, please file them at https://github.com/logseq/db-test/issues.
|
||||
* For feature or enhancement requests, please file them on Discord on the `#db-feedback` channel.
|
||||
* For discussions:
|
||||
* General ==> see the `#db-chat` channel in Discord.
|
||||
* Sync and RTC ==> see the `#sync-test` channel in Discord.
|
||||
* Mobile ==> see the `#mobile-test` channel in Discord.
|
||||
|
||||
## 🤔 Why Logseq?
|
||||
|
||||
[Logseq](https://logseq.com) is a **knowledge management** and **collaboration** platform. It focuses on **privacy**, **longevity**, and [**user control**](https://www.gnu.org/philosophy/free-sw.en.html). Logseq offers a range of **powerful tools** for **knowledge management**, **collaboration**, **PDF annotation**, and **task management** with support for multiple file formats, including **Markdown** and **Org-mode**, and **various features** for organizing and structuring your notes.
|
||||
|
||||
In addition to its core features, Logseq has a growing ecosystem of **plugins** and **themes** that enable a wide range of workflows and **customization** options. **Mobile apps** are also available, providing access to most of the features of the desktop application. Whether you're a student, a professional, or anyone who values a clear and organized approach to managing your ideas and notes, Logseq is an excellent choice for anyone looking to improve their productivity and streamline their workflow.
|
||||
|
||||

|
||||
|
||||
<a href="https://github.com/logseq/logseq/releases/latest/">
|
||||
<img src="https://img.shields.io/badge/Download_Logseq-100000?style=for-the-badge&logo=flatpak&logoColor=white&labelColor=002b36&color=85c8c8"
|
||||
align="right"
|
||||
alt="Download Logseq"/></a>
|
||||
|
||||
## 👀 How can I use it?
|
||||
|
||||
To start using Logseq, follow these simple steps:
|
||||
|
||||
1. [Download](https://github.com/logseq/logseq/releases/latest) the latest version of Logseq
|
||||
2. Install Logseq on your device and launch the application
|
||||
3. Start writing ✍️
|
||||
|
||||
That's it! You can now enjoy the benefits of using Logseq to streamline your workflow, manage your projects, and stay on top of your goals. Have fun! 🎉
|
||||
|
||||
**Linux users**: Use the automated installer script for the best experience:
|
||||
|
||||
```bash
|
||||
# Download and run the installer
|
||||
curl -fsSL https://raw.githubusercontent.com/logseq/logseq/master/scripts/install-linux.sh | bash
|
||||
|
||||
# Or install a specific version
|
||||
curl -fsSL https://raw.githubusercontent.com/logseq/logseq/master/scripts/install-linux.sh | bash -s -- 0.10.14
|
||||
|
||||
# For user-specific installation (no root required)
|
||||
curl -fsSL https://raw.githubusercontent.com/logseq/logseq/master/scripts/install-linux.sh | bash -s -- --user
|
||||
```
|
||||
|
||||
## 📚 Learn more
|
||||
|
||||
* Website: [logseq.com](https://logseq.com)
|
||||
* Documentation: [docs.logseq.com](https://docs.logseq.com)
|
||||
* FAQ page: [Logseq Docs: FAQ](https://docs.logseq.com/#/page/faq)
|
||||
* Blog: [blog.logseq.com](https://blog.logseq.com)
|
||||
* Please visit our [About page](https://blog.logseq.com/about) for the latest updates.
|
||||
* Forum: [discuss.logseq.com](https://discuss.logseq.com) - Where we answer questions, discuss workflows, and share tips
|
||||
* FAQ forum section: [Logseq Forum: FAQ](https://discuss.logseq.com/c/faq/6)
|
||||
* [Awesome Logseq](https://github.com/logseq/awesome-logseq) - Awesome Logseq extensions and resources created by the community <3
|
||||
* Twitter: [@Logseq](https://twitter.com/logseq)
|
||||
* Discord: [https://discord.com/invite/KpN4eHY](https://discord.com/invite/KpN4eHY)
|
||||
* [中文 Discord](https://discord.gg/xYqcrXWymg)
|
||||
|
||||
## 🫶 Support Logseq Development
|
||||
|
||||
If you find Logseq useful and want to help us keep the project growing, please consider supporting our contributors on [Open Collective](https://opencollective.com/logseq). Your support shows our contributors that their efforts are appreciated and motivates them to continue their excellent work. Every contribution, no matter how small, helps us keep improving Logseq.
|
||||
|
||||
## 💡 Feature requests
|
||||
|
||||
We value your input on improving Logseq and making it more useful for you. If you have any ideas or feature requests, please share them in the [Logseq Forum: Feature
|
||||
Requests](https://discuss.logseq.com/new-topic?category=feature-requests) section.
|
||||
|
||||
Your feedback helps us understand our users' needs and prioritize the features that matter most to you. We appreciate your time and effort in sharing your thoughts with us.
|
||||
|
||||
We appreciate your support, and we look forward to hearing your ideas!
|
||||
|
||||
## 🔌 Plugin API
|
||||
|
||||
Logseq provides a plugin API that enables developers to create custom plugins and extend the functionality of Logseq. The plugin API documentation is available at [plugins-doc.logseq.com](https://plugins-doc.logseq.com/), where you can find everything needed to get started with plugin development.
|
||||
|
||||
We value your feedback and suggestions on how to improve our documentation. Please do not hesitate to contact us with any comments or questions. Your input helps us to provide a better experience for our users and developers.
|
||||
|
||||
Thank you for using Logseq, and we look forward to seeing what you create with our plugin API!
|
||||
|
||||
## 🌟 Contributing to Logseq
|
||||
|
||||
To start contributing to Logseq, please read [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||
There are ways to contribute [with code](https://github.com/logseq/logseq/blob/master/CONTRIBUTING.md#code-contributions) and [without code](https://github.com/logseq/logseq/blob/master/CONTRIBUTING.md#-how-can-i-help). We welcome all
|
||||
contributions, big or small, and we appreciate your time and effort in helping
|
||||
us improve Logseq. We look forward to your contributions 🚀
|
||||
|
||||
### 🛠️ Setting Up a Development Environment
|
||||
|
||||
If you want to set up a development environment for the Logseq web or desktop app, please refer to the [Develop Logseq](docs/develop-logseq.md) guide for macOS/Linux users and the [Develop Logseq on Windows](docs/develop-logseq-on-windows.md) guide for Windows users.
|
||||
|
||||
In addition to these guides, you can also find other helpful resources in the [docs/](docs/) folder, such as the [Guide for Contributing to Translations](docs/contributing-to-translations.md), the [Docker Web App Guide](docs/docker-web-app-guide.md) and the [mobile development guide](docs/develop-logseq-on-mobile.md)
|
||||
|
||||
### 🧰 Logseq CLI (Node)
|
||||
|
||||
Logseq CLI documentation is maintained in `docs/cli/logseq-cli.md`.
|
||||
|
||||
## ✨ Inspiration
|
||||
|
||||
Logseq is inspired by several unique tools and projects, including [Roam Research](https://roamresearch.com/), [Org Mode](https://orgmode.org/), [TiddlyWiki](https://tiddlywiki.com/), [Workflowy](https://workflowy.com/), and [Cuekeeper](https://github.com/talex5/cuekeeper).
|
||||
|
||||
We owe a huge debt of gratitude to the developers and creators of these projects, and we hope that Logseq can continue to build on their innovative ideas and make them accessible to a broader audience.
|
||||
|
||||
Thank you to all those who inspire us, and we look forward to seeing what the Logseq community will create with this tool!
|
||||
|
||||
Logseq is also made possible by the following projects:
|
||||
|
||||
* [Clojure & ClojureScript](https://clojure.org/) - A dynamic, functional, general-purpose programming language
|
||||
* [DataScript](https://github.com/tonsky/datascript) - An immutable database and Datalog query-engine for Clojure,
|
||||
ClojureScript and JS
|
||||
* [OCaml](https://ocaml.org/) & [Angstrom](https://github.com/inhabitedtype/angstrom), for the document parser [mldoc](https://github.com/logseq/mldoc)
|
||||
* [isomorphic-git](https://isomorphic-git.org/) - A pure JavaScript implementation of Git for NodeJS and web browsers
|
||||
* [SCI](https://github.com/borkdude/sci) - A Small Clojure Interpreter
|
||||
|
||||
# 🙏 Thank You
|
||||
|
||||
We want to express our sincere gratitude to our [Open Collective](https://opencollective.com/logseq) **sponsors**, **backers**, and **contributors**. Your support and contributions allow us to continue developing and improving Logseq. Thank you for being a part of our community and helping us make Logseq the best it can be!
|
||||
|
||||
## 💎 Sponsors
|
||||
|
||||
<p align="center">
|
||||
<a href="https://opencollective.com/logseq#sponsor"> [Become a sponsor]</a>
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://opencollective.com/logseq" alt="Sponsors on Open Collective">
|
||||
<img src="https://opencollective.com/logseq/tiers/sponsors.svg?avatarHeight=42&width=600"/></a>
|
||||
</p>
|
||||
|
||||
## 🌟 Contributors
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/logseq/logseq/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=logseq/logseq&max=300&columns=14" width="600"/></a>
|
||||
</p>
|
||||
|
||||
<!-- JetBrains Logo -->
|
||||
<p align="center">
|
||||
<a href="https://jetbrains.com" alt="JetBrains">
|
||||
<img src="docs/assets/jetbrains.svg"/></a>
|
||||
</p>
|
||||
|
||||
<!-- ProductHunt Review Button -->
|
||||
<p align="center">
|
||||
<a href="https://www.producthunt.com/posts/logseq?utm_source=badge-review&utm_medium=badge&utm_souce=badge-logseq#discussion-body"
|
||||
target="_blank"><img
|
||||
src="https://api.producthunt.com/widgets/embed-image/v1/review.svg?post_id=298158&theme=dark"
|
||||
align="center"
|
||||
alt="Logseq - Your joyful, private digital garden | Product Hunt" style="width: 250px; height: 54px;"
|
||||
width="250" height="54"/></a>
|
||||
</p>
|
||||
99
android/.gitignore
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
# Using Android gitignore template: https://github.com/github/gitignore/blob/HEAD/Android.gitignore
|
||||
|
||||
# Built application files
|
||||
*.apk
|
||||
*.aar
|
||||
*.ap_
|
||||
*.aab
|
||||
|
||||
# Files for the ART/Dalvik VM
|
||||
*.dex
|
||||
|
||||
# Java class files
|
||||
*.class
|
||||
|
||||
# Generated files
|
||||
bin/
|
||||
gen/
|
||||
out/
|
||||
# Uncomment the following line in case you need and you don't have the release build type files in your app
|
||||
# release/
|
||||
|
||||
# Gradle files
|
||||
.gradle/
|
||||
build/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
local.properties
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
|
||||
# Log Files
|
||||
*.log
|
||||
|
||||
# Android Studio Navigation editor temp files
|
||||
.navigation/
|
||||
|
||||
# Android Studio captures folder
|
||||
captures/
|
||||
|
||||
# IntelliJ
|
||||
*.iml
|
||||
.idea/workspace.xml
|
||||
.idea/tasks.xml
|
||||
.idea/gradle.xml
|
||||
.idea/assetWizardSettings.xml
|
||||
.idea/dictionaries
|
||||
.idea/libraries
|
||||
# Android Studio 3 in .gitignore file.
|
||||
.idea/caches
|
||||
.idea/modules.xml
|
||||
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
|
||||
.idea/navEditor.xml
|
||||
|
||||
# Keystore files
|
||||
# Uncomment the following lines if you do not want to check your keystore files in.
|
||||
#*.jks
|
||||
#*.keystore
|
||||
|
||||
# External native build folder generated in Android Studio 2.2 and later
|
||||
.externalNativeBuild
|
||||
.cxx/
|
||||
|
||||
# Google Services (e.g. APIs or Firebase)
|
||||
# google-services.json
|
||||
|
||||
# Freeline
|
||||
freeline.py
|
||||
freeline/
|
||||
freeline_project_description.json
|
||||
|
||||
# fastlane
|
||||
fastlane/report.xml
|
||||
fastlane/Preview.html
|
||||
fastlane/screenshots
|
||||
fastlane/test_output
|
||||
fastlane/readme.md
|
||||
|
||||
# Version control
|
||||
vcs.xml
|
||||
|
||||
# lint
|
||||
lint/intermediates/
|
||||
lint/generated/
|
||||
lint/outputs/
|
||||
lint/tmp/
|
||||
# lint/reports/
|
||||
|
||||
# Android Profiling
|
||||
*.hprof
|
||||
|
||||
# Cordova plugins for Capacitor
|
||||
capacitor-cordova-android-plugins
|
||||
|
||||
# Copied web assets
|
||||
app/src/main/assets/public
|
||||
|
||||
# Sentry Config File
|
||||
sentry.properties
|
||||
2
android/app/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/build/*
|
||||
!/build/.npmkeep
|
||||
79
android/app/build.gradle
Normal file
@@ -0,0 +1,79 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
apply from: 'capacitor.build.gradle'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'org.jetbrains.kotlin.plugin.compose'
|
||||
|
||||
android {
|
||||
namespace "com.logseq.app"
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
defaultConfig {
|
||||
applicationId "com.logseq.app"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 88
|
||||
versionName "2.0.1"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
aaptOptions {
|
||||
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
|
||||
// Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
|
||||
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
compose true
|
||||
}
|
||||
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion rootProject.ext.composeCompilerVersion
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = '21'
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
flatDir {
|
||||
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation "androidx.core:core-splashscreen:$coreSplashScreenVersion"
|
||||
implementation "androidx.coordinatorlayout:coordinatorlayout:$androidxCoordinatorLayoutVersion"
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
||||
implementation platform("androidx.compose:compose-bom:$composeBomVersion")
|
||||
implementation "androidx.activity:activity-compose:$androidxActivityVersion"
|
||||
implementation "androidx.compose.ui:ui"
|
||||
implementation "androidx.compose.foundation:foundation"
|
||||
implementation "androidx.compose.material3:material3"
|
||||
implementation "androidx.compose.material:material-icons-extended"
|
||||
implementation "androidx.compose.runtime:runtime"
|
||||
implementation "androidx.compose.animation:animation"
|
||||
implementation "androidx.navigation:navigation-compose:$androidxNavigationVersion"
|
||||
implementation "com.google.android.material:material:$materialVersion"
|
||||
implementation project(':capacitor-android')
|
||||
implementation 'androidx.documentfile:documentfile:1.0.1'
|
||||
testImplementation "junit:junit:$junitVersion"
|
||||
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
||||
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
||||
implementation project(':capacitor-cordova-android-plugins')
|
||||
}
|
||||
|
||||
try {
|
||||
def servicesJSON = file('google-services.json')
|
||||
if (servicesJSON.text) {
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
|
||||
}
|
||||
36
android/app/capacitor.build.gradle
Normal file
@@ -0,0 +1,36 @@
|
||||
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
|
||||
|
||||
android {
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_21
|
||||
targetCompatibility JavaVersion.VERSION_21
|
||||
}
|
||||
}
|
||||
|
||||
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
|
||||
dependencies {
|
||||
implementation project(':aparajita-capacitor-secure-storage')
|
||||
implementation project(':capacitor-community-safe-area')
|
||||
implementation project(':capacitor-action-sheet')
|
||||
implementation project(':capacitor-app')
|
||||
implementation project(':capacitor-camera')
|
||||
implementation project(':capacitor-clipboard')
|
||||
implementation project(':capacitor-device')
|
||||
implementation project(':capacitor-dialog')
|
||||
implementation project(':capacitor-filesystem')
|
||||
implementation project(':capacitor-haptics')
|
||||
implementation project(':capacitor-keyboard')
|
||||
implementation project(':capacitor-network')
|
||||
implementation project(':capacitor-share')
|
||||
implementation project(':capacitor-splash-screen')
|
||||
implementation project(':capacitor-status-bar')
|
||||
implementation project(':capgo-capacitor-navigation-bar')
|
||||
implementation project(':send-intent')
|
||||
implementation project(':jcesarmobile-ssl-skip')
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (hasProperty('postBuildExtras')) {
|
||||
postBuildExtras()
|
||||
}
|
||||
21
android/app/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
69
android/app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<!-- Permissions -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
tools:targetApi="tiramisu"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name="com.logseq.app.MainActivity"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode|navigation|density"
|
||||
android:exported="true"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:label="@string/title_activity_main"
|
||||
android:launchMode="singleTask"
|
||||
android:theme="@style/AppTheme.NoActionBarLaunch">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEND" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
<data android:mimeType="text/plain" />
|
||||
<data android:mimeType="image/*" />
|
||||
<data android:mimeType="application/*" />
|
||||
<data android:mimeType="video/*" />
|
||||
</intent-filter>
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
|
||||
<data android:scheme="logseq" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
</application>
|
||||
</manifest>
|
||||
74
android/app/src/main/assets/capacitor.plugins.json
Normal file
@@ -0,0 +1,74 @@
|
||||
[
|
||||
{
|
||||
"pkg": "@aparajita/capacitor-secure-storage",
|
||||
"classpath": "com.aparajita.capacitor.securestorage.SecureStorage"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor-community/safe-area",
|
||||
"classpath": "com.getcapacitor.community.safearea.SafeAreaPlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor/action-sheet",
|
||||
"classpath": "com.capacitorjs.plugins.actionsheet.ActionSheetPlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor/app",
|
||||
"classpath": "com.capacitorjs.plugins.app.AppPlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor/camera",
|
||||
"classpath": "com.capacitorjs.plugins.camera.CameraPlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor/clipboard",
|
||||
"classpath": "com.capacitorjs.plugins.clipboard.ClipboardPlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor/device",
|
||||
"classpath": "com.capacitorjs.plugins.device.DevicePlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor/dialog",
|
||||
"classpath": "com.capacitorjs.plugins.dialog.DialogPlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor/filesystem",
|
||||
"classpath": "com.capacitorjs.plugins.filesystem.FilesystemPlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor/haptics",
|
||||
"classpath": "com.capacitorjs.plugins.haptics.HapticsPlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor/keyboard",
|
||||
"classpath": "com.capacitorjs.plugins.keyboard.KeyboardPlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor/network",
|
||||
"classpath": "com.capacitorjs.plugins.network.NetworkPlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor/share",
|
||||
"classpath": "com.capacitorjs.plugins.share.SharePlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor/splash-screen",
|
||||
"classpath": "com.capacitorjs.plugins.splashscreen.SplashScreenPlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capacitor/status-bar",
|
||||
"classpath": "com.capacitorjs.plugins.statusbar.StatusBarPlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "@capgo/capacitor-navigation-bar",
|
||||
"classpath": "ee.forgr.capacitor_navigation_bar.CapgoNavigationBarPlugin"
|
||||
},
|
||||
{
|
||||
"pkg": "send-intent",
|
||||
"classpath": "de.mindlib.sendIntent.SendIntent"
|
||||
},
|
||||
{
|
||||
"pkg": "@jcesarmobile/ssl-skip",
|
||||
"classpath": "com.jcesarmobile.sslskip.SslSkipPlugin"
|
||||
}
|
||||
]
|
||||
375
android/app/src/main/java/com/logseq/app/ComposeHost.kt
Normal file
@@ -0,0 +1,375 @@
|
||||
package com.logseq.app
|
||||
|
||||
import android.graphics.Color
|
||||
import android.app.Activity
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.WebView
|
||||
import android.widget.FrameLayout
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.animation.EnterTransition
|
||||
import androidx.compose.animation.ExitTransition
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.slideInHorizontally
|
||||
import androidx.compose.animation.slideOutHorizontally
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.asPaddingValues
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.systemBars
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.navArgument
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.SharedFlow
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
private const val ROOT_ROUTE = "web/{encodedPath}"
|
||||
private const val DEBUG_NAV_STACK_PREFIX = "[DEBUG-navstack]"
|
||||
|
||||
/**
|
||||
* Hosts the existing WebView inside Compose and drives Compose Navigation
|
||||
* so we get back gestures/animations while delegating actual routing to the JS layer.
|
||||
*/
|
||||
object ComposeHost {
|
||||
private val navEvents = MutableSharedFlow<NavigationRenderState>(extraBufferCapacity = 64)
|
||||
val navigationEvents: SharedFlow<NavigationRenderState> = navEvents
|
||||
|
||||
@JvmStatic
|
||||
fun applyNavigation(state: NavigationRenderState) {
|
||||
Log.d(
|
||||
"NavStack",
|
||||
"$DEBUG_NAV_STACK_PREFIX compose.applyNavigation stack=${state.activeStackId} previous=${state.previousStackId} " +
|
||||
"type=${state.navigationType} path=${state.path} paths=${state.paths} switched=${state.stackSwitched}"
|
||||
)
|
||||
if (!navEvents.tryEmit(state)) {
|
||||
Log.w(
|
||||
"ComposeHost",
|
||||
"Dropped navigation state: stack=${state.activeStackId} type=${state.navigationType} path=${state.path}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun renderWithSystemInsets(
|
||||
activity: Activity,
|
||||
webView: WebView
|
||||
) {
|
||||
WebViewSnapshotManager.registerWindow(activity.window)
|
||||
val root = activity.findViewById<FrameLayout>(android.R.id.content)
|
||||
|
||||
// WebView already created by BridgeActivity; just reparent it into Compose.
|
||||
(webView.parent as? ViewGroup)?.removeView(webView)
|
||||
|
||||
val composeView = ComposeView(activity).apply {
|
||||
tag = "compose-host-webview"
|
||||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
||||
setContent {
|
||||
ComposeNavigationHost(
|
||||
webView = webView
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (root.findViewWithTag<ComposeView>("compose-host-webview") == null) {
|
||||
root.addView(
|
||||
composeView,
|
||||
FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun encodePath(path: String): String =
|
||||
Uri.encode(if (path.isBlank()) "/" else path)
|
||||
|
||||
private fun routeFor(path: String): String =
|
||||
"web/${encodePath(path)}"
|
||||
|
||||
private fun decodePath(encodedPath: String?): String =
|
||||
Uri.decode(encodedPath?.takeIf { it.isNotBlank() } ?: encodePath("/"))
|
||||
|
||||
private fun NavHostController.currentPath(): String? =
|
||||
currentBackStackEntry?.arguments?.getString("encodedPath")?.let(::decodePath)
|
||||
|
||||
private fun NavHostController.rebuildBackStack(paths: List<String>) {
|
||||
val normalizedPaths = paths.ifEmpty { listOf("/") }
|
||||
val rootRoute = routeFor(normalizedPaths.first())
|
||||
navigate(rootRoute) {
|
||||
popUpTo(ROOT_ROUTE) {
|
||||
inclusive = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
}
|
||||
normalizedPaths.drop(1).forEach { path ->
|
||||
navigate(routeFor(path)) {
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun shouldAnimateNavigation(navigationType: String): Boolean =
|
||||
when (navigationType.trim().lowercase()) {
|
||||
"push",
|
||||
"pop",
|
||||
"back",
|
||||
"forward",
|
||||
"replace" -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalAnimationApi::class)
|
||||
@Composable
|
||||
private fun ComposeNavigationHost(
|
||||
webView: WebView
|
||||
) {
|
||||
val navController = rememberNavController()
|
||||
|
||||
DisposableEffect(navController) {
|
||||
navController.enableOnBackPressed(false)
|
||||
Log.d("NavStack", "$DEBUG_NAV_STACK_PREFIX compose.navController.backHandling disabled")
|
||||
onDispose {
|
||||
navController.enableOnBackPressed(true)
|
||||
}
|
||||
}
|
||||
|
||||
// Track the last navigation type so we can change slide direction.
|
||||
val lastNavTypeState = remember { mutableStateOf("push") }
|
||||
|
||||
HandleNavigationEvents(
|
||||
navController = navController,
|
||||
webView = webView
|
||||
) { type ->
|
||||
lastNavTypeState.value = type
|
||||
}
|
||||
|
||||
// You can comment this out if you want to rely purely on JS for back.
|
||||
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = ROOT_ROUTE,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(WindowInsets.systemBars.asPaddingValues())
|
||||
) {
|
||||
composable(
|
||||
route = ROOT_ROUTE,
|
||||
arguments = listOf(
|
||||
navArgument("encodedPath") {
|
||||
defaultValue = encodePath("/")
|
||||
}
|
||||
),
|
||||
// ---- PUSH: A -> B ----
|
||||
enterTransition = {
|
||||
val navType = lastNavTypeState.value
|
||||
if (!shouldAnimateNavigation(navType)) {
|
||||
EnterTransition.None
|
||||
} else if (navType == "pop") {
|
||||
slideInHorizontally(
|
||||
initialOffsetX = { fullWidth -> -fullWidth / 3 },
|
||||
animationSpec = tween(220)
|
||||
) + fadeIn(animationSpec = tween(180))
|
||||
} else {
|
||||
slideInHorizontally(
|
||||
initialOffsetX = { fullWidth -> fullWidth },
|
||||
animationSpec = tween(220)
|
||||
) + fadeIn(animationSpec = tween(180))
|
||||
}
|
||||
},
|
||||
exitTransition = {
|
||||
val navType = lastNavTypeState.value
|
||||
if (!shouldAnimateNavigation(navType)) {
|
||||
ExitTransition.None
|
||||
} else if (navType == "pop") {
|
||||
slideOutHorizontally(
|
||||
targetOffsetX = { fullWidth -> fullWidth },
|
||||
animationSpec = tween(200)
|
||||
) + fadeOut(animationSpec = tween(160))
|
||||
} else {
|
||||
slideOutHorizontally(
|
||||
targetOffsetX = { fullWidth -> -fullWidth / 4 },
|
||||
animationSpec = tween(220)
|
||||
) + fadeOut(animationSpec = tween(180))
|
||||
}
|
||||
},
|
||||
// ---- POP: B -> A ----
|
||||
popEnterTransition = {
|
||||
if (!shouldAnimateNavigation(lastNavTypeState.value)) {
|
||||
EnterTransition.None
|
||||
} else {
|
||||
slideInHorizontally(
|
||||
initialOffsetX = { fullWidth -> -fullWidth / 4 },
|
||||
animationSpec = tween(200)
|
||||
) + fadeIn(animationSpec = tween(160))
|
||||
}
|
||||
},
|
||||
popExitTransition = {
|
||||
if (!shouldAnimateNavigation(lastNavTypeState.value)) {
|
||||
ExitTransition.None
|
||||
} else {
|
||||
slideOutHorizontally(
|
||||
targetOffsetX = { fullWidth -> fullWidth },
|
||||
animationSpec = tween(200)
|
||||
) + fadeOut(animationSpec = tween(160))
|
||||
}
|
||||
}
|
||||
) {
|
||||
AndroidView(
|
||||
factory = { context ->
|
||||
FrameLayout(context).apply {
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
|
||||
val webContainer = FrameLayout(context).apply {
|
||||
id = R.id.webview_container
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
}
|
||||
|
||||
val overlayContainer = FrameLayout(context).apply {
|
||||
id = R.id.webview_overlay_container
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
isClickable = false
|
||||
isFocusable = false
|
||||
}
|
||||
|
||||
overlayContainer.setBackgroundColor(Color.TRANSPARENT)
|
||||
overlayContainer.alpha = 1f
|
||||
overlayContainer.visibility = android.view.View.GONE
|
||||
|
||||
addView(webContainer)
|
||||
addView(overlayContainer)
|
||||
|
||||
WebViewSnapshotManager.registerOverlay(overlayContainer)
|
||||
|
||||
(webView.parent as? ViewGroup)?.removeView(webView)
|
||||
webContainer.addView(
|
||||
webView,
|
||||
FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
)
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
update = { root ->
|
||||
val webContainer =
|
||||
root.findViewById<FrameLayout>(R.id.webview_container)
|
||||
val overlayContainer =
|
||||
root.findViewById<FrameLayout>(R.id.webview_overlay_container)
|
||||
WebViewSnapshotManager.registerOverlay(overlayContainer)
|
||||
if (webView.parent !== webContainer) {
|
||||
(webView.parent as? ViewGroup)?.removeView(webView)
|
||||
webContainer.addView(
|
||||
webView,
|
||||
FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun HandleNavigationEvents(
|
||||
navController: NavHostController,
|
||||
webView: WebView,
|
||||
onNavType: (String) -> Unit
|
||||
) {
|
||||
LaunchedEffect(navController) {
|
||||
var snapshotVersion = 0
|
||||
ComposeHost.navigationEvents.collect { state ->
|
||||
snapshotVersion += 1
|
||||
val currentSnapshotVersion = snapshotVersion
|
||||
val paths = state.paths.ifEmpty { listOf(state.path) }
|
||||
val targetPath = paths.lastOrNull() ?: state.path
|
||||
val route = routeFor(targetPath)
|
||||
val animateNavigation = shouldAnimateNavigation(state.navigationType) && !state.stackSwitched
|
||||
Log.d(
|
||||
"NavStack",
|
||||
"$DEBUG_NAV_STACK_PREFIX compose.event.before stack=${state.activeStackId} previous=${state.previousStackId} " +
|
||||
"type=${state.navigationType} path=$targetPath paths=$paths switched=${state.stackSwitched} targetRoute=$route " +
|
||||
"currentRoute=${navController.currentBackStackEntry?.destination?.route} " +
|
||||
"currentArgs=${navController.currentBackStackEntry?.arguments} " +
|
||||
"previousRoute=${navController.previousBackStackEntry?.destination?.route}"
|
||||
)
|
||||
if (animateNavigation) {
|
||||
WebViewSnapshotManager.showSnapshot("navigation", webView)
|
||||
} else {
|
||||
WebViewSnapshotManager.clearSnapshot("navigation")
|
||||
}
|
||||
onNavType(state.navigationType)
|
||||
when {
|
||||
state.stackSwitched || state.navigationType == "reset" -> {
|
||||
navController.rebuildBackStack(paths)
|
||||
}
|
||||
|
||||
state.navigationType == "push" -> {
|
||||
if (navController.currentPath() != targetPath) {
|
||||
navController.navigate(route)
|
||||
}
|
||||
}
|
||||
|
||||
state.navigationType == "replace" -> {
|
||||
navController.popBackStack()
|
||||
navController.navigate(route) {
|
||||
launchSingleTop = true
|
||||
}
|
||||
}
|
||||
|
||||
state.navigationType == "pop" -> {
|
||||
if (!navController.popBackStack(route, inclusive = false)) {
|
||||
navController.rebuildBackStack(paths)
|
||||
}
|
||||
}
|
||||
|
||||
else -> navController.navigate(route)
|
||||
}
|
||||
Log.d(
|
||||
"NavStack",
|
||||
"$DEBUG_NAV_STACK_PREFIX compose.event.after stack=${state.activeStackId} type=${state.navigationType} path=$targetPath targetRoute=$route " +
|
||||
"currentRoute=${navController.currentBackStackEntry?.destination?.route} " +
|
||||
"currentArgs=${navController.currentBackStackEntry?.arguments} " +
|
||||
"previousRoute=${navController.previousBackStackEntry?.destination?.route}"
|
||||
)
|
||||
|
||||
if (animateNavigation) {
|
||||
launch {
|
||||
delay(260)
|
||||
if (currentSnapshotVersion == snapshotVersion) {
|
||||
WebViewSnapshotManager.clearSnapshot("navigation")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
214
android/app/src/main/java/com/logseq/app/FileUtil.java
Normal file
@@ -0,0 +1,214 @@
|
||||
package com.logseq.app;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
// The following refs
|
||||
// https://stackoverflow.com/questions/29713587/how-to-get-the-real-path-with-action-open-document-tree-intent
|
||||
// https://gist.github.com/asifmujteba/d89ba9074bc941de1eaa#file-asfurihelper
|
||||
// with bug fixes and patches.
|
||||
public class FileUtil {
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
public static String getPath(final Context context, final Uri uri) {
|
||||
|
||||
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||
|
||||
// DocumentProvider
|
||||
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
|
||||
// ExternalStorageProvider
|
||||
if (isExternalStorageDocument(uri)) {
|
||||
final String docId = DocumentsContract.getDocumentId(uri);
|
||||
final String[] split = docId.split(":");
|
||||
final String type = split[0];
|
||||
// NOTE: It's not a good idea to use storage root as Graph root.
|
||||
String remain = "";
|
||||
if (split.length == 2) {
|
||||
remain = split[1];
|
||||
}
|
||||
|
||||
if ("primary".equalsIgnoreCase(type)) {
|
||||
return Environment.getExternalStorageDirectory() + "/" + remain;
|
||||
} else if ("home".equalsIgnoreCase(type)) {
|
||||
return Environment.getExternalStorageDirectory() + "/Documents/" + remain;
|
||||
} else if ("downloads".equalsIgnoreCase(type)) {
|
||||
return Environment.getExternalStorageDirectory() + "/Download/" + remain; // No 's' here
|
||||
}
|
||||
|
||||
File dir = null;
|
||||
File[] mdirs = context.getExternalMediaDirs();
|
||||
for (File mdir : mdirs) {
|
||||
String extPath = mdir.getAbsolutePath();
|
||||
|
||||
if (extPath.contains("/" + type + "/")) {
|
||||
dir = new File(extPath.substring(0, extPath.indexOf("/Android")) + "/" + remain);
|
||||
if (dir.exists()) {
|
||||
return dir.getAbsolutePath();
|
||||
}
|
||||
}
|
||||
}
|
||||
// FIXME: The following attempt cannot handle same directory name on different devices!
|
||||
// attempt 1
|
||||
dir = new File("/storage/" + type + "/" + remain);
|
||||
if (dir.exists()) {
|
||||
return dir.getAbsolutePath();
|
||||
}
|
||||
// attempt 3
|
||||
dir = new File("/mnt/media_rw/" + type + "/" + remain);
|
||||
if (dir.exists()) {
|
||||
return dir.getAbsolutePath();
|
||||
}
|
||||
// attempt 3
|
||||
dir = new File("/mnt/" + type + "/" + remain);
|
||||
if (dir.exists()) {
|
||||
return dir.getAbsolutePath();
|
||||
}
|
||||
|
||||
// TODO: other cases
|
||||
} else if (isDownloadsDocument(uri)) {
|
||||
final String id = DocumentsContract.getDocumentId(uri);
|
||||
if (!TextUtils.isEmpty(id)) {
|
||||
if (id.startsWith("raw:")) {
|
||||
return id.replaceFirst("raw:", "");
|
||||
}
|
||||
try {
|
||||
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
||||
return getDataColumn(context, contentUri, null, null);
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} else if (isMediaDocument(uri)) {
|
||||
final String docId = DocumentsContract.getDocumentId(uri);
|
||||
final String[] split = docId.split(":");
|
||||
final String type = split[0];
|
||||
|
||||
Uri contentUri = null;
|
||||
if ("image".equals(type)) {
|
||||
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||
} else if ("video".equals(type)) {
|
||||
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
||||
} else if ("audio".equals(type)) {
|
||||
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
||||
}
|
||||
|
||||
final String selection = "_id=?";
|
||||
final String[] selectionArgs = new String[]{
|
||||
split[1]
|
||||
};
|
||||
|
||||
return getDataColumn(context, contentUri, selection, selectionArgs);
|
||||
} else if (isTermuxDocument(uri)) {
|
||||
String docId = DocumentsContract.getDocumentId(uri);
|
||||
|
||||
// Ref: https://github.com/termux/termux-app/blob/master/app/src/main/java/com/termux/app/TermuxInstaller.java
|
||||
if (docId.startsWith("/")) {
|
||||
if (docId.contains("/com.termux/files/home/storage/")) {
|
||||
String remain = docId.replaceFirst("^.*?com\\.termux/files/home/storage/[^/]+/", "");
|
||||
if (docId.contains("/storage/external-1")) { // TODO: Support external-2 or more
|
||||
File[] dirs = context.getExternalFilesDirs(remain);
|
||||
if (dirs != null && dirs.length >= 2) {
|
||||
docId = dirs[1].getAbsolutePath();
|
||||
}
|
||||
} else if (docId.contains("/storage/media-1")) {
|
||||
File[] dirs = context.getExternalMediaDirs();
|
||||
if (dirs != null && dirs.length >= 2) {
|
||||
docId = dirs[1].getAbsolutePath() + "/" + remain;
|
||||
}
|
||||
} else if (docId.contains("/storage/downloads")) {
|
||||
docId = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + remain;
|
||||
} else if (docId.contains("/storage/shared")) {
|
||||
docId = Environment.getExternalStorageDirectory() + "/" + remain;
|
||||
}
|
||||
}
|
||||
File dir = new File(docId);
|
||||
if (dir.exists()) {
|
||||
return dir.getAbsolutePath();
|
||||
}
|
||||
Log.e("Logseq/FileUtil", "Handle termux content url failed: " + docId);
|
||||
}
|
||||
// FIXME: Are there any other cases?
|
||||
}
|
||||
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
||||
// Return the remote address
|
||||
if (isGooglePhotosUri(uri))
|
||||
return uri.getLastPathSegment();
|
||||
|
||||
return getDataColumn(context, uri, null, null);
|
||||
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
||||
return uri.getPath();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getDataColumn(Context context, Uri uri, String selection,
|
||||
String[] selectionArgs) {
|
||||
|
||||
Cursor cursor = null;
|
||||
final String column = "_data";
|
||||
final String[] projection = {
|
||||
column
|
||||
};
|
||||
|
||||
try {
|
||||
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
|
||||
null);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
final int index = cursor.getColumnIndexOrThrow(column);
|
||||
return cursor.getString(index);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param uri The Uri to check.
|
||||
* @return Whether the Uri authority is ExternalStorageProvider.
|
||||
*/
|
||||
public static boolean isExternalStorageDocument(Uri uri) {
|
||||
return "com.android.externalstorage.documents".equals(uri.getAuthority());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri The Uri to check.
|
||||
* @return Whether the Uri authority is DownloadsProvider.
|
||||
*/
|
||||
public static boolean isDownloadsDocument(Uri uri) {
|
||||
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri The Uri to check.
|
||||
* @return Whether the Uri authority is MediaProvider.
|
||||
*/
|
||||
public static boolean isMediaDocument(Uri uri) {
|
||||
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri The Uri to check.
|
||||
* @return Whether the Uri authority is Google Photos.
|
||||
*/
|
||||
public static boolean isGooglePhotosUri(Uri uri) {
|
||||
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
|
||||
}
|
||||
|
||||
public static boolean isTermuxDocument(Uri uri) {
|
||||
return "com.termux.documents".equals(uri.getAuthority());
|
||||
}
|
||||
}
|
||||
91
android/app/src/main/java/com/logseq/app/FolderPicker.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package com.logseq.app;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.os.Build;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.activity.result.ActivityResult;
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.documentfile.provider.DocumentFile;
|
||||
|
||||
import com.getcapacitor.JSObject;
|
||||
import com.getcapacitor.Plugin;
|
||||
import com.getcapacitor.annotation.ActivityCallback;
|
||||
import com.getcapacitor.annotation.CapacitorPlugin;
|
||||
import com.getcapacitor.PluginCall;
|
||||
import com.getcapacitor.PluginMethod;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
||||
@CapacitorPlugin(name = "FolderPicker")
|
||||
public class FolderPicker extends Plugin {
|
||||
public static boolean FileAccessAllowed()
|
||||
{
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
||||
return true;
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
return (Environment.isExternalStorageManager());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@PluginMethod()
|
||||
public void pickFolder(PluginCall call) {
|
||||
if (FileAccessAllowed()) {
|
||||
Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||
i.addCategory(Intent.CATEGORY_DEFAULT);
|
||||
startActivityForResult(call, i, "folderPickerResult");
|
||||
} else {
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION);
|
||||
Uri uri = Uri.fromParts("package", this.getContext().getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
startActivityForResult(call, intent, 20);
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod()
|
||||
public void openFile(PluginCall call) {
|
||||
Uri uri = Uri.parse(call.getString("uri"));
|
||||
File file = new File(uri.getPath());
|
||||
|
||||
// Get URI and MIME type of file
|
||||
String appId = getAppId();
|
||||
uri = FileProvider.getUriForFile(getActivity(), appId + ".fileprovider", file);
|
||||
String mime = getContext().getContentResolver().getType(uri);
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(uri, mime);
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
getContext().startActivity(intent);
|
||||
}
|
||||
|
||||
@ActivityCallback
|
||||
private void folderPickerResult(PluginCall call, ActivityResult result) {
|
||||
if (call == null) {
|
||||
return;
|
||||
}
|
||||
JSObject ret = new JSObject();
|
||||
Context context = this.getContext();
|
||||
Uri treeUri = result.getData().getData();
|
||||
Uri docUri = DocumentsContract.buildDocumentUriUsingTree(treeUri,
|
||||
DocumentsContract.getTreeDocumentId(treeUri));
|
||||
Log.i("Logseq/FolderPicker", "Got uri " + docUri);
|
||||
String path = FileUtil.getPath(context, docUri);
|
||||
Log.i("Logseq/FolderPicker", "Convert to path " + FileUtil.getPath(context, docUri));
|
||||
if (path == null || path.isEmpty()) {
|
||||
call.reject("Cannot support this directory type: " + docUri);
|
||||
} else {
|
||||
Uri folderUri = Uri.fromFile(new File(path));
|
||||
ret.put("path", folderUri.toString());
|
||||
call.resolve(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
307
android/app/src/main/java/com/logseq/app/FsWatcher.java
Normal file
@@ -0,0 +1,307 @@
|
||||
package com.logseq.app;
|
||||
|
||||
import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
import android.system.StructStat;
|
||||
import android.util.Log;
|
||||
import android.os.FileObserver;
|
||||
|
||||
import android.net.Uri;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.text.Normalizer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.getcapacitor.JSObject;
|
||||
import com.getcapacitor.Plugin;
|
||||
import com.getcapacitor.annotation.CapacitorPlugin;
|
||||
import com.getcapacitor.PluginMethod;
|
||||
import com.getcapacitor.PluginCall;
|
||||
|
||||
@CapacitorPlugin(name = "FsWatcher")
|
||||
public class FsWatcher extends Plugin {
|
||||
private String mPath;
|
||||
private PollingFsWatcher mWatcher;
|
||||
private Thread mThread;
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
Log.i("FsWatcher", "Android fs-watcher loaded!");
|
||||
}
|
||||
|
||||
@PluginMethod()
|
||||
public void watch(PluginCall call) {
|
||||
String pathParam = call.getString("path");
|
||||
// check file:// or no scheme uris
|
||||
Uri u = Uri.parse(pathParam);
|
||||
Log.i("FsWatcher", "watching " + u);
|
||||
// TODO: handle context:// uri
|
||||
if (u.getScheme() == null || u.getScheme().equals("file")) {
|
||||
File pathObj;
|
||||
try {
|
||||
pathObj = new File(u.getPath());
|
||||
} catch (Exception e) {
|
||||
call.reject("invalid watch path: " + pathParam);
|
||||
return;
|
||||
}
|
||||
|
||||
mPath = pathObj.getAbsolutePath();
|
||||
|
||||
if (mWatcher != null) {
|
||||
call.reject("already watching");
|
||||
return;
|
||||
}
|
||||
|
||||
mWatcher = new PollingFsWatcher(mPath);
|
||||
mThread = new Thread(mWatcher);
|
||||
mThread.start();
|
||||
|
||||
call.resolve();
|
||||
} else {
|
||||
call.reject(u.getScheme() + " scheme not supported");
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod()
|
||||
public void unwatch(PluginCall call) {
|
||||
Log.i("FsWatcher", "unwatch all...");
|
||||
|
||||
if (mWatcher != null) {
|
||||
mThread.interrupt();
|
||||
mWatcher = null;
|
||||
}
|
||||
|
||||
call.resolve();
|
||||
}
|
||||
|
||||
// add, change, unlink events
|
||||
public void onObserverEvent(int event, String path, SimpleFileMetadata metadata) {
|
||||
JSObject obj = new JSObject();
|
||||
String content = null;
|
||||
File f = new File(path);
|
||||
|
||||
boolean shouldRead = false;
|
||||
if (Pattern.matches("(?i)[^.].*?\\.(md|org|css|edn|js|markdown|excalidraw)$", f.getName())) {
|
||||
shouldRead = true;
|
||||
}
|
||||
|
||||
Uri dir = Uri.fromFile(new File(mPath));
|
||||
Uri fpath = Uri.fromFile(f);
|
||||
String relpath = null;
|
||||
|
||||
if (fpath.getPath().startsWith(dir.getPath())) {
|
||||
relpath = fpath.getPath().substring(dir.getPath().length());
|
||||
if (relpath.startsWith("/")) {
|
||||
relpath = relpath.substring(1);
|
||||
}
|
||||
} else {
|
||||
Log.e("FsWatcher", "file path not under watch path");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
obj.put("path", Normalizer.normalize(relpath, Normalizer.Form.NFC));
|
||||
obj.put("dir", Uri.fromFile(new File(mPath))); // Uri is for Android. URI is for RFC compatible
|
||||
JSObject stat;
|
||||
|
||||
switch (event) {
|
||||
case FileObserver.MODIFY:
|
||||
obj.put("event", "change");
|
||||
stat = new JSObject();
|
||||
stat.put("mtime", metadata.mtime);
|
||||
stat.put("ctime", metadata.ctime);
|
||||
stat.put("size", metadata.size);
|
||||
obj.put("stat", stat);
|
||||
if (shouldRead) {
|
||||
try {
|
||||
content = getFileContents(f);
|
||||
} catch (IOException e) {
|
||||
Log.e("FsWatcher", "error reading modified file");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Log.i("FsWatcher", "prepare event " + obj);
|
||||
obj.put("content", content);
|
||||
break;
|
||||
case FileObserver.CREATE:
|
||||
obj.put("event", "add");
|
||||
stat = new JSObject();
|
||||
stat.put("mtime", metadata.mtime);
|
||||
stat.put("ctime", metadata.ctime);
|
||||
stat.put("size", metadata.size);
|
||||
obj.put("stat", stat);
|
||||
if (shouldRead) {
|
||||
try {
|
||||
content = getFileContents(f);
|
||||
} catch (IOException e) {
|
||||
Log.e("FsWatcher", "error reading new file");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
obj.put("content", content);
|
||||
break;
|
||||
case FileObserver.DELETE:
|
||||
if (f.exists()) {
|
||||
Log.i("FsWatcher", "abandon delete notification due to file exists");
|
||||
return;
|
||||
} else {
|
||||
obj.put("event", "unlink");
|
||||
}
|
||||
Log.i("FsWatcher", "prepare event " + obj);
|
||||
break;
|
||||
default:
|
||||
// unreachable?
|
||||
obj.put("event", "unknown");
|
||||
break;
|
||||
}
|
||||
|
||||
notifyListeners("watcher", obj);
|
||||
}
|
||||
|
||||
public static String getFileContents(final File file) throws IOException {
|
||||
InputStream inputStream = new FileInputStream(file);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
|
||||
while ((length = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
inputStream.close();
|
||||
return outputStream.toString("utf-8");
|
||||
}
|
||||
|
||||
public class SimpleFileMetadata {
|
||||
public long mtime;
|
||||
public long ctime;
|
||||
public long size;
|
||||
public long ino;
|
||||
|
||||
public SimpleFileMetadata(File file) throws ErrnoException {
|
||||
StructStat stat = Os.stat(file.getPath());
|
||||
mtime = stat.st_mtime;
|
||||
ctime = stat.st_ctime;
|
||||
size = stat.st_size;
|
||||
ino = stat.st_ino;
|
||||
}
|
||||
|
||||
public boolean equals(SimpleFileMetadata other) {
|
||||
return mtime == other.mtime && ctime == other.ctime && size == other.size && ino == other.ino;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class PollingFsWatcher implements Runnable {
|
||||
private String mPath;
|
||||
private Map<String, SimpleFileMetadata> metaDb;
|
||||
|
||||
public PollingFsWatcher(String path) {
|
||||
metaDb = new HashMap();
|
||||
|
||||
File dir = new File(path);
|
||||
try {
|
||||
mPath = dir.getCanonicalPath();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
this.tick(false); // skip initial notification
|
||||
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
this.tick(true);
|
||||
Thread.sleep(2000); // The same as iOS fswatcher, 2s interval
|
||||
} catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
Log.i("FsWatcher", "interrupted, unwatch");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void tick(boolean shouldNotify) {
|
||||
Map<String, SimpleFileMetadata> newMetaDb = new HashMap();
|
||||
|
||||
Stack<String> paths = new Stack();
|
||||
paths.push(mPath);
|
||||
while (!paths.isEmpty()) {
|
||||
String dir = paths.pop();
|
||||
File curr = new File(dir);
|
||||
|
||||
File[] files = curr.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
String filename = file.getName();
|
||||
if (file.isDirectory()) {
|
||||
if (!filename.startsWith(".") && !filename.equals("bak") && !filename.equals("version-files") && !filename.equals("node_modules")) {
|
||||
paths.push(file.getAbsolutePath());
|
||||
}
|
||||
} else if (file.isFile() && !filename.equals("graphs-txid.edn") && !filename.equals("broken-config.edn")) {
|
||||
try {
|
||||
SimpleFileMetadata metadata = new SimpleFileMetadata(file);
|
||||
newMetaDb.put(file.getAbsolutePath(), metadata);
|
||||
} catch (ErrnoException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldNotify) {
|
||||
this.updateMetaDb(newMetaDb);
|
||||
} else {
|
||||
this.metaDb = newMetaDb;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMetaDb(Map<String, SimpleFileMetadata> newMetaDb) {
|
||||
for (Map.Entry<String, SimpleFileMetadata> entry : newMetaDb.entrySet()) {
|
||||
String path = entry.getKey();
|
||||
SimpleFileMetadata newMeta = entry.getValue();
|
||||
SimpleFileMetadata oldMeta = metaDb.remove(path);
|
||||
if (oldMeta == null) {
|
||||
// new file
|
||||
onObserverEvent(FileObserver.CREATE, path, newMeta);
|
||||
Log.d("FsWatcher", "create " + path);
|
||||
} else if (!oldMeta.equals(newMeta)) {
|
||||
// file changed
|
||||
onObserverEvent(FileObserver.MODIFY, path, newMeta);
|
||||
Log.d("FsWatcher", "changed " + path);
|
||||
}
|
||||
}
|
||||
for (String path : metaDb.keySet()) {
|
||||
// file deleted
|
||||
Thread timer = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// delay 500ms then send, enough for most syncing net disks
|
||||
Thread.sleep(500);
|
||||
onObserverEvent(FileObserver.DELETE, path, null);
|
||||
Log.d("FsWatcher", "deleted " + path);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
timer.start();
|
||||
}
|
||||
|
||||
this.metaDb = newMetaDb;
|
||||
}
|
||||
}
|
||||
}
|
||||
663
android/app/src/main/java/com/logseq/app/LiquidTabsPlugin.kt
Normal file
@@ -0,0 +1,663 @@
|
||||
package com.logseq.app
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.graphics.Color
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.view.Gravity
|
||||
import android.view.KeyEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowInsets
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import android.widget.EditText
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageButton
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.ScrollView
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.content.res.AppCompatResources
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Circle
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.NavigationBar
|
||||
import androidx.compose.material3.NavigationBarItem
|
||||
import androidx.compose.material3.NavigationBarItemDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.ui.graphics.Color as ComposeColor
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp // New Import for DP units
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.doOnNextLayout
|
||||
import com.getcapacitor.JSArray
|
||||
import com.getcapacitor.JSObject
|
||||
import com.getcapacitor.Plugin
|
||||
import com.getcapacitor.PluginCall
|
||||
import com.getcapacitor.PluginMethod
|
||||
import com.getcapacitor.annotation.CapacitorPlugin
|
||||
|
||||
// NOTE: NativeUiUtils and MaterialIconResolver are assumed to be defined elsewhere in your project
|
||||
// and are necessary for this code to compile.
|
||||
|
||||
@CapacitorPlugin(name = "LiquidTabsPlugin")
|
||||
class LiquidTabsPlugin : Plugin() {
|
||||
private var bottomNav: ComposeView? = null
|
||||
private var searchContainer: LinearLayout? = null
|
||||
private var searchInput: EditText? = null
|
||||
private var resultsContainer: LinearLayout? = null
|
||||
private var closeButton: ImageButton? = null
|
||||
private var originalBottomPadding: Int? = null
|
||||
|
||||
private var tabsState by mutableStateOf<List<TabSpec>>(emptyList())
|
||||
private var currentTabId by mutableStateOf<String?>(null)
|
||||
|
||||
// Define a standard horizontal padding for consistency
|
||||
private val HORIZONTAL_PADDING_DP = 16f
|
||||
private val VERTICAL_PADDING_DP = 12f
|
||||
private val RESULT_ROW_VERTICAL_PADDING_DP = 10f
|
||||
|
||||
// 💡 NEW: Define padding for the Tab Bar edges (makes it compact and adds left/right space)
|
||||
private val TAB_BAR_HORIZONTAL_PADDING = 12.dp
|
||||
private val ACCENT_COLOR_HEX = "#6097c7"
|
||||
|
||||
private fun tabIconResId(tabId: String): Int? = when (tabId) {
|
||||
"flashcards" -> R.drawable.ic_tab_flashcards
|
||||
else -> null
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun configureTabs(call: PluginCall) {
|
||||
val activity = activity ?: run {
|
||||
call.reject("No activity")
|
||||
return
|
||||
}
|
||||
val tabs = parseTabs(call.getArray("tabs"))
|
||||
|
||||
activity.runOnUiThread {
|
||||
tabsState = tabs
|
||||
val activeId = currentTabId?.takeIf { id -> tabs.any { it.id == id } }
|
||||
?: tabs.firstOrNull()?.id
|
||||
currentTabId = activeId
|
||||
ensureNav()
|
||||
currentTabId?.let { id ->
|
||||
tabsState.find { it.id == id }?.let { tab ->
|
||||
handleSelection(tab, reselected = false, notify = false)
|
||||
}
|
||||
} ?: hideSearchUi()
|
||||
adjustWebViewPadding()
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun selectTab(call: PluginCall) {
|
||||
val id = call.getString("id") ?: run {
|
||||
call.reject("Missing id")
|
||||
return
|
||||
}
|
||||
val tab = tabsState.find { it.id == id }
|
||||
if (tab == null) {
|
||||
call.resolve()
|
||||
return
|
||||
}
|
||||
val nav = bottomNav
|
||||
if (nav == null) {
|
||||
call.resolve()
|
||||
return
|
||||
}
|
||||
nav.post {
|
||||
val reselected = currentTabId == tab.id
|
||||
handleSelection(tab, reselected, notify = false)
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun updateNativeSearchResults(call: PluginCall) {
|
||||
val results = parseResults(call.getArray("results"))
|
||||
activity?.runOnUiThread {
|
||||
ensureSearchUi()
|
||||
val container = resultsContainer ?: return@runOnUiThread
|
||||
container.removeAllViews()
|
||||
results.forEach { result ->
|
||||
container.addView(makeResultRow(result))
|
||||
}
|
||||
call.resolve()
|
||||
} ?: call.resolve()
|
||||
}
|
||||
|
||||
/**
|
||||
* FIX: Allows the web view to explicitly show the search UI again,
|
||||
* typically after backing out of an opened search result item.
|
||||
*/
|
||||
@PluginMethod
|
||||
fun showSearchUiNative(call: PluginCall) {
|
||||
activity?.runOnUiThread {
|
||||
showSearchUi()
|
||||
// Ensure padding is correct when search UI is manually shown
|
||||
adjustWebViewPadding()
|
||||
call.resolve()
|
||||
} ?: call.resolve()
|
||||
}
|
||||
|
||||
fun handleNativeBackPressed(): Boolean {
|
||||
val container = searchContainer ?: return false
|
||||
if (container.visibility != View.VISIBLE) return false
|
||||
|
||||
val input = searchInput ?: return false
|
||||
val imeVisible = ViewCompat.getRootWindowInsets(input)
|
||||
?.isVisible(WindowInsetsCompat.Type.ime()) == true
|
||||
val hasFocus = input.hasFocus()
|
||||
|
||||
if (imeVisible || hasFocus) {
|
||||
moveFocusAwayFromSearchInput(input)
|
||||
hideIme(input)
|
||||
return true
|
||||
}
|
||||
|
||||
dismissSearchUiFromBack()
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
private fun ensureNav(): ComposeView {
|
||||
val activity = activity ?: throw IllegalStateException("No activity")
|
||||
val root = NativeUiUtils.contentRoot(activity)
|
||||
val nav = bottomNav ?: ComposeView(activity).also { view ->
|
||||
view.id = R.id.liquid_tabs_bottom_nav // Assuming R.id.liquid_tabs_bottom_nav is defined
|
||||
view.setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
||||
view.layoutParams = FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
Gravity.BOTTOM
|
||||
)
|
||||
view.setBackgroundColor(LogseqTheme.current().background)
|
||||
bottomNav = view
|
||||
root.addView(view)
|
||||
setupImeBehaviorForNav(view)
|
||||
}
|
||||
|
||||
nav.setContent {
|
||||
BottomNavBar(
|
||||
tabs = tabsState,
|
||||
currentId = currentTabId,
|
||||
onSelect = { tab ->
|
||||
val reselected = tab.id == currentTabId
|
||||
handleSelection(tab, reselected, notify = true)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
nav.doOnNextLayout { adjustWebViewPadding() }
|
||||
return nav
|
||||
}
|
||||
|
||||
private fun handleSelection(tab: TabSpec, reselected: Boolean, notify: Boolean) {
|
||||
currentTabId = tab.id
|
||||
if (tab.role == "search") {
|
||||
showSearchUi()
|
||||
} else {
|
||||
clearSearchUi()
|
||||
hideSearchUi()
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
notifyListeners("tabSelected", JSObject().put("id", tab.id).put("reselected", reselected))
|
||||
}
|
||||
|
||||
adjustWebViewPadding()
|
||||
}
|
||||
|
||||
private fun adjustWebViewPadding() {
|
||||
val webView = bridge.webView ?: return
|
||||
val nav = bottomNav ?: return
|
||||
if (originalBottomPadding == null) {
|
||||
originalBottomPadding = webView.paddingBottom
|
||||
}
|
||||
nav.post {
|
||||
val padding = originalBottomPadding ?: 0
|
||||
val h = nav.height
|
||||
val newPadding = if (searchContainer?.visibility == View.VISIBLE) {
|
||||
padding
|
||||
} else {
|
||||
padding + h
|
||||
}
|
||||
webView.setPadding(webView.paddingLeft, webView.paddingTop, webView.paddingRight, newPadding)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupImeBehaviorForNav(nav: View) {
|
||||
ViewCompat.setOnApplyWindowInsetsListener(nav) { v, insets ->
|
||||
val imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime())
|
||||
val imeVisible = insets.isVisible(WindowInsetsCompat.Type.ime())
|
||||
|
||||
val extra = if (imeVisible) {
|
||||
imeInsets.bottom
|
||||
} else {
|
||||
0
|
||||
}
|
||||
v.translationY = extra.toFloat()
|
||||
insets
|
||||
}
|
||||
|
||||
ViewCompat.requestApplyInsets(nav)
|
||||
}
|
||||
|
||||
private fun ensureSearchUi() {
|
||||
if (searchContainer != null) return
|
||||
showSearchUi()
|
||||
}
|
||||
|
||||
private fun showSearchUi() {
|
||||
val activity = activity ?: return
|
||||
val root = NativeUiUtils.contentRoot(activity)
|
||||
val theme = LogseqTheme.current()
|
||||
val labelColor = if (theme.isDark) theme.tint else Color.BLACK
|
||||
val secondaryLabelColor =
|
||||
if (theme.isDark) Color.argb(200, 245, 247, 250) else Color.DKGRAY
|
||||
|
||||
// Calculate status bar height for safe area padding
|
||||
val insets = ViewCompat.getRootWindowInsets(root)
|
||||
val statusBarHeight = insets?.getInsets(WindowInsetsCompat.Type.statusBars())?.top ?: 0
|
||||
|
||||
val container = searchContainer ?: LinearLayout(activity).also { layout ->
|
||||
layout.orientation = LinearLayout.VERTICAL
|
||||
layout.setBackgroundColor(theme.background)
|
||||
|
||||
val lp = FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
|
||||
// Set bottom margin to clear the bottom navigation bar
|
||||
lp.setMargins(0, 0, 0, bottomNav?.height ?: NativeUiUtils.dp(activity, 56f))
|
||||
|
||||
// Remove elevation/shadow
|
||||
layout.elevation = 0f
|
||||
|
||||
// Apply status bar height as top padding for safe area
|
||||
layout.setPadding(0, statusBarHeight, 0, 0)
|
||||
|
||||
root.addView(layout, lp)
|
||||
searchContainer = layout
|
||||
}
|
||||
|
||||
// Re-apply top padding in case insets were not available on first run
|
||||
container.setPadding(0, statusBarHeight, 0, 0)
|
||||
|
||||
// Search Input Setup
|
||||
if (searchInput == null) {
|
||||
// Container for input and close button
|
||||
val searchRow = LinearLayout(activity).apply {
|
||||
orientation = LinearLayout.HORIZONTAL
|
||||
gravity = Gravity.CENTER_VERTICAL // Center items vertically
|
||||
}
|
||||
|
||||
val input = EditText(activity).apply {
|
||||
hint = "Search"
|
||||
setSingleLine(true)
|
||||
imeOptions = EditorInfo.IME_ACTION_SEARCH
|
||||
setTextColor(labelColor)
|
||||
setHintTextColor(secondaryLabelColor)
|
||||
// Remove EditText default background/border for a flat look
|
||||
setBackgroundColor(Color.TRANSPARENT)
|
||||
|
||||
// Fine-tune padding inside the EditText for text alignment
|
||||
setPadding(
|
||||
NativeUiUtils.dp(activity, 0f),
|
||||
NativeUiUtils.dp(activity, 10f),
|
||||
NativeUiUtils.dp(activity, 0f),
|
||||
NativeUiUtils.dp(activity, 10f)
|
||||
)
|
||||
|
||||
// Layout params to make EditText take most of the horizontal space
|
||||
layoutParams = LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f)
|
||||
|
||||
setOnEditorActionListener { _, actionId, event ->
|
||||
val isEnter =
|
||||
actionId == EditorInfo.IME_ACTION_SEARCH ||
|
||||
actionId == EditorInfo.IME_ACTION_DONE ||
|
||||
actionId == EditorInfo.IME_ACTION_GO ||
|
||||
(event?.keyCode == KeyEvent.KEYCODE_ENTER)
|
||||
if (isEnter) {
|
||||
notifyListeners("keyboardHackKey", JSObject().put("key", "enter"))
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
setOnKeyListener { _, keyCode, event ->
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_ENTER -> {
|
||||
if (event.action == KeyEvent.ACTION_DOWN) {
|
||||
notifyListeners("keyboardHackKey", JSObject().put("key", "enter"))
|
||||
}
|
||||
true
|
||||
}
|
||||
KeyEvent.KEYCODE_DEL -> {
|
||||
if (text.isNullOrEmpty() && event.action == KeyEvent.ACTION_DOWN) {
|
||||
notifyListeners("keyboardHackKey", JSObject().put("key", "backspace"))
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
addTextChangedListener(object : TextWatcher {
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
// Toggle close button visibility based on text
|
||||
val hasText = !s.isNullOrEmpty()
|
||||
closeButton?.visibility = if (hasText) View.VISIBLE else View.GONE
|
||||
}
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
notifyListeners("searchChanged", JSObject().put("query", s?.toString() ?: ""))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Close Button
|
||||
val button = ImageButton(activity).apply {
|
||||
setImageDrawable(AppCompatResources.getDrawable(activity, R.drawable.ic_search_clear))
|
||||
background = null
|
||||
scaleType = ImageView.ScaleType.CENTER_INSIDE
|
||||
contentDescription = "Clear search"
|
||||
alpha = if (theme.isDark) 0.92f else 0.8f
|
||||
setPadding(
|
||||
NativeUiUtils.dp(activity, 4f),
|
||||
NativeUiUtils.dp(activity, 4f),
|
||||
NativeUiUtils.dp(activity, 4f),
|
||||
NativeUiUtils.dp(activity, 4f)
|
||||
)
|
||||
minimumWidth = NativeUiUtils.dp(activity, 28f)
|
||||
minimumHeight = NativeUiUtils.dp(activity, 28f)
|
||||
visibility = View.GONE // Initially hidden
|
||||
|
||||
setOnClickListener {
|
||||
input.setText("") // Clear the EditText
|
||||
// TextWatcher will handle notifying the web view and hiding the button
|
||||
}
|
||||
// Set layout params for the button
|
||||
layoutParams = LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
).apply {
|
||||
marginStart = NativeUiUtils.dp(activity, 8f)
|
||||
}
|
||||
}
|
||||
|
||||
// 1. Add EditText
|
||||
searchRow.addView(input)
|
||||
// 2. Add Close Button
|
||||
searchRow.addView(button)
|
||||
|
||||
// inputContainer (was the old search container wrapper)
|
||||
val inputContainer = LinearLayout(activity).apply {
|
||||
// Add horizontal padding for the search box container
|
||||
setPadding(
|
||||
NativeUiUtils.dp(activity, HORIZONTAL_PADDING_DP),
|
||||
NativeUiUtils.dp(activity, VERTICAL_PADDING_DP),
|
||||
NativeUiUtils.dp(activity, HORIZONTAL_PADDING_DP),
|
||||
NativeUiUtils.dp(activity, VERTICAL_PADDING_DP)
|
||||
)
|
||||
orientation = LinearLayout.VERTICAL
|
||||
// Add the new searchRow (input + button)
|
||||
addView(searchRow, 0, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
|
||||
// Add a divider below the search box (optional visual polish)
|
||||
val divider = View(activity).apply {
|
||||
layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, NativeUiUtils.dp(activity, 1f))
|
||||
setBackgroundColor(
|
||||
if (theme.isDark) Color.argb(40, 245, 247, 250) else Color.parseColor("#E0E0E0")
|
||||
)
|
||||
}
|
||||
addView(divider, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, NativeUiUtils.dp(activity, 1f)))
|
||||
}
|
||||
|
||||
// Insert the inputContainer into the main searchContainer
|
||||
container.addView(inputContainer, 0, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
searchInput = input
|
||||
closeButton = button
|
||||
}
|
||||
|
||||
// Search Results Setup
|
||||
if (resultsContainer == null) {
|
||||
val scroll = ScrollView(activity)
|
||||
val inner = LinearLayout(activity).apply {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
// Apply horizontal padding for the list of results
|
||||
setPadding(
|
||||
NativeUiUtils.dp(activity, HORIZONTAL_PADDING_DP), // Left
|
||||
NativeUiUtils.dp(activity, 0f), // Top
|
||||
NativeUiUtils.dp(activity, HORIZONTAL_PADDING_DP), // Right
|
||||
NativeUiUtils.dp(activity, 12f) // Bottom
|
||||
)
|
||||
}
|
||||
scroll.addView(inner, FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||
// The ScrollView should take up the rest of the vertical space
|
||||
container.addView(scroll, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
|
||||
resultsContainer = inner
|
||||
}
|
||||
|
||||
container.visibility = View.VISIBLE
|
||||
adjustWebViewPadding()
|
||||
}
|
||||
|
||||
private fun clearSearchUi() {
|
||||
searchInput?.setText("")
|
||||
resultsContainer?.removeAllViews()
|
||||
}
|
||||
|
||||
private fun hideSearchUi() {
|
||||
dismissActiveSearchInput()
|
||||
searchContainer?.visibility = View.GONE
|
||||
adjustWebViewPadding()
|
||||
}
|
||||
|
||||
private fun dismissSearchUiFromBack() {
|
||||
hideSearchUi()
|
||||
}
|
||||
|
||||
private fun dismissActiveSearchInput() {
|
||||
searchInput?.let { input ->
|
||||
moveFocusAwayFromSearchInput(input)
|
||||
hideIme(input)
|
||||
}
|
||||
}
|
||||
|
||||
private fun moveFocusAwayFromSearchInput(input: EditText) {
|
||||
val container = searchContainer
|
||||
if (container != null) {
|
||||
container.isFocusableInTouchMode = true
|
||||
container.isFocusable = true
|
||||
container.requestFocus()
|
||||
}
|
||||
input.clearFocus()
|
||||
activity?.currentFocus?.clearFocus()
|
||||
}
|
||||
|
||||
private fun hideIme(target: View) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
target.windowInsetsController?.hide(WindowInsets.Type.ime())
|
||||
}
|
||||
val imm = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager
|
||||
val windowToken = target.windowToken
|
||||
?: activity?.currentFocus?.windowToken
|
||||
?: activity?.window?.decorView?.windowToken
|
||||
?: searchContainer?.windowToken
|
||||
if (windowToken != null) {
|
||||
imm?.hideSoftInputFromWindow(windowToken, 0)
|
||||
}
|
||||
target.post {
|
||||
val postedToken = activity?.window?.decorView?.windowToken ?: target.windowToken
|
||||
if (postedToken != null) {
|
||||
imm?.hideSoftInputFromWindow(postedToken, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun makeResultRow(result: SearchResult): View {
|
||||
val activity = activity ?: throw IllegalStateException("No activity")
|
||||
val theme = LogseqTheme.current()
|
||||
val labelColor = if (theme.isDark) theme.tint else Color.BLACK
|
||||
val secondaryLabelColor =
|
||||
if (theme.isDark) Color.argb(200, 245, 247, 250) else Color.DKGRAY
|
||||
return LinearLayout(activity).apply {
|
||||
orientation = LinearLayout.VERTICAL
|
||||
|
||||
// Apply vertical padding for the row item, using RESULT_ROW_VERTICAL_PADDING_DP (10f)
|
||||
// for both top and bottom to ensure they are equal.
|
||||
setPadding(0,
|
||||
NativeUiUtils.dp(activity, RESULT_ROW_VERTICAL_PADDING_DP), // TOP: 10f
|
||||
0,
|
||||
NativeUiUtils.dp(activity, RESULT_ROW_VERTICAL_PADDING_DP) // BOTTOM: 10f
|
||||
)
|
||||
|
||||
val subtitleText = result.subtitle
|
||||
if (subtitleText != null &&
|
||||
!subtitleText.isNullOrBlank() &&
|
||||
subtitleText.lowercase() != "null") {
|
||||
|
||||
val sub = TextView(activity).apply {
|
||||
text = subtitleText
|
||||
setTextColor(secondaryLabelColor)
|
||||
textSize = 13f
|
||||
}
|
||||
addView(sub)
|
||||
}
|
||||
|
||||
val titleView = TextView(activity).apply {
|
||||
text = result.title
|
||||
setTextColor(labelColor)
|
||||
textSize = 15f
|
||||
}
|
||||
addView(titleView)
|
||||
|
||||
setOnClickListener {
|
||||
hideSearchUi()
|
||||
notifyListeners("openSearchResultBlock", JSObject().put("id", result.id))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BottomNavBar(
|
||||
tabs: List<TabSpec>,
|
||||
currentId: String?,
|
||||
onSelect: (TabSpec) -> Unit
|
||||
) {
|
||||
val theme by LogseqTheme.colors.collectAsState()
|
||||
val container = ComposeColor(theme.background)
|
||||
val unselected = if (theme.isDark) ComposeColor(theme.tint).copy(alpha = 0.78f) else ComposeColor.Black.copy(alpha = 0.65f)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(container)
|
||||
.padding(horizontal = TAB_BAR_HORIZONTAL_PADDING)
|
||||
) {
|
||||
NavigationBar(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
containerColor = container
|
||||
) {
|
||||
tabs.forEach { tab ->
|
||||
val selected = tab.id == currentId
|
||||
val icon = remember(tab.systemImage, tab.id) {
|
||||
MaterialIconResolver.resolve(tab.systemImage) ?: MaterialIconResolver.resolve(tab.id)
|
||||
}
|
||||
val iconResId = remember(tab.id) { tabIconResId(tab.id) }
|
||||
val accent = ComposeColor(NativeUiUtils.parseColor(ACCENT_COLOR_HEX, Color.parseColor(ACCENT_COLOR_HEX)))
|
||||
|
||||
NavigationBarItem(
|
||||
selected = selected,
|
||||
onClick = { onSelect(tab) },
|
||||
colors = NavigationBarItemDefaults.colors(
|
||||
selectedIconColor = accent,
|
||||
selectedTextColor = accent,
|
||||
unselectedIconColor = unselected,
|
||||
unselectedTextColor = unselected,
|
||||
indicatorColor = accent.copy(alpha = 0.12f)
|
||||
),
|
||||
icon = {
|
||||
if (iconResId != null) {
|
||||
Icon(
|
||||
painter = painterResource(id = iconResId),
|
||||
contentDescription = tab.title
|
||||
)
|
||||
} else {
|
||||
Icon(
|
||||
imageVector = icon ?: Icons.Filled.Circle,
|
||||
contentDescription = tab.title
|
||||
)
|
||||
}
|
||||
},
|
||||
// Slightly reduce the default Material3 gap between icon and label.
|
||||
label = { Text(tab.title, modifier = Modifier.offset(y = (-4).dp)) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseTabs(array: JSArray?): List<TabSpec> {
|
||||
if (array == null) return emptyList()
|
||||
val result = mutableListOf<TabSpec>()
|
||||
for (i in 0 until array.length()) {
|
||||
val obj = array.optJSONObject(i) ?: continue
|
||||
val id = obj.optString("id", "")
|
||||
if (id.isBlank()) continue
|
||||
val title = obj.optString("title", id)
|
||||
val systemImage = obj.optString("systemImage", "")
|
||||
val role = obj.optString("role", "normal")
|
||||
result.add(TabSpec(id, title, systemImage, role))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun parseResults(array: JSArray?): List<SearchResult> {
|
||||
if (array == null) return emptyList()
|
||||
val result = mutableListOf<SearchResult>()
|
||||
for (i in 0 until array.length()) {
|
||||
val obj = array.optJSONObject(i) ?: continue
|
||||
val id = obj.optString("id", "")
|
||||
if (id.isBlank()) continue
|
||||
val title = obj.optString("title", "")
|
||||
val subtitle = if (obj.has("subtitle") && !obj.isNull("subtitle")) obj.optString("subtitle") else null
|
||||
result.add(SearchResult(id, title, subtitle))
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
data class TabSpec(
|
||||
val id: String,
|
||||
val title: String,
|
||||
val systemImage: String,
|
||||
val role: String
|
||||
)
|
||||
|
||||
data class SearchResult(
|
||||
val id: String,
|
||||
val title: String,
|
||||
val subtitle: String?
|
||||
)
|
||||
44
android/app/src/main/java/com/logseq/app/LogseqTheme.kt
Normal file
@@ -0,0 +1,44 @@
|
||||
package com.logseq.app
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
data class LogseqThemeColors(
|
||||
val background: Int,
|
||||
val tint: Int,
|
||||
val isDark: Boolean,
|
||||
)
|
||||
|
||||
object LogseqTheme {
|
||||
private val _colors = MutableStateFlow(compute(isDark = false))
|
||||
val colors: StateFlow<LogseqThemeColors> = _colors.asStateFlow()
|
||||
|
||||
fun update(context: Context) {
|
||||
_colors.value = compute(context)
|
||||
}
|
||||
|
||||
fun current(): LogseqThemeColors = _colors.value
|
||||
|
||||
fun isDark(context: Context): Boolean {
|
||||
val mask = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||
return mask == Configuration.UI_MODE_NIGHT_YES
|
||||
}
|
||||
|
||||
private fun compute(context: Context): LogseqThemeColors = compute(isDark(context))
|
||||
|
||||
private fun compute(isDark: Boolean): LogseqThemeColors {
|
||||
val background =
|
||||
if (isDark) Color.parseColor("#002B36") else Color.parseColor("#FCFCFC")
|
||||
val tint =
|
||||
if (isDark) Color.parseColor("#F5F7FA") else Color.parseColor("#000000")
|
||||
return LogseqThemeColors(
|
||||
background = background,
|
||||
tint = tint,
|
||||
isDark = isDark,
|
||||
)
|
||||
}
|
||||
}
|
||||
345
android/app/src/main/java/com/logseq/app/MainActivity.java
Normal file
@@ -0,0 +1,345 @@
|
||||
package com.logseq.app;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Build;
|
||||
import android.webkit.WebView;
|
||||
import androidx.activity.OnBackPressedCallback;
|
||||
import androidx.activity.BackEventCompat;
|
||||
import androidx.activity.EdgeToEdge;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.view.WindowInsetsControllerCompat;
|
||||
import com.getcapacitor.BridgeActivity;
|
||||
import com.getcapacitor.PluginHandle;
|
||||
import com.getcapacitor.Plugin;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.window.OnBackInvokedCallback;
|
||||
import android.window.OnBackInvokedDispatcher;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class MainActivity extends BridgeActivity {
|
||||
private static final String NAV_STACK_DEBUG_PREFIX = "[DEBUG-navstack]";
|
||||
private final NavigationCoordinator navigationCoordinator = new NavigationCoordinator();
|
||||
private BroadcastReceiver routeChangeReceiver;
|
||||
private OnBackInvokedCallback overlayBackInvokedCallback;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
registerPlugin(FolderPicker.class);
|
||||
registerPlugin(UILocal.class);
|
||||
registerPlugin(NativeTopBarPlugin.class);
|
||||
registerPlugin(NativeBottomSheetPlugin.class);
|
||||
registerPlugin(NativeEditorToolbarPlugin.class);
|
||||
registerPlugin(NativeSelectionActionBarPlugin.class);
|
||||
registerPlugin(LiquidTabsPlugin.class);
|
||||
registerPlugin(Utils.class);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
// @capacitor/app installs its own OnBackPressedCallback during plugin load (inside
|
||||
// super.onCreate above). Its callback consumes the first system/edge back press by
|
||||
// calling webView.goBack(), which both makes the WebView flash and prevents our
|
||||
// MainActivity-level handler (below) from ever running. We route back through JS
|
||||
// instead, so disable that plugin's back handler defensively even if the config
|
||||
// entry "App.disableBackButtonHandler" hasn't been synced yet.
|
||||
disableCapacitorAppBackHandler();
|
||||
|
||||
EdgeToEdge.enable(this);
|
||||
WebView webView = getBridge().getWebView();
|
||||
webView.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
|
||||
webView.getSettings().setUseWideViewPort(true);
|
||||
webView.getSettings().setLoadWithOverviewMode(true);
|
||||
|
||||
applyLogseqTheme();
|
||||
|
||||
// Let Compose host the WebView with system bar padding for safe areas.
|
||||
// Android back is still delegated to JS from the Activity back dispatcher.
|
||||
ComposeHost.INSTANCE.renderWithSystemInsets(this, webView);
|
||||
WebViewKeyboardRecovery.install(this, webView);
|
||||
|
||||
// On API 33+ (Android 13+), predictive back routes through the platform-level
|
||||
// OnBackInvokedDispatcher. AndroidX's OnBackPressedDispatcher bridges into it at
|
||||
// PRIORITY_DEFAULT, so plugin / Compose / WebView callbacks registered through
|
||||
// AndroidX can pre-empt ours. Register OUR callback directly on the platform
|
||||
// dispatcher at PRIORITY_OVERLAY to guarantee the first edge-back gesture is
|
||||
// delivered to handleNativeBack().
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
overlayBackInvokedCallback = () -> {
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.onBackInvoked source=window-overlay");
|
||||
handleNativeBack();
|
||||
};
|
||||
getOnBackInvokedDispatcher().registerOnBackInvokedCallback(
|
||||
OnBackInvokedDispatcher.PRIORITY_OVERLAY,
|
||||
overlayBackInvokedCallback
|
||||
);
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.onBackInvoked.registered priority=OVERLAY");
|
||||
}
|
||||
|
||||
// Fallback for API < 33 and as defense in depth. Predictive-back lifecycle methods
|
||||
// log so we can see whether the system is starting/cancelling vs committing.
|
||||
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
|
||||
@Override
|
||||
public void handleOnBackStarted(BackEventCompat backEvent) {
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.onBackStarted progress=" + backEvent.getProgress() + " edge=" + backEvent.getSwipeEdge());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleOnBackProgressed(BackEventCompat backEvent) {
|
||||
// Intentionally not logging every progress tick; uncomment for tracing.
|
||||
// Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.onBackProgressed progress=" + backEvent.getProgress());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleOnBackCancelled() {
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.onBackCancelled");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleOnBackPressed() {
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.onBackPressed source=androidx-dispatcher");
|
||||
handleNativeBack();
|
||||
}
|
||||
});
|
||||
|
||||
routeChangeReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (!UILocal.ACTION_ROUTE_CHANGED.equals(intent.getAction())) return;
|
||||
String stack = intent.getStringExtra("stack");
|
||||
String navigationType = intent.getStringExtra("navigationType");
|
||||
String path = intent.getStringExtra("path");
|
||||
Log.d(
|
||||
"NavStack",
|
||||
NAV_STACK_DEBUG_PREFIX + " activity.routeChange.received stack=" + stack
|
||||
+ " type=" + navigationType
|
||||
+ " path=" + path
|
||||
+ " before=" + navigationCoordinator.debugState()
|
||||
);
|
||||
NavigationRenderState renderState = navigationCoordinator.onRouteChange(stack, navigationType, path);
|
||||
if (renderState.getApplyToCompose()) {
|
||||
ComposeHost.applyNavigation(renderState);
|
||||
} else {
|
||||
Log.d(
|
||||
"NavStack",
|
||||
NAV_STACK_DEBUG_PREFIX + " activity.routeChange.skippedCompose stack="
|
||||
+ renderState.getActiveStackId()
|
||||
+ " type=" + renderState.getNavigationType()
|
||||
+ " path=" + renderState.getPath()
|
||||
);
|
||||
}
|
||||
Log.d(
|
||||
"NavStack",
|
||||
NAV_STACK_DEBUG_PREFIX + " activity.routeChange.applied after="
|
||||
+ navigationCoordinator.debugState()
|
||||
+ " renderStack=" + renderState.getActiveStackId()
|
||||
+ " renderPaths=" + renderState.getPaths()
|
||||
+ " stackSwitched=" + renderState.getStackSwitched()
|
||||
+ " applyToCompose=" + renderState.getApplyToCompose()
|
||||
);
|
||||
}
|
||||
};
|
||||
IntentFilter filter = new IntentFilter(UILocal.ACTION_ROUTE_CHANGED);
|
||||
ContextCompat.registerReceiver(this, routeChangeReceiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED);
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
bridge.eval("window.dispatchEvent(new Event('sendIntentReceived'))", s -> {});
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
applyLogseqTheme();
|
||||
dispatchSystemThemeToWeb();
|
||||
}
|
||||
|
||||
private void applyLogseqTheme() {
|
||||
LogseqTheme.INSTANCE.update(this);
|
||||
LogseqThemeColors colors = LogseqTheme.INSTANCE.current();
|
||||
|
||||
int bg = colors.getBackground();
|
||||
boolean isDark = colors.isDark();
|
||||
|
||||
View content = findViewById(android.R.id.content);
|
||||
if (content != null) {
|
||||
content.setBackgroundColor(bg);
|
||||
}
|
||||
|
||||
WebView webView = getBridge() != null ? getBridge().getWebView() : null;
|
||||
if (webView != null) {
|
||||
webView.setBackgroundColor(bg);
|
||||
}
|
||||
|
||||
getWindow().getDecorView().setBackgroundColor(bg);
|
||||
getWindow().setStatusBarColor(bg);
|
||||
getWindow().setNavigationBarColor(bg);
|
||||
|
||||
WindowInsetsControllerCompat controller = new WindowInsetsControllerCompat(getWindow(), getWindow().getDecorView());
|
||||
controller.setAppearanceLightStatusBars(!isDark);
|
||||
controller.setAppearanceLightNavigationBars(!isDark);
|
||||
|
||||
WebViewSnapshotManager.INSTANCE.setSnapshotBackgroundColor(bg);
|
||||
}
|
||||
|
||||
public void applyLogseqThemeNow() {
|
||||
applyLogseqTheme();
|
||||
}
|
||||
|
||||
private void dispatchSystemThemeToWeb() {
|
||||
try {
|
||||
if (bridge == null) return;
|
||||
boolean isDark = LogseqTheme.INSTANCE.isDark(this);
|
||||
String js = "window.dispatchEvent(new CustomEvent('logseq:native-system-theme-changed', { detail: { isDark: "
|
||||
+ (isDark ? "true" : "false")
|
||||
+ " } }));";
|
||||
bridge.eval(js, null);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
overridePendingTransition(0, R.anim.byebye);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
private void handleNativeBack() {
|
||||
Log.d("onBackPressed", "Debug");
|
||||
Log.d(
|
||||
"NavStack",
|
||||
NAV_STACK_DEBUG_PREFIX + " activity.nativeBack source=system-or-edge before="
|
||||
+ navigationCoordinator.debugState()
|
||||
);
|
||||
|
||||
if (consumeNativeOverlayBack()) {
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.nativeBack consumed=native-overlay");
|
||||
return;
|
||||
}
|
||||
|
||||
WebView webView = getBridge().getWebView();
|
||||
if (webView != null) {
|
||||
NavigationRenderState nativePopState = navigationCoordinator.prepareNativePop();
|
||||
if (nativePopState != null) {
|
||||
Log.d(
|
||||
"NavStack",
|
||||
NAV_STACK_DEBUG_PREFIX + " activity.nativeBack consumed=native-stack-pop target="
|
||||
+ nativePopState.getPath()
|
||||
+ " paths=" + nativePopState.getPaths()
|
||||
);
|
||||
ComposeHost.applyNavigation(nativePopState);
|
||||
}
|
||||
// Send "native back" into JS. JS will call your UILocal/route-change,
|
||||
// which flows into ComposeHost.applyNavigation(...) and animates.
|
||||
sendJsBack(webView);
|
||||
} else {
|
||||
// Fallback if for some reason there is no webview
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
String action = intent.getAction();
|
||||
String type = intent.getType();
|
||||
if (Intent.ACTION_SEND.equals(action) && type != null) {
|
||||
bridge.getActivity().setIntent(intent);
|
||||
bridge.eval("window.dispatchEvent(new Event('sendIntentReceived'))", s -> {});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && overlayBackInvokedCallback != null) {
|
||||
try {
|
||||
getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(overlayBackInvokedCallback);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
overlayBackInvokedCallback = null;
|
||||
}
|
||||
if (routeChangeReceiver != null) {
|
||||
unregisterReceiver(routeChangeReceiver);
|
||||
routeChangeReceiver = null;
|
||||
}
|
||||
WebViewKeyboardRecovery.uninstall(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void sendJsBack(WebView webView) {
|
||||
if (webView == null) return;
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.sendJsBack dispatching onNativePop");
|
||||
webView.post(() -> webView.evaluateJavascript(
|
||||
"window.LogseqNative && window.LogseqNative.onNativePop && window.LogseqNative.onNativePop();",
|
||||
null
|
||||
));
|
||||
}
|
||||
|
||||
private boolean consumeNativeOverlayBack() {
|
||||
try {
|
||||
if (getBridge() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PluginHandle handle = getBridge().getPlugin("LiquidTabsPlugin");
|
||||
if (handle == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Plugin instance = handle.getInstance();
|
||||
if (!(instance instanceof LiquidTabsPlugin)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((LiquidTabsPlugin) instance).handleNativeBackPressed();
|
||||
} catch (Exception e) {
|
||||
Log.d(
|
||||
"NavStack",
|
||||
NAV_STACK_DEBUG_PREFIX + " activity.nativeOverlayBack error="
|
||||
+ e.getClass().getSimpleName() + ":" + e.getMessage()
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void disableCapacitorAppBackHandler() {
|
||||
try {
|
||||
if (getBridge() == null) {
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.appPluginBack bridge=null skip");
|
||||
return;
|
||||
}
|
||||
PluginHandle handle = getBridge().getPlugin("App");
|
||||
if (handle == null) {
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.appPluginBack pluginHandle=null skip");
|
||||
return;
|
||||
}
|
||||
Plugin instance = handle.getInstance();
|
||||
if (instance == null) {
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.appPluginBack pluginInstance=null skip");
|
||||
return;
|
||||
}
|
||||
Field field = instance.getClass().getDeclaredField("onBackPressedCallback");
|
||||
field.setAccessible(true);
|
||||
Object callback = field.get(instance);
|
||||
if (callback instanceof OnBackPressedCallback) {
|
||||
((OnBackPressedCallback) callback).setEnabled(false);
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.appPluginBack disabled");
|
||||
} else {
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.appPluginBack unexpectedType=" + (callback == null ? "null" : callback.getClass().getName()));
|
||||
}
|
||||
} catch (NoSuchFieldException e) {
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.appPluginBack noField=" + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
Log.d("NavStack", NAV_STACK_DEBUG_PREFIX + " activity.appPluginBack error=" + e.getClass().getSimpleName() + ":" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.logseq.app
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.outlined.Comment
|
||||
import androidx.compose.material.icons.filled.Bookmarks
|
||||
import androidx.compose.material.icons.filled.Circle
|
||||
import androidx.compose.material.icons.filled.CloudUpload
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Home
|
||||
import androidx.compose.material.icons.filled.Layers
|
||||
import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.material.icons.filled.Send
|
||||
import androidx.compose.material.icons.filled.Star
|
||||
import androidx.compose.material.icons.outlined.CameraAlt
|
||||
import androidx.compose.material.icons.outlined.Add
|
||||
import androidx.compose.material.icons.outlined.AddCircle
|
||||
import androidx.compose.material.icons.outlined.AddReaction
|
||||
import androidx.compose.material.icons.outlined.DataArray
|
||||
import androidx.compose.material.icons.outlined.KeyboardCommandKey
|
||||
import androidx.compose.material.icons.outlined.ArrowBack
|
||||
import androidx.compose.material.icons.outlined.ArrowForward
|
||||
import androidx.compose.material.icons.outlined.AttachFile
|
||||
import androidx.compose.material.icons.outlined.BookmarkAdd
|
||||
import androidx.compose.material.icons.outlined.CalendarToday
|
||||
import androidx.compose.material.icons.outlined.CheckBox
|
||||
import androidx.compose.material.icons.outlined.Code
|
||||
import androidx.compose.material.icons.outlined.ContentCopy
|
||||
import androidx.compose.material.icons.outlined.Dashboard
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material.icons.outlined.Equalizer
|
||||
import androidx.compose.material.icons.outlined.Explore
|
||||
import androidx.compose.material.icons.outlined.GraphicEq
|
||||
import androidx.compose.material.icons.outlined.KeyboardHide
|
||||
import androidx.compose.material.icons.outlined.Link
|
||||
import androidx.compose.material.icons.outlined.LocalOffer
|
||||
import androidx.compose.material.icons.outlined.MoreVert
|
||||
import androidx.compose.material.icons.outlined.Redo
|
||||
import androidx.compose.material.icons.outlined.Search
|
||||
import androidx.compose.material.icons.outlined.StarBorder
|
||||
import androidx.compose.material.icons.outlined.Undo
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
object MaterialIconResolver {
|
||||
fun resolve(name: String?): ImageVector? {
|
||||
val key = name
|
||||
?.trim()
|
||||
?.lowercase()
|
||||
?.replace("_", "-")
|
||||
?.replace("\\s+".toRegex(), "-")
|
||||
?.replace(".", "-")
|
||||
?: return null
|
||||
|
||||
return when (key) {
|
||||
"chevron-backward", "arrow-left", "back" -> Icons.Outlined.ArrowBack
|
||||
"arrow-right" -> Icons.Outlined.ArrowForward
|
||||
"arrow-uturn-backward" -> Icons.Outlined.Undo
|
||||
"arrow-uturn-forward" -> Icons.Outlined.Redo
|
||||
"calendar" -> Icons.Outlined.CalendarToday
|
||||
"waveform", "audio", "equalizer" -> Icons.Outlined.GraphicEq
|
||||
"ellipsis" -> Icons.Outlined.MoreVert
|
||||
"star-fill" -> Icons.Filled.Star
|
||||
"star" -> Icons.Outlined.StarBorder
|
||||
"circle-fill" -> Icons.Filled.Circle
|
||||
"plus", "add" -> Icons.Outlined.Add
|
||||
"paperplane", "send" -> Icons.Filled.Send
|
||||
"todo", "checkmark-square" -> Icons.Outlined.CheckBox
|
||||
"number", "tag" -> Icons.Outlined.LocalOffer
|
||||
"parentheses" -> Icons.Outlined.DataArray
|
||||
"command", "slash" -> Icons.Outlined.KeyboardCommandKey
|
||||
"camera" -> Icons.Outlined.CameraAlt
|
||||
"keyboard-chevron-compact-down", "keyboard-hide" -> Icons.Outlined.KeyboardHide
|
||||
"doc-on-doc", "copy" -> Icons.Outlined.ContentCopy
|
||||
"text-bubble", "comment" -> Icons.AutoMirrored.Outlined.Comment
|
||||
"trash", "delete" -> Icons.Outlined.Delete
|
||||
"r-square", "bookmark-ref" -> Icons.Outlined.BookmarkAdd
|
||||
"link" -> Icons.Outlined.Link
|
||||
"xmark", "close" -> Icons.Filled.Close
|
||||
"house", "home" -> Icons.Filled.Home
|
||||
"app-background-dotted" -> Icons.Outlined.Dashboard
|
||||
"tray", "add" -> Icons.Outlined.AddCircle
|
||||
"square-stack-3d-down-right", "layers" -> Icons.Filled.Layers
|
||||
"magnifyingglass", "search" -> Icons.Outlined.Search
|
||||
"go-to", "goto" -> Icons.Outlined.Explore
|
||||
"bookmark" -> Icons.Filled.Bookmarks
|
||||
"sync" -> Icons.Outlined.Equalizer
|
||||
"cloud", "cloud-upload", "icloud-and-arrow-up" -> Icons.Filled.CloudUpload
|
||||
"paperclip" -> Icons.Outlined.AttachFile
|
||||
"face-smiling" -> Icons.Outlined.AddReaction
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
package com.logseq.app
|
||||
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import com.getcapacitor.JSObject
|
||||
import com.getcapacitor.Plugin
|
||||
import com.getcapacitor.PluginCall
|
||||
import com.getcapacitor.PluginMethod
|
||||
import com.getcapacitor.annotation.CapacitorPlugin
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
|
||||
@CapacitorPlugin(name = "NativeBottomSheetPlugin")
|
||||
class NativeBottomSheetPlugin : Plugin() {
|
||||
private val snapshotTag = "bottom-sheet"
|
||||
private val mainHandler = Handler(Looper.getMainLooper())
|
||||
private var dialog: BottomSheetDialog? = null
|
||||
private var pendingPresentation: (() -> Unit)? = null
|
||||
private var awaitingContentReady = false
|
||||
private var previousParent: ViewGroup? = null
|
||||
private var previousIndex: Int = -1
|
||||
private var previousLayoutParams: ViewGroup.LayoutParams? = null
|
||||
private var placeholder: View? = null
|
||||
private var container: FrameLayout? = null
|
||||
private var pendingRestoreWebView: View? = null
|
||||
private var dismissalFallback: Runnable? = null
|
||||
|
||||
@PluginMethod
|
||||
fun present(call: PluginCall) {
|
||||
val activity = activity ?: run {
|
||||
call.reject("No activity")
|
||||
return
|
||||
}
|
||||
val webView = bridge.webView ?: run {
|
||||
call.reject("No webview")
|
||||
return
|
||||
}
|
||||
|
||||
activity.runOnUiThread {
|
||||
WebViewSnapshotManager.registerWindow(activity.window)
|
||||
if (dialog != null || pendingPresentation != null || awaitingContentReady) {
|
||||
call.resolve()
|
||||
return@runOnUiThread
|
||||
}
|
||||
|
||||
val ctx = activity
|
||||
container = FrameLayout(ctx)
|
||||
container!!.layoutParams = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
|
||||
val cornerRadius = NativeUiUtils.dp(ctx, 16f).toFloat()
|
||||
val roundedBackground = GradientDrawable().apply {
|
||||
setColor(LogseqTheme.current().background)
|
||||
cornerRadii = floatArrayOf(
|
||||
cornerRadius, cornerRadius, // 左上角
|
||||
cornerRadius, cornerRadius, // 右上角
|
||||
0f, 0f, // 右下角
|
||||
0f, 0f // 左下角
|
||||
)
|
||||
}
|
||||
container!!.background = roundedBackground
|
||||
container!!.clipToOutline = true
|
||||
|
||||
val sheet = BottomSheetDialog(ctx)
|
||||
sheet.setContentView(container!!)
|
||||
|
||||
sheet.setOnShowListener {
|
||||
val bottomSheet = sheet.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
|
||||
bottomSheet?.setBackgroundColor(Color.TRANSPARENT)
|
||||
}
|
||||
|
||||
WebViewSnapshotManager.showSnapshot(snapshotTag, webView)
|
||||
|
||||
val behavior = sheet.behavior
|
||||
val defaultHeight = call.getInt("defaultHeight", null)
|
||||
val allowFullHeight = call.getBoolean("allowFullHeight") ?: true
|
||||
if (defaultHeight != null) {
|
||||
val peek = NativeUiUtils.dp(ctx, defaultHeight.toFloat())
|
||||
behavior.peekHeight = peek
|
||||
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
} else {
|
||||
behavior.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
}
|
||||
behavior.skipCollapsed = !allowFullHeight
|
||||
|
||||
sheet.setOnDismissListener {
|
||||
awaitingContentReady = true
|
||||
|
||||
// Forcefully detach WebView before restoring
|
||||
try {
|
||||
(webView.parent as? ViewGroup)?.removeView(webView)
|
||||
container?.removeAllViews()
|
||||
} catch (_: Exception) {}
|
||||
|
||||
// Delay restoration slightly to let Android clean up window surfaces
|
||||
mainHandler.post {
|
||||
restoreWebView(webView)
|
||||
webView.alpha = 0f
|
||||
pendingRestoreWebView = webView
|
||||
awaitingContentReady = true
|
||||
scheduleDismissalFallback()
|
||||
}
|
||||
|
||||
notifyListeners("state", JSObject().put("dismissing", true))
|
||||
dialog = null
|
||||
container = null
|
||||
}
|
||||
|
||||
pendingPresentation = {
|
||||
detachWebView(webView, ctx)
|
||||
container!!.addView(
|
||||
webView,
|
||||
FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
)
|
||||
sheet.show()
|
||||
notifyListeners("state", JSObject().put("presented", true))
|
||||
dialog = sheet
|
||||
call.resolve()
|
||||
}
|
||||
notifyListeners("state", JSObject().put("presenting", true))
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun dismiss(call: PluginCall) {
|
||||
activity?.runOnUiThread {
|
||||
if (pendingPresentation != null) {
|
||||
pendingPresentation = null
|
||||
container = null
|
||||
WebViewSnapshotManager.clearSnapshot(snapshotTag)
|
||||
notifyListeners("state", JSObject().put("dismissing", true))
|
||||
notifyListeners(
|
||||
"state",
|
||||
JSObject()
|
||||
.put("presented", false)
|
||||
.put("dismissing", false)
|
||||
)
|
||||
call.resolve()
|
||||
return@runOnUiThread
|
||||
}
|
||||
|
||||
if (dialog == null) {
|
||||
pendingRestoreWebView?.let { finishDismissal(it) }
|
||||
?: WebViewSnapshotManager.clearSnapshot(snapshotTag)
|
||||
call.resolve()
|
||||
return@runOnUiThread
|
||||
}
|
||||
|
||||
dialog?.dismiss()
|
||||
call.resolve()
|
||||
} ?: call.resolve()
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun contentReady(call: PluginCall) {
|
||||
activity?.runOnUiThread {
|
||||
pendingPresentation?.let { presentation ->
|
||||
pendingPresentation = null
|
||||
presentation()
|
||||
call.resolve()
|
||||
return@runOnUiThread
|
||||
}
|
||||
|
||||
val webView = pendingRestoreWebView
|
||||
if (!awaitingContentReady || webView == null) {
|
||||
call.resolve()
|
||||
return@runOnUiThread
|
||||
}
|
||||
|
||||
finishDismissal(webView)
|
||||
call.resolve()
|
||||
} ?: call.resolve()
|
||||
}
|
||||
|
||||
private fun detachWebView(webView: View, ctx: android.content.Context) {
|
||||
val parent = webView.parent as? ViewGroup ?: return
|
||||
previousParent = parent
|
||||
previousIndex = parent.indexOfChild(webView)
|
||||
previousLayoutParams = webView.layoutParams
|
||||
|
||||
parent.removeView(webView)
|
||||
placeholder = View(ctx).apply {
|
||||
setBackgroundColor(LogseqTheme.current().background)
|
||||
layoutParams = previousLayoutParams ?: ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
}
|
||||
parent.addView(placeholder, previousIndex)
|
||||
}
|
||||
|
||||
private fun restoreWebView(webView: View) {
|
||||
val parent = previousParent ?: return
|
||||
val lp = previousLayoutParams ?: ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
|
||||
// Fully detach from any container
|
||||
(webView.parent as? ViewGroup)?.removeView(webView)
|
||||
placeholder?.let { parent.removeView(it) }
|
||||
placeholder = null
|
||||
|
||||
// Reattach WebView
|
||||
if (previousIndex in 0..parent.childCount) {
|
||||
parent.addView(webView, previousIndex, lp)
|
||||
} else {
|
||||
parent.addView(webView, lp)
|
||||
}
|
||||
|
||||
// ✅ Force WebView to recreate its SurfaceView and redraw
|
||||
webView.visibility = View.INVISIBLE
|
||||
webView.post {
|
||||
webView.visibility = View.VISIBLE
|
||||
webView.requestLayout()
|
||||
webView.invalidate()
|
||||
webView.dispatchWindowVisibilityChanged(View.VISIBLE)
|
||||
}
|
||||
|
||||
previousParent = null
|
||||
previousLayoutParams = null
|
||||
previousIndex = -1
|
||||
container = null
|
||||
}
|
||||
|
||||
private fun finishDismissal(webView: View) {
|
||||
dismissalFallback?.let(mainHandler::removeCallbacks)
|
||||
dismissalFallback = null
|
||||
awaitingContentReady = false
|
||||
pendingRestoreWebView = null
|
||||
|
||||
webView.alpha = 1f
|
||||
webView.requestLayout()
|
||||
webView.invalidate()
|
||||
|
||||
WebViewSnapshotManager.clearSnapshot(snapshotTag)
|
||||
notifyListeners(
|
||||
"state",
|
||||
JSObject()
|
||||
.put("presented", false)
|
||||
.put("dismissing", false)
|
||||
)
|
||||
}
|
||||
|
||||
private fun scheduleDismissalFallback() {
|
||||
dismissalFallback?.let(mainHandler::removeCallbacks)
|
||||
|
||||
val runnable = Runnable {
|
||||
val webView = pendingRestoreWebView
|
||||
if (awaitingContentReady && webView != null) {
|
||||
finishDismissal(webView)
|
||||
}
|
||||
}
|
||||
|
||||
dismissalFallback = runnable
|
||||
mainHandler.postDelayed(runnable, 2_000)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,381 @@
|
||||
package com.logseq.app
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.defaultMinSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.wrapContentHeight
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color as ComposeColor
|
||||
import androidx.compose.ui.graphics.luminance
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.getcapacitor.JSArray
|
||||
import com.getcapacitor.JSObject
|
||||
import com.getcapacitor.Plugin
|
||||
import com.getcapacitor.PluginCall
|
||||
import com.getcapacitor.PluginMethod
|
||||
import com.getcapacitor.annotation.CapacitorPlugin
|
||||
|
||||
@CapacitorPlugin(name = "NativeEditorToolbarPlugin")
|
||||
class NativeEditorToolbarPlugin : Plugin() {
|
||||
private var toolbarView: EditorToolbarView? = null
|
||||
|
||||
@PluginMethod
|
||||
fun present(call: PluginCall) {
|
||||
val activity = activity ?: run {
|
||||
call.reject("No activity")
|
||||
return
|
||||
}
|
||||
|
||||
val actions = parseActions(call.getArray("actions"))
|
||||
val trailing = call.getObject("trailingAction")?.let { EditorAction.from(it) }
|
||||
val tintHex = call.getString("tintColor")
|
||||
val bgHex = call.getString("backgroundColor")
|
||||
|
||||
activity.runOnUiThread {
|
||||
if (actions.isEmpty() && trailing == null) {
|
||||
dismissInternal()
|
||||
call.resolve()
|
||||
return@runOnUiThread
|
||||
}
|
||||
|
||||
val view = toolbarView ?: EditorToolbarView(activity).also { v ->
|
||||
v.onAction = { id ->
|
||||
notifyListeners("action", JSObject().put("id", id))
|
||||
}
|
||||
toolbarView = v
|
||||
}
|
||||
|
||||
view.bind(actions, trailing, tintHex, bgHex)
|
||||
|
||||
val root = NativeUiUtils.contentRoot(activity)
|
||||
val margin = NativeUiUtils.dp(activity, 12f)
|
||||
if (view.parent !== root) {
|
||||
NativeUiUtils.detachView(view)
|
||||
val lp = FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
Gravity.BOTTOM
|
||||
).apply {
|
||||
setMargins(margin, margin, margin, margin)
|
||||
}
|
||||
root.addView(view, lp)
|
||||
}
|
||||
view.bindToKeyboardTop(root, margin)
|
||||
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun dismiss(call: PluginCall) {
|
||||
activity?.runOnUiThread {
|
||||
dismissInternal()
|
||||
call.resolve()
|
||||
} ?: call.resolve()
|
||||
}
|
||||
|
||||
private fun dismissInternal() {
|
||||
val root = activity?.let { NativeUiUtils.contentRoot(it) } ?: return
|
||||
toolbarView?.let {
|
||||
it.clearKeyboardTopBinding()
|
||||
root.removeView(it)
|
||||
}
|
||||
toolbarView = null
|
||||
}
|
||||
|
||||
private fun parseActions(array: JSArray?): List<EditorAction> {
|
||||
if (array == null) return emptyList()
|
||||
val result = mutableListOf<EditorAction>()
|
||||
for (i in 0 until array.length()) {
|
||||
val obj = array.optJSONObject(i) ?: continue
|
||||
EditorAction.from(obj)?.let { result.add(it) }
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
data class EditorAction(
|
||||
val id: String,
|
||||
val title: String,
|
||||
val systemIcon: String?
|
||||
) {
|
||||
companion object {
|
||||
fun from(obj: org.json.JSONObject): EditorAction? {
|
||||
val id = obj.optString("id", "")
|
||||
if (id.isBlank()) return null
|
||||
val title = obj.optString("title", id)
|
||||
val icon = if (obj.has("systemIcon") && !obj.isNull("systemIcon")) {
|
||||
obj.optString("systemIcon")
|
||||
} else {
|
||||
null
|
||||
}
|
||||
return EditorAction(id, title, icon)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class EditorToolbarView(context: android.content.Context) : FrameLayout(context) {
|
||||
var onAction: ((String) -> Unit)? = null
|
||||
|
||||
private val showAfterImeSettles = Runnable {
|
||||
pendingShowAfterImeSettles = null
|
||||
if (imeVisible && visibility != VISIBLE) {
|
||||
visibility = VISIBLE
|
||||
}
|
||||
}
|
||||
private var pendingShowAfterImeSettles: Runnable? = null
|
||||
private var imeVisible: Boolean = false
|
||||
|
||||
private val composeView = ComposeView(context).apply {
|
||||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
||||
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
|
||||
private var actions: List<EditorAction> = emptyList()
|
||||
private var trailing: EditorAction? = null
|
||||
private var tint: Int = defaultTint()
|
||||
private var backgroundColor: Int = defaultBackground()
|
||||
|
||||
init {
|
||||
visibility = GONE
|
||||
addView(composeView)
|
||||
}
|
||||
|
||||
fun bindToKeyboardTop(root: FrameLayout, margin: Int) {
|
||||
val decorView = root.rootView ?: root
|
||||
updateBottomMargin(margin)
|
||||
ViewCompat.setOnApplyWindowInsetsListener(this) { _, insets ->
|
||||
applyRootInsets(root, decorView, insets, margin)
|
||||
insets
|
||||
}
|
||||
root.post {
|
||||
ViewCompat.getRootWindowInsets(decorView)?.let { applyRootInsets(root, decorView, it, margin) }
|
||||
?: ViewCompat.getRootWindowInsets(root)?.let { applyRootInsets(root, decorView, it, margin) }
|
||||
ViewCompat.requestApplyInsets(this)
|
||||
}
|
||||
}
|
||||
|
||||
fun clearKeyboardTopBinding() {
|
||||
cancelPendingShow()
|
||||
imeVisible = false
|
||||
visibility = GONE
|
||||
ViewCompat.setOnApplyWindowInsetsListener(this, null)
|
||||
}
|
||||
|
||||
private fun applyRootInsets(
|
||||
root: FrameLayout,
|
||||
decorView: View,
|
||||
insets: WindowInsetsCompat,
|
||||
margin: Int
|
||||
) {
|
||||
val imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime())
|
||||
val navInsets = insets.getInsets(WindowInsetsCompat.Type.navigationBars())
|
||||
val imeVisible = insets.isVisible(WindowInsetsCompat.Type.ime())
|
||||
updateVisibilityForIme(imeVisible)
|
||||
val coveredBySystemUi = if (imeVisible) {
|
||||
bottomOverlap(root, decorView, imeInsets.bottom)
|
||||
} else {
|
||||
bottomOverlap(root, decorView, navInsets.bottom)
|
||||
}
|
||||
updateBottomMargin(coveredBySystemUi + margin)
|
||||
}
|
||||
|
||||
private fun updateVisibilityForIme(imeVisible: Boolean) {
|
||||
this.imeVisible = imeVisible
|
||||
if (!imeVisible) {
|
||||
cancelPendingShow()
|
||||
if (visibility != GONE) {
|
||||
visibility = GONE
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (visibility == VISIBLE) {
|
||||
return
|
||||
}
|
||||
|
||||
cancelPendingShow()
|
||||
pendingShowAfterImeSettles = showAfterImeSettles
|
||||
postDelayed(showAfterImeSettles, TOOLBAR_SHOW_DELAY_MS)
|
||||
}
|
||||
|
||||
private fun cancelPendingShow() {
|
||||
pendingShowAfterImeSettles?.let {
|
||||
removeCallbacks(it)
|
||||
pendingShowAfterImeSettles = null
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TOOLBAR_SHOW_DELAY_MS = 160L
|
||||
}
|
||||
|
||||
private fun bottomOverlap(root: View, decorView: View, bottomInset: Int): Int {
|
||||
if (bottomInset <= 0 || root.height <= 0) return 0
|
||||
|
||||
val decorHeight = decorView.height.takeIf { it > 0 } ?: root.rootView.height
|
||||
if (decorHeight <= 0) return bottomInset
|
||||
|
||||
val rootLocation = IntArray(2)
|
||||
val decorLocation = IntArray(2)
|
||||
root.getLocationInWindow(rootLocation)
|
||||
decorView.getLocationInWindow(decorLocation)
|
||||
|
||||
val rootBottomInWindow = rootLocation[1] + root.height
|
||||
val decorBottomInWindow = decorLocation[1] + decorHeight
|
||||
val insetTopInWindow = decorBottomInWindow - bottomInset
|
||||
|
||||
return (rootBottomInWindow - insetTopInWindow).coerceAtLeast(0)
|
||||
}
|
||||
|
||||
private fun updateBottomMargin(bottom: Int) {
|
||||
val lp = layoutParams as? LayoutParams ?: return
|
||||
if (lp.bottomMargin == bottom) return
|
||||
lp.bottomMargin = bottom
|
||||
layoutParams = lp
|
||||
}
|
||||
|
||||
fun bind(
|
||||
actions: List<EditorAction>,
|
||||
trailing: EditorAction?,
|
||||
tintHex: String?,
|
||||
bgHex: String?
|
||||
) {
|
||||
this.actions = actions
|
||||
this.trailing = trailing
|
||||
tint = NativeUiUtils.parseColor(tintHex, defaultTint())
|
||||
backgroundColor = NativeUiUtils.parseColor(bgHex, defaultBackground())
|
||||
render()
|
||||
}
|
||||
|
||||
private fun defaultTint(): Int =
|
||||
if (LogseqTheme.current().isDark) Color.WHITE else Color.BLACK
|
||||
|
||||
private fun defaultBackground(): Int = LogseqTheme.current().background
|
||||
|
||||
private fun render() {
|
||||
val onActionFn = onAction
|
||||
val actionsSnapshot = actions
|
||||
val trailingSnapshot = trailing
|
||||
val tintColor = tint
|
||||
val bgColor = backgroundColor
|
||||
|
||||
composeView.setContent {
|
||||
EditorToolbar(
|
||||
actions = actionsSnapshot,
|
||||
trailing = trailingSnapshot,
|
||||
tint = ComposeColor(tintColor),
|
||||
background = ComposeColor(bgColor),
|
||||
onAction = { id -> onActionFn?.invoke(id) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EditorToolbar(
|
||||
actions: List<EditorAction>,
|
||||
trailing: EditorAction?,
|
||||
tint: ComposeColor,
|
||||
background: ComposeColor,
|
||||
onAction: (String) -> Unit
|
||||
) {
|
||||
val borderColor = ComposeColor.Gray.copy(
|
||||
alpha = if (background.luminance() < 0.5f) 0.08f else 0.2f
|
||||
)
|
||||
|
||||
Surface(
|
||||
color = background,
|
||||
shadowElevation = 0.dp,
|
||||
border = BorderStroke(1.dp, borderColor),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 8.dp, vertical = 6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.horizontalScroll(rememberScrollState()),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
actions.forEach { action ->
|
||||
ToolbarButton(action, tint, onAction)
|
||||
}
|
||||
}
|
||||
|
||||
trailing?.let { trailingAction ->
|
||||
if (actions.isNotEmpty()) {
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
}
|
||||
ToolbarButton(trailingAction, tint, onAction)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ToolbarButton(
|
||||
action: EditorAction,
|
||||
tint: ComposeColor,
|
||||
onAction: (String) -> Unit
|
||||
) {
|
||||
val icon = remember(action.systemIcon) { MaterialIconResolver.resolve(action.systemIcon) }
|
||||
val contentTint = remember(tint) { tint.copy(alpha = 0.8f) }
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.defaultMinSize(minWidth = 44.dp)
|
||||
.clickable { onAction(action.id) }
|
||||
.padding(horizontal = 10.dp, vertical = 8.dp)
|
||||
) {
|
||||
if (icon != null) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = action.title.ifBlank { action.id },
|
||||
tint = contentTint,
|
||||
modifier = Modifier
|
||||
.defaultMinSize(minWidth = 20.dp)
|
||||
.padding(end = 2.dp)
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = action.title,
|
||||
color = contentTint,
|
||||
fontSize = 14.sp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
package com.logseq.app
|
||||
|
||||
import android.graphics.Color
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.defaultMinSize
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Divider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color as ComposeColor
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.core.view.doOnNextLayout
|
||||
import com.getcapacitor.JSArray
|
||||
import com.getcapacitor.JSObject
|
||||
import com.getcapacitor.Plugin
|
||||
import com.getcapacitor.PluginCall
|
||||
import com.getcapacitor.PluginMethod
|
||||
import com.getcapacitor.annotation.CapacitorPlugin
|
||||
import kotlin.math.max
|
||||
|
||||
@CapacitorPlugin(name = "NativeSelectionActionBarPlugin")
|
||||
class NativeSelectionActionBarPlugin : Plugin() {
|
||||
private var barView: SelectionActionBarView? = null
|
||||
|
||||
@PluginMethod
|
||||
fun present(call: PluginCall) {
|
||||
val activity = activity ?: run {
|
||||
call.reject("No activity")
|
||||
return
|
||||
}
|
||||
|
||||
val actionsArray = call.getArray("actions")
|
||||
val actions = parseActions(actionsArray)
|
||||
val tintHex = call.getString("tintColor")
|
||||
val bgHex = call.getString("backgroundColor")
|
||||
|
||||
activity.runOnUiThread {
|
||||
if (actions.isEmpty()) {
|
||||
dismissInternal()
|
||||
call.resolve()
|
||||
return@runOnUiThread
|
||||
}
|
||||
|
||||
val root = NativeUiUtils.contentRoot(activity)
|
||||
val view = barView ?: SelectionActionBarView(activity).also { v ->
|
||||
v.onAction = { id ->
|
||||
notifyListeners("action", JSObject().put("id", id))
|
||||
}
|
||||
barView = v
|
||||
}
|
||||
|
||||
view.bind(actions, tintHex, bgHex)
|
||||
|
||||
if (view.parent !== root) {
|
||||
NativeUiUtils.detachView(view)
|
||||
|
||||
val lp = FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.WRAP_CONTENT,
|
||||
Gravity.BOTTOM
|
||||
).apply {
|
||||
val margin = NativeUiUtils.dp(activity, 12f)
|
||||
val bottomOffset = computeBottomOffset(activity, root)
|
||||
// top / left / right: margin
|
||||
// bottom: margin + bottom nav height + system/IME inset
|
||||
setMargins(margin, margin, margin, margin + bottomOffset)
|
||||
}
|
||||
|
||||
root.addView(view, lp)
|
||||
}
|
||||
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun dismiss(call: PluginCall) {
|
||||
activity?.runOnUiThread {
|
||||
dismissInternal()
|
||||
call.resolve()
|
||||
} ?: call.resolve()
|
||||
}
|
||||
|
||||
private fun dismissInternal() {
|
||||
val activity = activity ?: return
|
||||
val root = NativeUiUtils.contentRoot(activity)
|
||||
|
||||
barView?.let { root.removeView(it) }
|
||||
barView = null
|
||||
}
|
||||
|
||||
private fun parseActions(array: JSArray?): List<SelectionAction> {
|
||||
if (array == null) return emptyList()
|
||||
val result = mutableListOf<SelectionAction>()
|
||||
for (i in 0 until array.length()) {
|
||||
val obj = array.optJSONObject(i) ?: continue
|
||||
SelectionAction.from(obj)?.let { result.add(it) }
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute how far we must lift the bar from the bottom so that it
|
||||
* sits above:
|
||||
* - the BottomNavigationView created by LiquidTabsPlugin
|
||||
* - system nav / gesture bar
|
||||
* - IME (when showing)
|
||||
*/
|
||||
private fun computeBottomOffset(activity: android.app.Activity, root: ViewGroup): Int {
|
||||
val insets = ViewCompat.getRootWindowInsets(root)
|
||||
val systemBarsBottom = insets?.getInsets(WindowInsetsCompat.Type.systemBars())?.bottom ?: 0
|
||||
val imeBottom = insets?.getInsets(WindowInsetsCompat.Type.ime())?.bottom ?: 0
|
||||
|
||||
// Find the bottom nav created by LiquidTabsPlugin (must have this ID set there)
|
||||
val bottomNav = activity.findViewById<View>(R.id.liquid_tabs_bottom_nav)
|
||||
// Fallback height if nav not measured yet
|
||||
val navHeight = bottomNav?.height ?: NativeUiUtils.dp(activity, 56f)
|
||||
|
||||
val insetBottom = max(systemBarsBottom, imeBottom)
|
||||
return navHeight + insetBottom
|
||||
}
|
||||
}
|
||||
|
||||
data class SelectionAction(
|
||||
val id: String,
|
||||
val title: String,
|
||||
val systemIcon: String?
|
||||
) {
|
||||
companion object {
|
||||
fun from(obj: org.json.JSONObject): SelectionAction? {
|
||||
val id = obj.optString("id", "")
|
||||
if (id.isBlank()) return null
|
||||
val title = obj.optString("title", id)
|
||||
val icon = obj.optString("systemIcon", null)
|
||||
return SelectionAction(id, title, icon)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class SelectionActionBarView(context: android.content.Context) : FrameLayout(context) {
|
||||
var onAction: ((String) -> Unit)? = null
|
||||
private val composeView: ComposeView
|
||||
|
||||
init {
|
||||
composeView = ComposeView(context).apply {
|
||||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
||||
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
addView(composeView)
|
||||
}
|
||||
|
||||
fun bind(actions: List<SelectionAction>, tintHex: String?, bgHex: String?) {
|
||||
val defaultTint = if (LogseqTheme.current().isDark) Color.WHITE else Color.BLACK
|
||||
val tint = ComposeColor(NativeUiUtils.parseColor(tintHex, defaultTint))
|
||||
val backgroundColor = ComposeColor(NativeUiUtils.parseColor(bgHex, LogseqTheme.current().background))
|
||||
val onActionFn = onAction
|
||||
|
||||
composeView.setContent {
|
||||
SelectionActionBar(actions, tint, backgroundColor) { id ->
|
||||
onActionFn?.invoke(id)
|
||||
}
|
||||
}
|
||||
composeView.doOnNextLayout { requestLayout() }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SelectionActionBar(
|
||||
actions: List<SelectionAction>,
|
||||
tint: ComposeColor,
|
||||
background: ComposeColor,
|
||||
onAction: (String) -> Unit
|
||||
) {
|
||||
val (mainActions, trailingAction) = remember(actions) {
|
||||
val primary = if (actions.size > 1) actions.dropLast(1) else emptyList()
|
||||
Pair(primary, actions.lastOrNull())
|
||||
}
|
||||
val scrollState = rememberScrollState()
|
||||
|
||||
Surface(
|
||||
color = background,
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
border = BorderStroke(1.dp, tint.copy(alpha = 0.05f))
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 12.dp, vertical = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
if (mainActions.isNotEmpty()) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.horizontalScroll(scrollState),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
||||
) {
|
||||
mainActions.forEach { action ->
|
||||
SelectionActionButton(action, tint, onAction)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trailingAction?.let { action ->
|
||||
if (mainActions.isNotEmpty()) {
|
||||
Spacer(modifier = Modifier.width(6.dp))
|
||||
Divider(
|
||||
modifier = Modifier
|
||||
.height(28.dp)
|
||||
.width(1.dp),
|
||||
color = tint.copy(alpha = 0.15f)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(6.dp))
|
||||
}
|
||||
SelectionActionButton(action, tint, onAction)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SelectionActionButton(
|
||||
action: SelectionAction,
|
||||
tint: ComposeColor,
|
||||
onAction: (String) -> Unit
|
||||
) {
|
||||
val icon = remember(action.systemIcon) { MaterialIconResolver.resolve(action.systemIcon) }
|
||||
val contentTint = remember(tint) { tint.copy(alpha = 0.8f) }
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(6.dp),
|
||||
modifier = Modifier
|
||||
.defaultMinSize(minWidth = 48.dp)
|
||||
.clickable { onAction(action.id) }
|
||||
.padding(horizontal = 4.dp, vertical = 8.dp)
|
||||
) {
|
||||
if (icon != null) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = action.title.ifBlank { action.id },
|
||||
tint = contentTint,
|
||||
modifier = Modifier.size(22.dp)
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = action.title,
|
||||
color = contentTint,
|
||||
fontSize = 12.sp,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
300
android/app/src/main/java/com/logseq/app/NativeTopBarPlugin.kt
Normal file
@@ -0,0 +1,300 @@
|
||||
package com.logseq.app
|
||||
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color as ComposeColor
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.ViewCompositionStrategy
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.core.view.doOnNextLayout
|
||||
import com.getcapacitor.JSArray
|
||||
import com.getcapacitor.JSObject
|
||||
import com.getcapacitor.Plugin
|
||||
import com.getcapacitor.PluginCall
|
||||
import com.getcapacitor.PluginMethod
|
||||
import com.getcapacitor.annotation.CapacitorPlugin
|
||||
|
||||
@CapacitorPlugin(name = "NativeTopBarPlugin")
|
||||
class NativeTopBarPlugin : Plugin() {
|
||||
private var topBarView: NativeTopBarView? = null
|
||||
|
||||
@PluginMethod
|
||||
fun configure(call: PluginCall) {
|
||||
val activity = activity ?: run {
|
||||
call.reject("No activity")
|
||||
return
|
||||
}
|
||||
|
||||
activity.runOnUiThread {
|
||||
val hidden = call.getBoolean("hidden") ?: false
|
||||
val title = call.getString("title") ?: ""
|
||||
val leftButtons = parseButtons(call.getArray("leftButtons"))
|
||||
val rightButtons = parseButtons(call.getArray("rightButtons"))
|
||||
val titleClickable = call.getBoolean("titleClickable") ?: false
|
||||
val tintHex = call.getString("tintColor")
|
||||
val tintColorOverride =
|
||||
tintHex?.takeIf { it.isNotBlank() }
|
||||
?.let { NativeUiUtils.parseColor(it, LogseqTheme.current().tint) }
|
||||
|
||||
if (hidden) {
|
||||
removeBar()
|
||||
call.resolve()
|
||||
return@runOnUiThread
|
||||
}
|
||||
|
||||
val bar = topBarView ?: NativeTopBarView(activity).also { view ->
|
||||
view.onTap = { id ->
|
||||
notifyListeners("buttonTapped", JSObject().put("id", id))
|
||||
}
|
||||
attachBar(view)
|
||||
topBarView = view
|
||||
}
|
||||
|
||||
bar.bind(title, titleClickable, leftButtons, rightButtons, tintColorOverride)
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
|
||||
private fun attachBar(bar: NativeTopBarView) {
|
||||
val root = NativeUiUtils.contentRoot(activity)
|
||||
if (bar.parent !== root) {
|
||||
NativeUiUtils.detachView(bar)
|
||||
val lp = ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
)
|
||||
root.addView(bar, lp)
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeBar() {
|
||||
val root = activity?.let { NativeUiUtils.contentRoot(it) } ?: return
|
||||
topBarView?.let { view ->
|
||||
root.removeView(view)
|
||||
}
|
||||
topBarView = null
|
||||
}
|
||||
|
||||
private fun parseButtons(array: JSArray?): List<ButtonSpec> {
|
||||
if (array == null) return emptyList()
|
||||
val result = mutableListOf<ButtonSpec>()
|
||||
for (i in 0 until array.length()) {
|
||||
val obj = array.optJSONObject(i) ?: continue
|
||||
val id = obj.optString("id", "")
|
||||
if (id.isBlank()) continue
|
||||
val systemIcon = obj.optString("systemIcon", "")
|
||||
val title = obj.optString("title", id)
|
||||
val tintHex = obj.optString("tintColor", obj.optString("color", ""))
|
||||
val iconSize = if (id == "sync") {
|
||||
"small"
|
||||
} else {
|
||||
"medium"
|
||||
}
|
||||
|
||||
val size = obj.optString("size", iconSize)
|
||||
result.add(
|
||||
ButtonSpec(
|
||||
id = id,
|
||||
title = if (title.isNotBlank()) title else id,
|
||||
systemIcon = systemIcon.takeIf { it.isNotBlank() },
|
||||
tint = tintHex,
|
||||
size = size
|
||||
)
|
||||
)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
data class ButtonSpec(
|
||||
val id: String,
|
||||
val title: String,
|
||||
val systemIcon: String?,
|
||||
val tint: String?,
|
||||
val size: String
|
||||
)
|
||||
|
||||
private class NativeTopBarView(context: android.content.Context) : FrameLayout(context) {
|
||||
var onTap: ((String) -> Unit)? = null
|
||||
private val composeView = ComposeView(context).apply {
|
||||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
|
||||
layoutParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
|
||||
init {
|
||||
addView(composeView)
|
||||
}
|
||||
|
||||
fun bind(
|
||||
title: String,
|
||||
titleClickable: Boolean,
|
||||
leftButtons: List<ButtonSpec>,
|
||||
rightButtons: List<ButtonSpec>,
|
||||
tintColorOverride: Int?
|
||||
) {
|
||||
val onTapFn = onTap
|
||||
composeView.setContent {
|
||||
TopBarContent(
|
||||
title = title,
|
||||
titleClickable = titleClickable,
|
||||
leftButtons = leftButtons,
|
||||
rightButtons = rightButtons,
|
||||
tintOverride = tintColorOverride,
|
||||
onTap = { id -> onTapFn?.invoke(id) }
|
||||
)
|
||||
}
|
||||
doOnNextLayout {
|
||||
requestLayout()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TopBarContent(
|
||||
title: String,
|
||||
titleClickable: Boolean,
|
||||
leftButtons: List<ButtonSpec>,
|
||||
rightButtons: List<ButtonSpec>,
|
||||
tintOverride: Int?,
|
||||
onTap: (String) -> Unit
|
||||
) {
|
||||
val theme by LogseqTheme.colors.collectAsState()
|
||||
val background = ComposeColor(theme.background)
|
||||
val tint = tintOverride?.let { ComposeColor(it) } ?: ComposeColor(theme.tint)
|
||||
val contentTint = tint.copy(alpha = 0.8f)
|
||||
|
||||
Surface(
|
||||
color = background,
|
||||
shadowElevation = 4.dp
|
||||
) {
|
||||
Column {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(min = 42.dp)
|
||||
.padding(start = 12.dp, end = 8.dp, top = 16.dp, bottom = 16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.weight(1f),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
leftButtons.forEachIndexed { index, button ->
|
||||
if (index > 0) {
|
||||
Spacer(modifier = Modifier.width(10.dp))
|
||||
}
|
||||
TopBarButton(button, contentTint, onTap)
|
||||
}
|
||||
}
|
||||
|
||||
Text(
|
||||
text = title,
|
||||
color = contentTint,
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 2.dp)
|
||||
.let { mod ->
|
||||
if (titleClickable) {
|
||||
mod.clickable { onTap("title") }
|
||||
} else {
|
||||
mod
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier.weight(1f),
|
||||
horizontalArrangement = Arrangement.End,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
rightButtons.forEachIndexed { index, button ->
|
||||
if (index > 0) {
|
||||
Spacer(modifier = Modifier.width(6.dp))
|
||||
}
|
||||
TopBarButton(button, contentTint, onTap)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HorizontalDivider(
|
||||
// thickness = 1.dp,
|
||||
// color = contentTint.copy(alpha = 0.28f)
|
||||
// )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TopBarButton(
|
||||
spec: ButtonSpec,
|
||||
fallbackTint: ComposeColor,
|
||||
onTap: (String) -> Unit
|
||||
) {
|
||||
val icon = remember(spec.systemIcon) { MaterialIconResolver.resolve(spec.systemIcon) }
|
||||
val baseTint = remember(spec.tint, fallbackTint) {
|
||||
spec.tint?.let { ComposeColor(NativeUiUtils.parseColor(it, fallbackTint.toArgb())) }
|
||||
?: fallbackTint
|
||||
}
|
||||
val tint = remember(baseTint) { baseTint.copy(alpha = 0.8f) }
|
||||
val fontSize = when (spec.size.lowercase()) {
|
||||
"small" -> 13.sp
|
||||
"large" -> 17.sp
|
||||
else -> 15.sp
|
||||
}
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.clickable { onTap(spec.id) }
|
||||
.padding(horizontal = 8.dp, vertical = 1.dp)
|
||||
) {
|
||||
if (icon != null) {
|
||||
val iconSize = when (spec.size.lowercase()) {
|
||||
"small" -> 12.dp
|
||||
else -> 22.dp
|
||||
}
|
||||
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = spec.title.ifBlank { spec.id },
|
||||
tint = tint,
|
||||
modifier = Modifier.size(iconSize)
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
text = spec.title,
|
||||
color = tint,
|
||||
fontSize = fontSize,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
android/app/src/main/java/com/logseq/app/NativeUiUtils.kt
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.logseq.app
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.FrameLayout
|
||||
|
||||
object NativeUiUtils {
|
||||
fun dp(context: Context, value: Float): Int =
|
||||
(value * context.resources.displayMetrics.density).toInt()
|
||||
|
||||
fun parseColor(hex: String?, defaultColor: Int): Int {
|
||||
if (hex.isNullOrBlank()) return defaultColor
|
||||
return try {
|
||||
Color.parseColor(hex)
|
||||
} catch (_: IllegalArgumentException) {
|
||||
defaultColor
|
||||
}
|
||||
}
|
||||
|
||||
fun contentRoot(activity: Activity): FrameLayout =
|
||||
activity.findViewById(android.R.id.content)
|
||||
|
||||
fun detachView(view: View?): ViewGroup? {
|
||||
val parent = view?.parent as? ViewGroup ?: return null
|
||||
parent.removeView(view)
|
||||
return parent
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
package com.logseq.app
|
||||
|
||||
import android.util.Log
|
||||
|
||||
data class NavigationRenderState(
|
||||
val previousStackId: String,
|
||||
val activeStackId: String,
|
||||
val paths: List<String>,
|
||||
val navigationType: String,
|
||||
val path: String,
|
||||
val stackSwitched: Boolean,
|
||||
val applyToCompose: Boolean = true
|
||||
)
|
||||
|
||||
private data class PendingNativePop(
|
||||
val stackId: String,
|
||||
val targetPath: String
|
||||
)
|
||||
|
||||
class NavigationCoordinator {
|
||||
companion object {
|
||||
private const val TAG = "NavStack"
|
||||
private const val DEBUG_PREFIX = "[DEBUG-navstack]"
|
||||
}
|
||||
|
||||
private val primaryStack = "home"
|
||||
private val stackPaths: MutableMap<String, MutableList<String>> = mutableMapOf(
|
||||
primaryStack to mutableListOf("/")
|
||||
)
|
||||
private val pendingNativePops: ArrayDeque<PendingNativePop> = ArrayDeque()
|
||||
var activeStackId: String = primaryStack
|
||||
private set
|
||||
|
||||
private fun rootPath(stack: String): String =
|
||||
if (stack == primaryStack) "/" else "/__stack__/$stack"
|
||||
|
||||
private fun normalizedPath(raw: String?): String =
|
||||
raw?.takeIf { it.isNotBlank() } ?: "/"
|
||||
|
||||
fun debugState(): String =
|
||||
"active=$activeStackId stacks=" + stackPaths.entries.joinToString(
|
||||
prefix = "{",
|
||||
postfix = "}"
|
||||
) { (stack, paths) -> "$stack=${paths.joinToString(prefix = "[", postfix = "]")}" }
|
||||
|
||||
private fun logDebug(message: String) {
|
||||
try {
|
||||
Log.d(TAG, message)
|
||||
} catch (_: RuntimeException) {
|
||||
// Local JVM unit tests do not provide android.util.Log.
|
||||
}
|
||||
}
|
||||
|
||||
private fun snapshot(
|
||||
previousStackId: String,
|
||||
navigationType: String,
|
||||
path: String,
|
||||
stackSwitched: Boolean,
|
||||
applyToCompose: Boolean = true
|
||||
): NavigationRenderState {
|
||||
val paths = stackPaths[activeStackId]?.toList() ?: listOf(rootPath(activeStackId))
|
||||
return NavigationRenderState(
|
||||
previousStackId = previousStackId,
|
||||
activeStackId = activeStackId,
|
||||
paths = paths,
|
||||
navigationType = navigationType,
|
||||
path = path,
|
||||
stackSwitched = stackSwitched,
|
||||
applyToCompose = applyToCompose
|
||||
)
|
||||
}
|
||||
|
||||
private fun consumePendingNativePop(stackId: String, path: String): Boolean {
|
||||
val pending = pendingNativePops.firstOrNull() ?: return false
|
||||
if (pending.stackId != stackId || pending.targetPath != path) {
|
||||
return false
|
||||
}
|
||||
pendingNativePops.removeFirst()
|
||||
logDebug(
|
||||
"$DEBUG_PREFIX coordinator.consumePendingNativePop stack=$stackId path=$path remaining=${pendingNativePops.size} ${debugState()}"
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
fun onRouteChange(stack: String?, navigationType: String?, path: String?): NavigationRenderState {
|
||||
val stackId = stack?.takeIf { it.isNotBlank() } ?: primaryStack
|
||||
val navType = navigationType?.lowercase() ?: "push"
|
||||
val resolvedPath = normalizedPath(path)
|
||||
val previousStackId = activeStackId
|
||||
|
||||
logDebug(
|
||||
"$DEBUG_PREFIX coordinator.onRouteChange.before stack=$stackId type=$navType path=$resolvedPath ${debugState()}"
|
||||
)
|
||||
|
||||
if (navType == "pop" && consumePendingNativePop(stackId, resolvedPath)) {
|
||||
activeStackId = stackId
|
||||
return snapshot(previousStackId, navType, resolvedPath, stackSwitched = false, applyToCompose = false)
|
||||
}
|
||||
|
||||
val paths = stackPaths.getOrPut(stackId) { mutableListOf(rootPath(stackId)) }
|
||||
|
||||
if (stackId != activeStackId) {
|
||||
val newPaths = paths.toMutableList()
|
||||
when {
|
||||
resolvedPath == rootPath(stackId) -> {
|
||||
newPaths.clear()
|
||||
newPaths.add(resolvedPath)
|
||||
}
|
||||
|
||||
navType == "reset" -> {
|
||||
newPaths.clear()
|
||||
newPaths.add(resolvedPath)
|
||||
}
|
||||
|
||||
stackId == primaryStack && resolvedPath == "/" -> {
|
||||
newPaths.clear()
|
||||
newPaths.add("/")
|
||||
}
|
||||
|
||||
newPaths.isEmpty() -> newPaths.add(resolvedPath)
|
||||
|
||||
navType == "push" && newPaths.last() != resolvedPath -> newPaths.add(resolvedPath)
|
||||
|
||||
newPaths.last() != resolvedPath -> newPaths[newPaths.lastIndex] = resolvedPath
|
||||
}
|
||||
|
||||
activeStackId = stackId
|
||||
stackPaths[stackId] = newPaths
|
||||
|
||||
logDebug(
|
||||
"$DEBUG_PREFIX coordinator.onRouteChange.after stack=$stackId type=$navType path=$resolvedPath ${debugState()} canPop=${canPop()} stackSwitched=true"
|
||||
)
|
||||
|
||||
return snapshot(previousStackId, navType, resolvedPath, stackSwitched = true)
|
||||
}
|
||||
|
||||
when (navType) {
|
||||
"reset" -> {
|
||||
paths.clear()
|
||||
paths.add(resolvedPath)
|
||||
}
|
||||
|
||||
"replace" -> {
|
||||
if (paths.isEmpty()) {
|
||||
paths.add(resolvedPath)
|
||||
} else {
|
||||
paths[paths.lastIndex] = resolvedPath
|
||||
}
|
||||
}
|
||||
|
||||
"pop" -> {
|
||||
if (paths.size > 1) {
|
||||
paths.removeAt(paths.lastIndex)
|
||||
}
|
||||
}
|
||||
|
||||
else -> { // push (default)
|
||||
if (paths.isEmpty()) {
|
||||
paths.add(resolvedPath)
|
||||
} else if (paths.last() != resolvedPath) {
|
||||
paths.add(resolvedPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (navType != "push" && resolvedPath == rootPath(stackId)) {
|
||||
paths.clear()
|
||||
paths.add(resolvedPath)
|
||||
}
|
||||
|
||||
activeStackId = stackId
|
||||
stackPaths[stackId] = paths
|
||||
|
||||
logDebug(
|
||||
"$DEBUG_PREFIX coordinator.onRouteChange.after stack=$stackId type=$navType path=$resolvedPath ${debugState()} canPop=${canPop()}"
|
||||
)
|
||||
|
||||
return snapshot(previousStackId, navType, resolvedPath, stackSwitched = false)
|
||||
}
|
||||
|
||||
fun canPop(): Boolean {
|
||||
val paths = stackPaths[activeStackId] ?: return false
|
||||
return paths.size > 1
|
||||
}
|
||||
|
||||
fun prepareNativePop(): NavigationRenderState? {
|
||||
val paths = stackPaths[activeStackId] ?: return null
|
||||
if (paths.size <= 1) return null
|
||||
paths.removeAt(paths.lastIndex)
|
||||
val target = paths.lastOrNull() ?: return null
|
||||
pendingNativePops.addLast(PendingNativePop(activeStackId, target))
|
||||
logDebug(
|
||||
"$DEBUG_PREFIX coordinator.prepareNativePop stack=$activeStackId target=$target pending=${pendingNativePops.size} ${debugState()} canPop=${canPop()}"
|
||||
)
|
||||
return snapshot(
|
||||
previousStackId = activeStackId,
|
||||
navigationType = "pop",
|
||||
path = target,
|
||||
stackSwitched = false,
|
||||
applyToCompose = true
|
||||
)
|
||||
}
|
||||
}
|
||||
146
android/app/src/main/java/com/logseq/app/UILocal.kt
Normal file
@@ -0,0 +1,146 @@
|
||||
package com.logseq.app
|
||||
|
||||
import android.app.DatePickerDialog
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import com.getcapacitor.JSObject
|
||||
import com.getcapacitor.Plugin
|
||||
import com.getcapacitor.PluginCall
|
||||
import com.getcapacitor.PluginMethod
|
||||
import com.getcapacitor.annotation.CapacitorPlugin
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Calendar
|
||||
import java.util.Locale
|
||||
|
||||
@CapacitorPlugin(name = "UILocal")
|
||||
class UILocal : Plugin() {
|
||||
private var toast: Toast? = null
|
||||
companion object {
|
||||
const val ACTION_ROUTE_CHANGED = "com.logseq.app.ROUTE_DID_CHANGE"
|
||||
private const val DEBUG_PREFIX = "[DEBUG-navstack]"
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun showDatePicker(call: PluginCall) {
|
||||
val defaultDate = call.getString("defaultDate")
|
||||
val calendar = Calendar.getInstance()
|
||||
|
||||
if (!defaultDate.isNullOrEmpty()) {
|
||||
try {
|
||||
val sdf = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
||||
val date = sdf.parse(defaultDate)
|
||||
if (date != null) {
|
||||
calendar.time = date
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
call.reject("Invalid default date format. Use YYYY-MM-DD", e)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
val year = calendar.get(Calendar.YEAR)
|
||||
val month = calendar.get(Calendar.MONTH)
|
||||
val day = calendar.get(Calendar.DAY_OF_MONTH)
|
||||
|
||||
// create date picker dialog
|
||||
val datePickerDialog = DatePickerDialog(
|
||||
activity,
|
||||
null,
|
||||
year, month, day
|
||||
)
|
||||
|
||||
datePickerDialog.datePicker.init(year, month, day) { _, selectedYear: Int, selectedMonth: Int, selectedDay: Int ->
|
||||
// format selected date
|
||||
val selectedDate = Calendar.getInstance().apply {
|
||||
set(selectedYear, selectedMonth, selectedDay)
|
||||
}
|
||||
|
||||
val sdf = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
|
||||
val formattedDate = sdf.format(selectedDate.time)
|
||||
|
||||
// return to js
|
||||
val res = JSObject()
|
||||
res.put("value", formattedDate)
|
||||
call.resolve(res)
|
||||
|
||||
// close dialog
|
||||
datePickerDialog.dismiss()
|
||||
}
|
||||
|
||||
datePickerDialog.setOnShowListener {
|
||||
val parent = datePickerDialog.getButton(DatePickerDialog.BUTTON_POSITIVE).parent.parent
|
||||
if (parent is ViewGroup) {
|
||||
parent.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
|
||||
if (call.getBoolean("restrictFuture", false) == true) {
|
||||
datePickerDialog.datePicker.maxDate = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
try {
|
||||
datePickerDialog.show()
|
||||
} catch (e: Exception) {
|
||||
call.reject("Error showing date picker", e)
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun alert(call: PluginCall) {
|
||||
val message = call.getString("title") ?: call.getString("message")
|
||||
val duration = if ((call.getDouble("duration") ?: 0.0) > 3.5) Toast.LENGTH_LONG else Toast.LENGTH_SHORT
|
||||
val ctx = context ?: run {
|
||||
call.reject("No context")
|
||||
return
|
||||
}
|
||||
if (message.isNullOrBlank()) {
|
||||
call.reject("title or message is required")
|
||||
return
|
||||
}
|
||||
toast?.cancel()
|
||||
toast = Toast.makeText(ctx, message, duration).also { it.show() }
|
||||
call.resolve()
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun hideAlert(call: PluginCall) {
|
||||
toast?.cancel()
|
||||
toast = null
|
||||
call.resolve()
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun routeDidChange(call: PluginCall) {
|
||||
val navigationType = call.getString("navigationType") ?: "push"
|
||||
val push = call.getBoolean("push") ?: (navigationType == "push")
|
||||
val path = call.getString("path") ?: "/"
|
||||
val stack = call.getString("stack") ?: "home"
|
||||
|
||||
Log.d(
|
||||
"NavStack",
|
||||
"$DEBUG_PREFIX uiLocal.routeDidChange stack=$stack type=$navigationType push=$push path=$path"
|
||||
)
|
||||
|
||||
|
||||
val ctx = context
|
||||
if (ctx != null) {
|
||||
val intent = Intent(ACTION_ROUTE_CHANGED).apply {
|
||||
putExtra("navigationType", navigationType)
|
||||
putExtra("push", push)
|
||||
putExtra("stack", stack)
|
||||
putExtra("path", path)
|
||||
}
|
||||
ctx.sendBroadcast(intent)
|
||||
}
|
||||
|
||||
call.resolve()
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun transcribeAudio2Text(call: PluginCall) {
|
||||
call.reject("transcription not supported on Android")
|
||||
}
|
||||
}
|
||||
38
android/app/src/main/java/com/logseq/app/Utils.kt
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.logseq.app
|
||||
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import com.getcapacitor.Plugin
|
||||
import com.getcapacitor.PluginCall
|
||||
import com.getcapacitor.PluginMethod
|
||||
import com.getcapacitor.annotation.CapacitorPlugin
|
||||
|
||||
@CapacitorPlugin(name = "Utils")
|
||||
class Utils : Plugin() {
|
||||
@PluginMethod
|
||||
fun setInterfaceStyle(call: PluginCall) {
|
||||
val mode = (call.getString("mode") ?: "system").lowercase()
|
||||
val system = call.getBoolean("system") ?: (mode == "system")
|
||||
|
||||
val nightMode =
|
||||
if (system || mode == "system") {
|
||||
AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
} else if (mode == "dark") {
|
||||
AppCompatDelegate.MODE_NIGHT_YES
|
||||
} else {
|
||||
AppCompatDelegate.MODE_NIGHT_NO
|
||||
}
|
||||
|
||||
val activity = activity
|
||||
if (activity == null) {
|
||||
call.reject("No activity")
|
||||
return
|
||||
}
|
||||
|
||||
activity.runOnUiThread {
|
||||
AppCompatDelegate.setDefaultNightMode(nightMode)
|
||||
(activity as? MainActivity)?.applyLogseqThemeNow()
|
||||
call.resolve()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.logseq.app
|
||||
|
||||
import android.app.Activity
|
||||
import android.graphics.Rect
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewTreeObserver
|
||||
import android.webkit.WebView
|
||||
import android.widget.FrameLayout
|
||||
import androidx.core.view.ViewCompat
|
||||
import java.util.WeakHashMap
|
||||
|
||||
/**
|
||||
* Defensive recovery for Android WebView/IME interactions.
|
||||
*
|
||||
* In this app the Capacitor WebView is re-parented into a Compose host. On some
|
||||
* Android/WebView combinations, focusing an input while the IME is shown can
|
||||
* leave the native WebView host chain panned/resized after the IME hides. The
|
||||
* web content itself may remain scrolled, which is valid; this class only resets
|
||||
* native view/container state that should always return to full-screen.
|
||||
*/
|
||||
object WebViewKeyboardRecovery {
|
||||
private val listeners = WeakHashMap<Activity, ViewTreeObserver.OnGlobalLayoutListener>()
|
||||
|
||||
@JvmStatic
|
||||
fun install(activity: Activity, webView: WebView) {
|
||||
if (listeners.containsKey(activity)) return
|
||||
|
||||
val content = activity.findViewById<FrameLayout>(android.R.id.content) ?: return
|
||||
val root = content.rootView ?: content
|
||||
val keyboardThreshold = NativeUiUtils.dp(activity, 120f)
|
||||
var wasKeyboardVisible = isKeyboardVisible(root, keyboardThreshold)
|
||||
|
||||
val listener = ViewTreeObserver.OnGlobalLayoutListener {
|
||||
val keyboardVisible = isKeyboardVisible(root, keyboardThreshold)
|
||||
if (wasKeyboardVisible && !keyboardVisible) {
|
||||
recoverAfterKeyboardHidden(activity, content, webView)
|
||||
}
|
||||
wasKeyboardVisible = keyboardVisible
|
||||
}
|
||||
|
||||
listeners[activity] = listener
|
||||
content.viewTreeObserver.addOnGlobalLayoutListener(listener)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun uninstall(activity: Activity) {
|
||||
val listener = listeners.remove(activity) ?: return
|
||||
val content = activity.findViewById<FrameLayout>(android.R.id.content) ?: return
|
||||
if (content.viewTreeObserver.isAlive) {
|
||||
content.viewTreeObserver.removeOnGlobalLayoutListener(listener)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isKeyboardVisible(root: View, thresholdPx: Int): Boolean {
|
||||
if (root.height <= 0) return false
|
||||
|
||||
val visibleFrame = Rect()
|
||||
root.getWindowVisibleDisplayFrame(visibleFrame)
|
||||
val coveredHeight = root.height - visibleFrame.bottom
|
||||
return coveredHeight > thresholdPx
|
||||
}
|
||||
|
||||
private fun recoverAfterKeyboardHidden(
|
||||
activity: Activity,
|
||||
content: FrameLayout,
|
||||
webView: WebView
|
||||
) {
|
||||
longArrayOf(0L, 80L, 240L).forEach { delay ->
|
||||
content.postDelayed({
|
||||
resetNativeHostState(content, webView)
|
||||
ViewCompat.requestApplyInsets(activity.window.decorView)
|
||||
ViewCompat.requestApplyInsets(content)
|
||||
ViewCompat.requestApplyInsets(webView)
|
||||
}, delay)
|
||||
}
|
||||
}
|
||||
|
||||
private fun resetNativeHostState(content: FrameLayout, webView: WebView) {
|
||||
content.translationY = 0f
|
||||
content.scrollTo(0, 0)
|
||||
|
||||
var current: View? = webView
|
||||
while (current != null) {
|
||||
current.translationY = 0f
|
||||
|
||||
if (current !== webView && current is ViewGroup) {
|
||||
current.scrollTo(0, 0)
|
||||
}
|
||||
|
||||
resetLayoutParamsIfWebViewHost(current, webView)
|
||||
current.requestLayout()
|
||||
current.invalidate()
|
||||
|
||||
if (current === content) break
|
||||
current = current.parent as? View
|
||||
}
|
||||
}
|
||||
|
||||
private fun resetLayoutParamsIfWebViewHost(view: View, webView: WebView) {
|
||||
val shouldFillParent = view === webView ||
|
||||
view.id == R.id.webview_container ||
|
||||
view.tag == "compose-host-webview"
|
||||
|
||||
if (!shouldFillParent) return
|
||||
|
||||
val lp = view.layoutParams ?: return
|
||||
var changed = false
|
||||
if (lp.width != ViewGroup.LayoutParams.MATCH_PARENT) {
|
||||
lp.width = ViewGroup.LayoutParams.MATCH_PARENT
|
||||
changed = true
|
||||
}
|
||||
if (lp.height != ViewGroup.LayoutParams.MATCH_PARENT) {
|
||||
lp.height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||
changed = true
|
||||
}
|
||||
if (changed) {
|
||||
view.layoutParams = lp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
package com.logseq.app
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.graphics.Rect
|
||||
import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.PixelCopy
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageView
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
/**
|
||||
* Utility to capture lightweight WebView snapshots and show them in the overlay container.
|
||||
* Used to keep the background stable while the shared WebView is being reparented
|
||||
* (navigation transitions, bottom sheet presentation/dismiss).
|
||||
*/
|
||||
object WebViewSnapshotManager {
|
||||
private var overlayRef: WeakReference<FrameLayout>? = null
|
||||
private var windowRef: WeakReference<Window>? = null
|
||||
private val snapshotRefs: MutableMap<String, WeakReference<View>> = mutableMapOf()
|
||||
private val containerRefs: MutableMap<String, WeakReference<FrameLayout>> = mutableMapOf()
|
||||
private var snapshotBackgroundColor: Int = LogseqTheme.current().background
|
||||
private val mainHandler = Handler(Looper.getMainLooper())
|
||||
|
||||
fun setSnapshotBackgroundColor(color: Int) {
|
||||
snapshotBackgroundColor = color
|
||||
overlayRef?.get()?.setBackgroundColor(Color.TRANSPARENT)
|
||||
}
|
||||
|
||||
fun registerWindow(window: Window?) {
|
||||
windowRef = window?.let { WeakReference(it) }
|
||||
}
|
||||
|
||||
fun registerOverlay(overlay: FrameLayout?) {
|
||||
overlayRef = overlay?.let { WeakReference(it) }
|
||||
}
|
||||
|
||||
fun showSnapshot(tag: String, webView: View): View? {
|
||||
val overlay = ensureOverlay(webView) ?: return null
|
||||
clearSnapshot(tag)
|
||||
overlay.isClickable = true
|
||||
overlay.visibility = View.VISIBLE
|
||||
|
||||
val snapshotView = makeSnapshotView(webView)
|
||||
|
||||
overlay.addView(
|
||||
snapshotView,
|
||||
FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
)
|
||||
overlay.bringChildToFront(snapshotView)
|
||||
|
||||
snapshotRefs[tag] = WeakReference(snapshotView)
|
||||
containerRefs[tag] = WeakReference(overlay)
|
||||
|
||||
return snapshotView
|
||||
}
|
||||
|
||||
fun clearSnapshot(tag: String) {
|
||||
val view = snapshotRefs.remove(tag)?.get()
|
||||
val container = containerRefs.remove(tag)?.get()
|
||||
if (view != null && container != null) {
|
||||
container.removeView(view)
|
||||
if (container.childCount == 0) {
|
||||
container.isClickable = false
|
||||
container.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun clearAll() {
|
||||
snapshotRefs.keys.toList().forEach { clearSnapshot(it) }
|
||||
}
|
||||
|
||||
private fun ensureOverlay(webView: View): FrameLayout? {
|
||||
overlayRef?.get()?.let { return it }
|
||||
val root = webView.rootView
|
||||
val overlay = root.findViewById<FrameLayout>(R.id.webview_overlay_container)
|
||||
if (overlay != null) {
|
||||
overlayRef = WeakReference(overlay)
|
||||
}
|
||||
return overlay
|
||||
}
|
||||
|
||||
private fun makeSnapshotView(webView: View): View {
|
||||
val width = webView.width
|
||||
val height = webView.height
|
||||
if (width <= 0 || height <= 0) {
|
||||
return View(webView.context).apply {
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
setBackgroundColor(snapshotBackgroundColor)
|
||||
isClickable = false
|
||||
isFocusable = false
|
||||
}
|
||||
}
|
||||
|
||||
// Limit bitmap size to avoid OOM (e.g., max 4096x4096 or 16MB)
|
||||
val MAX_BITMAP_DIMENSION = 4096
|
||||
val MAX_BITMAP_SIZE = 16 * 1024 * 1024 // 16MB
|
||||
val safeWidth = width.coerceAtMost(MAX_BITMAP_DIMENSION)
|
||||
val safeHeight = height.coerceAtMost(MAX_BITMAP_DIMENSION)
|
||||
val estimatedSize = safeWidth * safeHeight * 4
|
||||
if (estimatedSize > MAX_BITMAP_SIZE) {
|
||||
// Fallback: show plain color view if too large
|
||||
return View(webView.context).apply {
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
setBackgroundColor(snapshotBackgroundColor)
|
||||
isClickable = false
|
||||
isFocusable = false
|
||||
}
|
||||
}
|
||||
|
||||
val bitmap = try {
|
||||
Bitmap.createBitmap(safeWidth, safeHeight, Bitmap.Config.ARGB_8888)
|
||||
} catch (e: OutOfMemoryError) {
|
||||
// Fallback: show plain color view if OOM
|
||||
return View(webView.context).apply {
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
setBackgroundColor(snapshotBackgroundColor)
|
||||
isClickable = false
|
||||
isFocusable = false
|
||||
}
|
||||
}
|
||||
// Fast fallback: capture via View#draw (can be imperfect for WebView on some devices).
|
||||
try {
|
||||
val canvas = Canvas(bitmap)
|
||||
canvas.drawColor(snapshotBackgroundColor)
|
||||
// If we had to scale down, scale the canvas
|
||||
if (safeWidth != width || safeHeight != height) {
|
||||
val scaleX = safeWidth.toFloat() / width
|
||||
val scaleY = safeHeight.toFloat() / height
|
||||
canvas.scale(scaleX, scaleY)
|
||||
}
|
||||
webView.draw(canvas)
|
||||
} catch (_: Exception) {
|
||||
// Keep bitmap with background color only.
|
||||
}
|
||||
|
||||
val imageView = ImageView(webView.context).apply {
|
||||
setImageBitmap(bitmap)
|
||||
scaleType = ImageView.ScaleType.FIT_XY
|
||||
layoutParams = FrameLayout.LayoutParams(
|
||||
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||
FrameLayout.LayoutParams.MATCH_PARENT
|
||||
)
|
||||
setBackgroundColor(snapshotBackgroundColor)
|
||||
isClickable = false
|
||||
isFocusable = false
|
||||
}
|
||||
|
||||
// Higher-fidelity capture: PixelCopy from the Window buffer.
|
||||
val window = windowRef?.get()
|
||||
if (window != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
try {
|
||||
val loc = IntArray(2)
|
||||
webView.getLocationInWindow(loc)
|
||||
val rect = Rect(loc[0], loc[1], loc[0] + width, loc[1] + height)
|
||||
|
||||
PixelCopy.request(window, rect, bitmap, { result ->
|
||||
if (result == PixelCopy.SUCCESS) {
|
||||
imageView.invalidate()
|
||||
}
|
||||
}, mainHandler)
|
||||
} catch (_: Exception) {
|
||||
// Ignore; fallback bitmap already set.
|
||||
}
|
||||
}
|
||||
|
||||
return imageView
|
||||
}
|
||||
}
|
||||
12
android/app/src/main/res/anim/byebye.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:zAdjustment="top">
|
||||
<translate android:fromYDelta="0" android:toYDelta="5%p"
|
||||
android:duration="250"
|
||||
android:interpolator="@android:interpolator/fast_out_slow_in"/>
|
||||
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
|
||||
android:fillEnabled="true" android:fillBefore="true" android:fillAfter="true"
|
||||
android:startOffset="100" android:duration="150"
|
||||
android:interpolator="@android:interpolator/fast_out_slow_in" />
|
||||
</set>
|
||||
BIN
android/app/src/main/res/drawable-land-hdpi/splash.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
android/app/src/main/res/drawable-land-ldpi/splash.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
android/app/src/main/res/drawable-land-mdpi/splash.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
android/app/src/main/res/drawable-land-night-hdpi/splash.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
android/app/src/main/res/drawable-land-night-ldpi/splash.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
android/app/src/main/res/drawable-land-night-mdpi/splash.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
android/app/src/main/res/drawable-land-night-xhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 74 KiB |
BIN
android/app/src/main/res/drawable-land-night-xxhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
android/app/src/main/res/drawable-land-night-xxxhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 141 KiB |
BIN
android/app/src/main/res/drawable-land-xhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 74 KiB |
BIN
android/app/src/main/res/drawable-land-xxhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 104 KiB |
BIN
android/app/src/main/res/drawable-land-xxxhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 141 KiB |
BIN
android/app/src/main/res/drawable-night/splash.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
android/app/src/main/res/drawable-port-hdpi/splash.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
android/app/src/main/res/drawable-port-ldpi/splash.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
android/app/src/main/res/drawable-port-mdpi/splash.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
android/app/src/main/res/drawable-port-night-hdpi/splash.png
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
android/app/src/main/res/drawable-port-night-ldpi/splash.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
android/app/src/main/res/drawable-port-night-mdpi/splash.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
android/app/src/main/res/drawable-port-night-xhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 74 KiB |
BIN
android/app/src/main/res/drawable-port-night-xxhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 102 KiB |
BIN
android/app/src/main/res/drawable-port-night-xxxhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 141 KiB |
BIN
android/app/src/main/res/drawable-port-xhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 74 KiB |
BIN
android/app/src/main/res/drawable-port-xxhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 102 KiB |
BIN
android/app/src/main/res/drawable-port-xxxhdpi/splash.png
Normal file
|
After Width: | Height: | Size: 141 KiB |
@@ -0,0 +1,34 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="78.5885"
|
||||
android:endY="90.9159"
|
||||
android:startX="48.7653"
|
||||
android:startY="61.0927"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0" />
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0" />
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1" />
|
||||
</vector>
|
||||
170
android/app/src/main/res/drawable/ic_launcher_background.xml
Normal file
@@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillColor="#26A69A"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8" />
|
||||
</vector>
|
||||
15
android/app/src/main/res/drawable/ic_search_clear.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="18dp"
|
||||
android:height="18dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#A68E8E93"
|
||||
android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2z" />
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M15.59,16.59 12,13 8.41,16.59 7,15.17 10.59,11.59 7,8 8.41,6.59 12,10.17 15.59,6.59 17,8 13.41,11.59 17,15.17z" />
|
||||
</vector>
|
||||
|
||||
|
||||
14
android/app/src/main/res/drawable/ic_tab_flashcards.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="960"
|
||||
android:viewportHeight="960">
|
||||
<group android:translateY="960">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="m608,-368l46,-166 -142,-98 -46,166 142,98ZM160,-207l-33,-16q-31,-13 -42,-44.5t3,-62.5l72,-156v279ZM320,-120q-33,0 -56.5,-24T240,-201v-239l107,294q3,7 5,13.5t7,12.5h-39ZM526,-125q-31,11 -62,-3t-42,-45L245,-662q-11,-31 3,-61.5t45,-41.5l301,-110q31,-11 61.5,3t41.5,45l178,489q11,31 -3,61.5T827,-235L526,-125ZM498,-200l302,-110 -179,-490 -301,110 178,490ZM560,-500Z" />
|
||||
</group>
|
||||
</vector>
|
||||
|
||||
|
||||
BIN
android/app/src/main/res/drawable/splash.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
6
android/app/src/main/res/drawable/splash_centered.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@color/logoPrimary" />
|
||||
<item android:drawable="@drawable/splash" android:gravity="center" />
|
||||
</layer-list>
|
||||
|
||||
12
android/app/src/main/res/layout/activity_main.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<WebView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background>
|
||||
<inset android:drawable="@mipmap/ic_launcher_background" android:inset="16.7%" />
|
||||
</background>
|
||||
<foreground>
|
||||
<inset android:drawable="@mipmap/ic_launcher_foreground" android:inset="16.7%" />
|
||||
</foreground>
|
||||
</adaptive-icon>
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background>
|
||||
<inset android:drawable="@mipmap/ic_launcher_background" android:inset="16.7%" />
|
||||
</background>
|
||||
<foreground>
|
||||
<inset android:drawable="@mipmap/ic_launcher_foreground" android:inset="16.7%" />
|
||||
</foreground>
|
||||
</adaptive-icon>
|
||||
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher_background.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher_monochrome.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
android/app/src/main/res/mipmap-ldpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 691 B |
BIN
android/app/src/main/res/mipmap-ldpi/ic_launcher_background.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
android/app/src/main/res/mipmap-ldpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
android/app/src/main/res/mipmap-ldpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher_background.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher_monochrome.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher_background.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher_monochrome.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 5.0 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 8.2 KiB |
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 7.1 KiB |
|
After Width: | Height: | Size: 6.3 KiB |
|
After Width: | Height: | Size: 6.3 KiB |
|
After Width: | Height: | Size: 10 KiB |
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 8.1 KiB |
8
android/app/src/main/res/values/colors.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="logoPrimary">#0f262e</color>
|
||||
<!-- Main brand color (HSL 200 97% 37%) -->
|
||||
<color name="colorPrimary">#037DBA</color>
|
||||
<color name="colorAccent">#6097c7</color>
|
||||
<color name="colorPrimaryDark">#0f262e</color>
|
||||
</resources>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="ic_launcher_background">#FFFFFF</color>
|
||||
</resources>
|
||||
5
android/app/src/main/res/values/ids.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<resources>
|
||||
<item name="webview_container" type="id"/>
|
||||
<item name="webview_overlay_container" type="id"/>
|
||||
<item name="liquid_tabs_bottom_nav" type="id"/>
|
||||
</resources>
|
||||