app.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import Taro, { useLaunch } from "@tarojs/taro";
  2. import { PropsWithChildren } from "react";
  3. import "./app.less";
  4. import { useAppStore } from "./store/appStore";
  5. if (process.env.TARO_ENV == "h5") {
  6. const VConsole = require("vconsole");
  7. new VConsole();
  8. }
  9. function App({ children }: PropsWithChildren<any>) {
  10. const { setSystemInfo } = useAppStore();
  11. useLaunch(() => {
  12. console.log("App launched.");
  13. if (process.env.TARO_ENV == "h5") {
  14. return;
  15. }
  16. const updateManager = Taro.getUpdateManager();
  17. updateManager.onCheckForUpdate(function (res) {
  18. // 请求完新版本信息的回调
  19. console.log("需要更新: ", res.hasUpdate);
  20. });
  21. updateManager.onUpdateReady(function () {
  22. Taro.showModal({
  23. title: "更新提示",
  24. content: "新版本已经准备好,是否重启应用?",
  25. success: function (res) {
  26. if (res.confirm) {
  27. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  28. updateManager.applyUpdate();
  29. }
  30. },
  31. });
  32. });
  33. updateManager.onUpdateFailed(function () {
  34. // 新版本下载失败
  35. });
  36. Taro.getSystemInfoAsync({
  37. success(res) {
  38. setSystemInfo(res);
  39. },
  40. });
  41. });
  42. return <>{children}</>;
  43. }
  44. export default App;