Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
build: set NEXT_PUBLIC_TAURI environment variable in tauri command
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaolu-lujunji committed Nov 19, 2022
1 parent 488cd2e commit da89828
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
3 changes: 1 addition & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
BANNER=国内用户建议使用
BANNER_LINK=https://github.com/xiaolu-lujunji/mooc-helper/releases
BANNER_LINK_DESCRIPTION=桌面端应用程序
NEXT_PUBLIC_TAURI=
BANNER_LINK_DESCRIPTION=桌面端应用程序
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"license": "MIT",
"scripts": {
"dev": "next dev",
"build:web": "next build",
"build": "next build && next export",
"build": "next build",
"export": "next build && next export",
"start": "next start",
"lint": "next lint",
"tauri": "tauri"
"tauri": "cross-env NEXT_PUBLIC_TAURI=1 tauri"
},
"dependencies": {
"@babel/core": "^7.18.5",
Expand All @@ -36,6 +36,7 @@
"@types/lodash": "^4.14.186",
"@types/node": "17.0.21",
"@types/react": "17.0.40",
"cross-env": "^7.0.3",
"eslint": "8.11.0",
"eslint-config-next": "12.1.0",
"typescript": "4.6.2"
Expand Down
8 changes: 5 additions & 3 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,11 @@ const Home: NextPage<{
export const getStaticProps = () => {
return {
props: {
banner: process.env.BANNER ?? null,
bannerLink: process.env.BANNER_LINK ?? null,
bannerLinkDescription: process.env.BANNER_LINK_DESCRIPTION ?? null,
...(!process.env.NEXT_PUBLIC_TAURI && {
banner: process.env.BANNER ?? null,
bannerLink: process.env.BANNER_LINK ?? null,
bannerLinkDescription: process.env.BANNER_LINK_DESCRIPTION ?? null,
}),
}, // will be passed to the page component as props
};
};
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
windows_subsystem = "windows"
)]

// use tauri::Manager;
use tauri_plugin_store::PluginBuilder;

fn main() {
tauri::Builder::default()
let builder = tauri::Builder::default();

builder
.plugin(PluginBuilder::default().build())
// .setup(|app| {
// #[cfg(debug_assertions)] // only include this code on debug builds
// {
// let window = app.get_window("main").unwrap();
// window.open_devtools();
// }
// Ok(())
// })
.setup(|app| {
#[cfg(debug_assertions)] // only include this code on debug builds
{
use tauri::Manager;
let window = app.get_window("main").unwrap();
window.open_devtools();
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/schema.json",
"build": {
"beforeBuildCommand": "npm run build",
"beforeBuildCommand": "cross-env NEXT_PUBLIC_TAURI=1 npm run export",
"beforeDevCommand": "npm run dev",
"devPath": "http://localhost:3000",
"distDir": "../out"
Expand Down

0 comments on commit da89828

Please sign in to comment.