Skip to content

Commit

Permalink
fix: fix screen module before app ready causes error on electron & fi…
Browse files Browse the repository at this point in the history
…x missing AutoUpdate Module on Android in store channel (#6451)
  • Loading branch information
huhuanming authored Jan 7, 2025
1 parent 9dc08d6 commit c8027cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion apps/desktop/src-electron/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
ipcMain,
nativeTheme,
powerMonitor,
screen,
session,
shell,
systemPreferences,
Expand Down Expand Up @@ -388,6 +387,8 @@ const getBackgroundColor = (key: string) =>
themeColors[nativeTheme.shouldUseDarkColors ? 'dark' : 'light'];

function createMainWindow() {
// https://github.com/electron/electron/issues/16168
const { screen } = require('electron');
const display = screen.getPrimaryDisplay();
const dimensions = display.workAreaSize;
const ratio = 16 / 9;
Expand Down
18 changes: 16 additions & 2 deletions packages/shared/src/modules3rdParty/auto-update/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ const { AutoUpdateModule } = NativeModules as {
};

export const clearPackage: IClearPackage = async () => {
if (!AutoUpdateModule) {
return;
}
await AutoUpdateModule.clearCache();
if (!RNFS) {
return;
Expand All @@ -53,6 +56,11 @@ export const downloadPackage: IDownloadPackage = async ({
downloadUrl,
latestVersion,
}) => {
if (!AutoUpdateModule) {
return {
downloadedFile: '',
};
}
await RNFS?.mkdir(DIR_PATH);
if (!downloadUrl || !latestVersion) {
throw new Error('Invalid version or downloadUrl');
Expand All @@ -69,19 +77,25 @@ export const downloadPackage: IDownloadPackage = async ({
};

export const verifyPackage: IVerifyPackage = async (params) => {
if (!AutoUpdateModule) {
return;
}
await AutoUpdateModule.verifyAPK({
filePath: params.downloadedFile,
downloadUrl: params.downloadUrl || '',
});
};

export const installPackage: IInstallPackage = ({
export const installPackage: IInstallPackage = async ({
latestVersion,
downloadUrl,
}) => {
if (!AutoUpdateModule) {
return;
}
defaultLogger.update.app.log('install', latestVersion);
if (!latestVersion) {
return Promise.resolve();
return;
}
return AutoUpdateModule.installAPK({
filePath: buildFilePath(latestVersion),
Expand Down

0 comments on commit c8027cc

Please sign in to comment.