Skip to content

Commit

Permalink
* Auto update cbetaBookcaseProcessingAssets.
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMYHuang committed Aug 23, 2022
1 parent 58fd040 commit ab8f4aa
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 32 deletions.
3 changes: 3 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# <a id='history'>版本歷史</a>
* PWA 10.7.0:
* [新增] app 啟動時自動更新 Bookcase 內容處理 assets。

* PWA 10.6.0:
* [調整] 離線 DB 模式統一連網下載 Bookcase 內容處理 assets。
* [修正] Bookcase XML 處理 xslt 程式漏掉部分經文內容。(已修正金剛經漏字問題)
Expand Down
4 changes: 1 addition & 3 deletions electronBuilderConfigs/appImage.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"from": "electronBuilderConfigs",
"to": ".",
"filter": ["IsAppImage.txt"]
},
"buildElectron/*.xsl",
"cbeta_gaiji/cbeta_gaiji.json"
}
]
}
4 changes: 1 addition & 3 deletions electronBuilderConfigs/deb.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"from": "electronBuilderConfigs",
"to": ".",
"filter": ["IsDeb.txt"]
},
"buildElectron/*.xsl",
"cbeta_gaiji/cbeta_gaiji.json"
}
]
}
4 changes: 1 addition & 3 deletions electronBuilderConfigs/flatpak.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"from": "electronBuilderConfigs",
"to": ".",
"filter": ["IsNoUpdater.txt"]
},
"buildElectron/*.xsl",
"cbeta_gaiji/cbeta_gaiji.json"
}
]
}
4 changes: 1 addition & 3 deletions electronBuilderConfigs/mac.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"from": "electronBuilderConfigs",
"to": ".",
"filter": ["IsMac.txt"]
},
"buildElectron/*.xsl",
"cbeta_gaiji/cbeta_gaiji.json"
}
],
"afterAllArtifactBuild": "electron-builder-notarize-pkg-myh",
"mac": {
Expand Down
4 changes: 1 addition & 3 deletions electronBuilderConfigs/mas.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
"from": "electronBuilderConfigs",
"to": ".",
"filter": ["IsMas.txt"]
},
"buildElectron/*.xsl",
"cbeta_gaiji/cbeta_gaiji.json"
}
],
"mac": {
"type": "distribution",
Expand Down
4 changes: 1 addition & 3 deletions electronBuilderConfigs/masDev.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"filter": [
"IsMas.txt"
]
},
"buildElectron/*.xsl",
"cbeta_gaiji/cbeta_gaiji.json"
}
],
"mac": {
"type": "development",
Expand Down
4 changes: 1 addition & 3 deletions electronBuilderConfigs/rpm.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"from": "electronBuilderConfigs",
"to": ".",
"filter": ["IsRpm.txt"]
},
"buildElectron/*.xsl",
"cbeta_gaiji/cbeta_gaiji.json"
}
]
}
4 changes: 1 addition & 3 deletions electronBuilderConfigs/snap.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"from": "electronBuilderConfigs",
"to": ".",
"filter": ["IsSnap.txt"]
},
"buildElectron/*.xsl",
"cbeta_gaiji/cbeta_gaiji.json"
}
]
}
4 changes: 1 addition & 3 deletions electronBuilderConfigs/win.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
"from": "electronBuilderConfigs",
"to": ".",
"filter": ["IsWin.txt"]
},
"buildElectron/*.xsl",
"cbeta_gaiji/cbeta_gaiji.json"
}
],
"icon": "buildElectron/icon.png",
"win": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cbetar2",
"productName": "電子佛典",
"homepage": "/",
"pwaVersion": "10.6.0",
"pwaVersion": "10.7.0",
"version": "21.1.0",
"license": "MIT",
"keywords": [
Expand Down
27 changes: 24 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,30 @@ class _AppOrig extends React.Component<AppOrigProps, State> {
</IonRouterOutlet>;
}

if (this.props.settings.cbetaOfflineDbMode === CbetaDbMode.OfflineIndexedDb) {
CbetaOfflineDb.init(CbetaDbMode.OfflineIndexedDb);
let updateCbetaBookcaseProcessingAssets = Promise.resolve();
if (this.props.settings.cbetaBookcaseProcessingAssetsVersion < Globals.cbetaBookcaseProcessingAssetsVersion) {
updateCbetaBookcaseProcessingAssets = Globals.downloadCbetaBookcaseAssets().then(async () => {
this.props.dispatch({
type: "SET_KEY_VAL",
key: 'cbetaBookcaseProcessingAssetsVersion',
val: Globals.cbetaBookcaseProcessingAssetsVersion,
});

// Remove for updating bookcaseInfos.
try {
await IndexedDbFuncs.removeFile(CbetaOfflineDb.bookcaseInfosKey);
} catch (error) {
console.error(error);
}
});
}
updateCbetaBookcaseProcessingAssets.then(() => {
if (this.props.settings.cbetaOfflineDbMode !== CbetaDbMode.Online) {
CbetaOfflineDb.init(CbetaDbMode.OfflineIndexedDb);
}
}).catch((error) => {
console.error(error);
});

electronBackendApi?.receive("fromMain", async (data: any) => {
switch (data.event) {
Expand All @@ -197,7 +218,7 @@ class _AppOrig extends React.Component<AppOrigProps, State> {
}
} catch (error) {
await CbetaOfflineDb.electronBackendApi.invoke('toMainV3', { event: 'disableBookcase' });
this.setState({showToast: true, toastMessage: `離線 CBETA Bookcase 異常,請重新設定載入!`});
this.setState({ showToast: true, toastMessage: `離線 CBETA Bookcase 異常,請重新設定載入!` });
this.props.dispatch({
type: "SET_KEY_VAL",
key: 'cbetaOfflineDbMode',
Expand Down
3 changes: 3 additions & 0 deletions src/CbetaOfflineDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ async function readBookcaseFromFileSystemV3(path: string) {
}

const CbetaOfflineDb = {
bookcaseInfosKey,
electronBackendApi,
filesFilter,
init,
Expand All @@ -468,6 +469,8 @@ const CbetaOfflineDb = {
fetchWork,
fetchJuan,
setOfflineFileSystemV2Ready,
readResourceFromFileSystemV2,
readResourceFromFileSystemV3,
};

export default CbetaOfflineDb;
2 changes: 2 additions & 0 deletions src/Globals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ async function loadTwKaiFont(font: string, key: string, fileName: string, forceU
})
}

const cbetaBookcaseProcessingAssetsVersion = 1;
async function downloadCbetaBookcaseAssets() {
const res = await axiosInstance.get(`${window.location.origin}/${pwaUrl}/assets.zip`, {
responseType: 'blob',
Expand Down Expand Up @@ -265,6 +266,7 @@ const Globals = {
twKaiFonts,
twKaiFontKeys,
loadTwKaiFonts,
cbetaBookcaseProcessingAssetsVersion,
downloadCbetaBookcaseAssets,
axiosInstance,
appSettings: {
Expand Down
2 changes: 2 additions & 0 deletions src/models/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum UiMode {
export interface Settings {
// version is the setting file version.
version: number;
cbetaBookcaseProcessingAssetsVersion: number;
hasAppLog: boolean;
theme: number;
paginated: boolean;
Expand All @@ -41,6 +42,7 @@ export interface Settings {
const defaultSettings = {
// version is the setting file version.
version: 1,
cbetaBookcaseProcessingAssetsVersion: 0,
hasAppLog: true,
theme: 0,
paginated: true,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/SettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class _SettingsPage extends React.Component<PageProps, StateProps> {
}}
/>
</IonItem>
<IonItem>
<IonItem hidden={!(this.props.settings.cbetaOfflineDbMode === CbetaDbMode.Online || this.props.settings.cbetaOfflineDbMode === CbetaDbMode.OfflineIndexedDb)}>
<div tabIndex={0}></div>{/* Workaround for macOS Safari 14 bug. */}
<IonIcon icon={download} slot='start' />
<div style={{ width: '100%' }}>
Expand Down

0 comments on commit ab8f4aa

Please sign in to comment.