-
-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add tauri support #213
base: master
Are you sure you want to change the base?
add tauri support #213
Conversation
WalkthroughThis pull request introduces several changes to set up a Tauri application named "hk-independent-bus-eta." Key updates include the addition of a new development dependency in Changes
Possibly related PRs
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (1)
src-tauri/src/lib.rs (1)
1-16
: Consider adding state management and custom commandsThe current implementation lacks common Tauri features that might be needed:
- State management for sharing data between frontend and backend
- Custom commands for platform-specific functionality
Would you like me to provide an example implementation with state management and custom commands?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (42)
src-tauri/Cargo.lock
is excluded by!**/*.lock
src-tauri/gen/android/.editorconfig
is excluded by!**/gen/**
src-tauri/gen/android/.gitignore
is excluded by!**/gen/**
src-tauri/gen/android/app/.gitignore
is excluded by!**/gen/**
src-tauri/gen/android/app/build.gradle.kts
is excluded by!**/gen/**
src-tauri/gen/android/app/proguard-rules.pro
is excluded by!**/gen/**
src-tauri/gen/android/app/src/main/AndroidManifest.xml
is excluded by!**/gen/**
src-tauri/gen/android/app/src/main/java/app/hkbus/MainActivity.kt
is excluded by!**/gen/**
src-tauri/gen/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
is excluded by!**/gen/**
src-tauri/gen/android/app/src/main/res/drawable/ic_launcher_background.xml
is excluded by!**/gen/**
src-tauri/gen/android/app/src/main/res/layout/activity_main.xml
is excluded by!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
is excluded by!**/*.png
,!**/gen/**
src-tauri/gen/android/app/src/main/res/values-night/themes.xml
is excluded by!**/gen/**
src-tauri/gen/android/app/src/main/res/values/colors.xml
is excluded by!**/gen/**
src-tauri/gen/android/app/src/main/res/values/strings.xml
is excluded by!**/gen/**
src-tauri/gen/android/app/src/main/res/values/themes.xml
is excluded by!**/gen/**
src-tauri/gen/android/app/src/main/res/xml/file_paths.xml
is excluded by!**/gen/**
src-tauri/gen/android/build.gradle.kts
is excluded by!**/gen/**
src-tauri/gen/android/buildSrc/build.gradle.kts
is excluded by!**/gen/**
src-tauri/gen/android/buildSrc/src/main/java/app/hkbus/kotlin/BuildTask.kt
is excluded by!**/gen/**
src-tauri/gen/android/buildSrc/src/main/java/app/hkbus/kotlin/RustPlugin.kt
is excluded by!**/gen/**
src-tauri/gen/android/gradle.properties
is excluded by!**/gen/**
src-tauri/gen/android/gradle/wrapper/gradle-wrapper.jar
is excluded by!**/*.jar
,!**/gen/**
src-tauri/gen/android/gradle/wrapper/gradle-wrapper.properties
is excluded by!**/gen/**
src-tauri/gen/android/gradlew
is excluded by!**/gen/**
src-tauri/gen/android/gradlew.bat
is excluded by!**/gen/**
src-tauri/gen/android/settings.gradle
is excluded by!**/gen/**
yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
📒 Files selected for processing (9)
package.json
(1 hunks)src-tauri/.gitignore
(1 hunks)src-tauri/Cargo.toml
(1 hunks)src-tauri/build.rs
(1 hunks)src-tauri/capabilities/default.json
(1 hunks)src-tauri/src/lib.rs
(1 hunks)src-tauri/src/main.rs
(1 hunks)src-tauri/tauri.conf.json
(1 hunks)vite.config.ts
(2 hunks)
✅ Files skipped from review due to trivial changes (6)
- src-tauri/src/main.rs
- src-tauri/.gitignore
- src-tauri/build.rs
- src-tauri/capabilities/default.json
- src-tauri/Cargo.toml
- src-tauri/tauri.conf.json
@@ -60,6 +60,7 @@ | |||
"web-vitals": "^2.1.4" | |||
}, | |||
"devDependencies": { | |||
"@tauri-apps/cli": "^2.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add missing Tauri dependencies and scripts
While @tauri-apps/cli
is added, there are some essential Tauri-related additions missing:
- Add
@tauri-apps/api
dependency for Tauri frontend APIs - Add Tauri-specific scripts for development workflow
Add these to package.json:
"dependencies": {
+ "@tauri-apps/api": "^2.1.0",
"@emotion/cache": "^11.11.0",
},
"scripts": {
+ "tauri": "tauri",
+ "tauri:dev": "tauri dev",
+ "tauri:build": "tauri build",
"start": "./scripts/start-all-platforms.cmd",
}
Committable suggestion skipped: line range outside the PR's diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qwqtoday, understood.
https: !mobile, | ||
host: true, | ||
port: 443, | ||
port: mobile ? 80 : 443, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review server configuration for security and reliability
Several concerns with the current server configuration:
- Disabling HTTPS on mobile platforms reduces security
- Hard-coded ports (80/443) require root/admin privileges
- No fallback ports if primary ports are unavailable
Consider this safer configuration:
server: {
- https: !mobile,
- host: true,
- port: mobile ? 80 : 443,
+ https: true, // Keep HTTPS for all platforms
+ host: true,
+ port: mobile ? 8080 : 8443, // Use non-privileged ports
+ strictPort: false, // Allow fallback to next available port
},
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
https: !mobile, | |
host: true, | |
port: 443, | |
port: mobile ? 80 : 443, | |
https: true, // Keep HTTPS for all platforms | |
host: true, | |
port: mobile ? 8080 : 8443, // Use non-privileged ports | |
strictPort: false, // Allow fallback to next available port |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well actually originally it was hard coded to 443.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qwqtoday, understood. If hardcoding port 443 suits your setup, it's acceptable to keep it as is. Thank you for the clarification.
✏️ Learnings added
Learnt from: qwqtoday
PR: hkbus/hk-independent-bus-eta#213
File: vite.config.ts:23-25
Timestamp: 2024-12-14T10:51:32.215Z
Learning: In the `hkbus` application, it's acceptable to hardcode port `443` in `vite.config.ts` for the server configuration.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
@@ -5,6 +5,9 @@ import { VitePWA, VitePWAOptions } from "vite-plugin-pwa"; | |||
import eslint from "vite-plugin-eslint" | |||
|
|||
// https://vitejs.dev/config/ | |||
|
|||
const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve platform detection reliability
The current regex might miss some mobile platforms. Consider using Tauri's built-in platform detection.
-const mobile = !!/android|ios/.exec(process.env.TAURI_ENV_PLATFORM);
+import { Platform } from '@tauri-apps/api/os';
+const mobile = await Platform.isAndroid || await Platform.isIOS;
Committable suggestion skipped: line range outside the PR's diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no thanks bro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qwqtoday, understood. Let me know if I can assist further.
#[cfg_attr(mobile, tauri::mobile_entry_point)] | ||
pub fn run() { | ||
tauri::Builder::default() | ||
.setup(|app| { | ||
if cfg!(debug_assertions) { | ||
app.handle().plugin( | ||
tauri_plugin_log::Builder::default() | ||
.level(log::LevelFilter::Info) | ||
.build(), | ||
)?; | ||
} | ||
Ok(()) | ||
}) | ||
.run(tauri::generate_context!()) | ||
.expect("error while running tauri application"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve error handling and logging configuration
Several improvements needed for production readiness:
- Replace panic with proper error handling
- Add configuration for production logging
- Add documentation for the public function
Consider this improved implementation:
+//! Tauri application entry point.
+//! This module initializes the application and sets up logging.
+
+use log::LevelFilter;
+use std::error::Error;
+
#[cfg_attr(mobile, tauri::mobile_entry_point)]
-pub fn run() {
+/// Initializes and runs the Tauri application.
+///
+/// # Errors
+/// Returns an error if the application fails to initialize or run.
+pub fn run() -> Result<(), Box<dyn Error>> {
tauri::Builder::default()
.setup(|app| {
- if cfg!(debug_assertions) {
- app.handle().plugin(
- tauri_plugin_log::Builder::default()
- .level(log::LevelFilter::Info)
- .build(),
- )?;
- }
+ let log_level = if cfg!(debug_assertions) {
+ LevelFilter::Debug
+ } else {
+ LevelFilter::Info
+ };
+
+ app.handle().plugin(
+ tauri_plugin_log::Builder::default()
+ .level(log_level)
+ .build(),
+ )?;
Ok(())
})
.run(tauri::generate_context!())
- .expect("error while running tauri application");
+ .map_err(|e| e.into())
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
#[cfg_attr(mobile, tauri::mobile_entry_point)] | |
pub fn run() { | |
tauri::Builder::default() | |
.setup(|app| { | |
if cfg!(debug_assertions) { | |
app.handle().plugin( | |
tauri_plugin_log::Builder::default() | |
.level(log::LevelFilter::Info) | |
.build(), | |
)?; | |
} | |
Ok(()) | |
}) | |
.run(tauri::generate_context!()) | |
.expect("error while running tauri application"); | |
} | |
//! Tauri application entry point. | |
//! This module initializes the application and sets up logging. | |
use log::LevelFilter; | |
use std::error::Error; | |
#[cfg_attr(mobile, tauri::mobile_entry_point)] | |
/// Initializes and runs the Tauri application. | |
/// | |
/// # Errors | |
/// Returns an error if the application fails to initialize or run. | |
pub fn run() -> Result<(), Box<dyn Error>> { | |
tauri::Builder::default() | |
.setup(|app| { | |
let log_level = if cfg!(debug_assertions) { | |
LevelFilter::Debug | |
} else { | |
LevelFilter::Info | |
}; | |
app.handle().plugin( | |
tauri_plugin_log::Builder::default() | |
.level(log_level) | |
.build(), | |
)?; | |
Ok(()) | |
}) | |
.run(tauri::generate_context!()) | |
.map_err(|e| e.into()) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was generated code and I wasn't supposed to modify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qwqtoday, understood. If this code is generated and not meant to be modified manually, it's acceptable to leave it as is.
✏️ Learnings added
Learnt from: qwqtoday
PR: hkbus/hk-independent-bus-eta#213
File: src-tauri/src/lib.rs:1-16
Timestamp: 2024-12-14T10:52:10.166Z
Learning: In the hk-independent-bus-eta project, the file `src-tauri/src/lib.rs` contains generated code that should not be manually modified.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qwqtoday, understood. If this code is generated and not meant to be modified manually, it's acceptable to leave it as is.
✏️ Learnings addedLearnt from: qwqtoday PR: hkbus/hk-independent-bus-eta#213 File: src-tauri/src/lib.rs:1-16 Timestamp: 2024-12-14T10:52:10.166Z Learning: In the hk-independent-bus-eta project, the file `src-tauri/src/lib.rs` contains generated code that should not be manually modified.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
please remove that learning, it's not completely true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qwqtoday, understood. I've removed the learning as per your request.
I don't have a mac so I can't test the iOS part |
Your code suggestion is highly appreciated, while I have no experience in Tauri, as well as the committed code under Would you explain more on it? And, how could it be built? |
I am unsure what does those png and xml do. You need to setup a lot of things to build it. SetupRust EnvironmentTo setup the Rust environment, you need to follow the instructions on this page: https://www.rust-lang.org/tools/install Android SDK & NDKI assume you have Android Studio installed. You need to open a project on Android Studio, click Android SDKAt that page you have to copy your Android SDK location, and add it to your environment variables as Android NDKAt the same page, you need to click SDK Tools. You will probably see the After you have Android NDK installed, you need to set the NDK location to your environment variables to Example: Building App
|
I forgot to mention, you also have to sign the apk after you build it. |
Have you also checked the developed native app features in https://github.com/hkbus/mobile-bus-app, e.g., 到站提示? Would Tauri support all of them by default? And, would you state the necessity on building app for Window? I do prefer user to install the App (a.k.a. Add to home screen) via Chrome in Window. |
Probably.
Building the app on windows, can guarantee users will able to access the app any time, even when https://hkbus.app is down. This does not mean the app can be used while offline, you still need to able to access https://data.gov.hk/ for the app to function. |
I have noticed the iOS and Android builds of this app is just showing the app from https://hkbus.app/ . This means if hkbus.app is down, the user wouldn't able use the app anymore. The Tauri builds includes all the website assets, and can load the app while offline, solving the problem I mentioned above. (This is not the only way to achieve this.) Users does not need to access https://hkbus.app to use the app with these builds, saving our organization some bandwidth, and potentially gives the user more privacy while using this app (no need to go online). This approach is also more secure, as if one day the hkbus.app domain has been taken by someone else, they can use it for malicious purposes targeting our app's users. |
This PR adds building the app using Tauri.
You can build the app using Tauri to Windows, Android or iOS (not yet).
maybe we can deprecate https://github.com/hkbus/mobile-bus-app