Skip to content

Commit

Permalink
Make standalone mode optional
Browse files Browse the repository at this point in the history
  • Loading branch information
daya0576 committed Oct 26, 2024
1 parent 148cc94 commit 6706d49
Show file tree
Hide file tree
Showing 6 changed files with 414 additions and 394 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,4 @@ test.db
.user/
screenshots/
tags
.env
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ docker run -d --name beaverhabits \

Options:

| Name | Description |
|:---------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **HABITS_STORAGE**(str) | The `DATABASE` option stores everything in a single SQLite database file named habits.db. On the other hand, the `USER_DISK` option saves habits and records in a local json file. |
| **FIRST_DAY_OF_WEEK**(int) | By default, the first day of the week is set as Monday. To change it to Sunday, you can set it as `6`. |
| **MAX_USER_COUNT**(int) | By setting it to `1`, you can prevent others from signing up in the future. |
| **ENABLE_PWA**(bool) | Experiential feature to support PWA, such as enabling standalone mode on iOS. The default setting is `ture` |
| Name | Description |
|:--------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **HABITS_STORAGE**(str) | The `DATABASE` option stores everything in a single SQLite database file named habits.db. On the other hand, the `USER_DISK` option saves habits and records in a local json file. |
| **FIRST_DAY_OF_WEEK**(int) | By default, the first day of the week is set as Monday. To change it to Sunday, you can set it as `6`. |
| **MAX_USER_COUNT**(int) | By setting it to `1`, you can prevent others from signing up in the future. |
| **ENABLE_IOS_STANDALONE**(bool) | Experiential feature to enable standalone mode on iOS. The default setting is `false` |

# Features

1. Pages
- [x] Index page
- [x] Habit list page
- [x] Order habits
- [x] Habit detail page
- [x] Calendar
- [x] Streaks
Expand Down Expand Up @@ -76,8 +77,13 @@ Here are my table tennis training sessions in the past year :)
To import from an existing setup, e.g. uhabit, please check this [wiki](https://github.com/daya0576/beaverhabits/wiki/Import-from-Existing-Setup) for more details.

## Standalone mode for iOS (Web Application)

Follow this [wiki](https://github.com/daya0576/beaverhabits/wiki/To-Add-Standalone-Mode-for-iOS-(Web-Application)) to add it as an icon on the home screen and make it launch in a separate window

## Order Habits

Open page `/gui/order` to change the order of habits.

# Future Plans

1. Native mobile app
Expand Down
2 changes: 1 addition & 1 deletion beaverhabits/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Settings(BaseSettings):

# Customization
FIRST_DAY_OF_WEEK: int = calendar.MONDAY
ENABLE_PWA: bool = True
ENABLE_IOS_STANDALONE: bool = False

def is_dev(self):
return self.ENV == "dev"
Expand Down
12 changes: 4 additions & 8 deletions beaverhabits/frontend/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def custom_header():
'<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">'
)
ui.add_head_html('<meta name="apple-mobile-web-app-title" content="Beaver">')
ui.add_head_html('<meta name="apple-mobile-web-app-capable" content="yes">')
ui.add_head_html(
'<meta name="apple-mobile-web-app-status-bar-style" content="black">'
)
Expand All @@ -26,10 +25,9 @@ def custom_header():
'<link rel="apple-touch-icon" href="/statics/images/apple-touch-icon-v4.png">'
)

ui.add_head_html('<link rel="manifest" href="/statics/pwa/manifest.json">')
ui.add_head_html(
'<script>if(navigator.standalone === true) { navigator.serviceWorker.register("/statics/pwa/service_worker.js"); };</script>'
)
# Experimental PWA support
if settings.ENABLE_IOS_STANDALONE:
ui.add_head_html('<meta name="apple-mobile-web-app-capable" content="yes">')


def menu_component(root_path: str) -> None:
Expand Down Expand Up @@ -61,9 +59,7 @@ def layout(title: str | None = None, with_menu: bool = True):
root_path = get_root_path()
title = title or get_page_title(root_path)
with ui.column().classes("max-w-sm mx-auto sm:mx-0"):
# Experimental PWA support
if settings.ENABLE_PWA:
custom_header()
custom_header()

with ui.row().classes("min-w-full"):
menu_header(title, target=root_path)
Expand Down
Loading

0 comments on commit 6706d49

Please sign in to comment.