Skip to content

Commit 26c3f96

Browse files
authored
Merge pull request #233 from entrylabs/develop
master <= Develop 2.1.31 alpha2
2 parents 089b85a + 36b83fa commit 26c3f96

File tree

8 files changed

+60
-5
lines changed

8 files changed

+60
-5
lines changed

src/main/ipcMainHelper.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Constants from './constants';
66
import CommonUtils from './commonUtils';
77
import checkUpdateRequest from './utils/network/checkUpdate';
88
import createLogger from './utils/functions/createLogger';
9-
import isValidAsarFile from './utils/functions/isValidAsarFile';
9+
import isValidAsarFile, { getPapagoHeaderInfoByValidator } from './utils/functions/isValidAsarFile';
1010
import fileUtils from './fileUtils';
1111
require('@electron/remote/main').initialize();
1212

@@ -48,6 +48,7 @@ new (class {
4848
ipcMain.handle('isValidAsarFile', this.checkIsValidAsarFile.bind(this));
4949
ipcMain.handle('saveSoundBuffer', this.saveSoundBuffer.bind(this));
5050
ipcMain.handle('getExistSoundFilePath', this.getExistSoundFilePath.bind(this));
51+
ipcMain.handle('getPapagoHeaderInfo', this.getPapagoHeaderInfo.bind(this));
5152
}
5253

5354
async saveProject(event: IpcMainInvokeEvent, project: ObjectLike, targetPath: string) {
@@ -259,6 +260,10 @@ new (class {
259260
return fileUtils.getExistSoundFilePath(sound);
260261
}
261262

263+
async getPapagoHeaderInfo(event: IpcMainInvokeEvent) {
264+
return await getPapagoHeaderInfoByValidator();
265+
}
266+
262267
openUrl(event: IpcMainInvokeEvent, url: string) {
263268
logger.info(`openUrl called : ${url}`);
264269
shell.openExternal(url);

src/main/utils/functions/isValidAsarFile.ts

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export enum ResultCode {
2424
}
2525

2626
export type ValidationResult = { result: ResultCode; reason?: string };
27+
export type ApiKeyResult = { result: ResultCode; value?: object };
2728

2829
// development: /Users/user/entry_projects/entry-offline
2930
// production: /Users/user/entry_projects/entry-offline/dist/Entry-darwin-x64/mac/Entry.app/Contents/Resources/app.asar
@@ -36,6 +37,8 @@ function getValidatorPath(): string | undefined {
3637
if (appPath.indexOf('app.asar') > -1) {
3738
// if asar packed (production)
3839
return path.join(appPath, '..', validatorFileName);
40+
} else if (process.env.NODE_ENV === 'development') {
41+
return path.join(appPath, '/validator', isMacOS ? 'mac' : 'win', validatorFileName);
3942
}
4043
}
4144

@@ -68,7 +71,7 @@ function isValidAsarFile(): Promise<boolean> {
6871
resolve(false);
6972
}, 3000);
7073

71-
childProcess.on('message', ((message: ValidationResult) => {
74+
childProcess.on('message', (message: ValidationResult) => {
7275
clearTimeout(timeout);
7376
const { result, reason } = message;
7477
if (result === ResultCode.INVALID || result === ResultCode.FILE_NOT_FOUND) {
@@ -78,7 +81,42 @@ function isValidAsarFile(): Promise<boolean> {
7881
resolve(true);
7982
}
8083
!childProcess.killed && childProcess.kill();
81-
}));
84+
});
85+
});
86+
}
87+
88+
export function getPapagoHeaderInfoByValidator(): Promise<object | undefined | null> {
89+
const validatorPath = getValidatorPath();
90+
91+
if (!validatorPath || !fs.existsSync(validatorPath)) {
92+
console.log('cannot find validator binary');
93+
return Promise.resolve(null);
94+
}
95+
96+
return new Promise((resolve) => {
97+
const childProcess = spawn(validatorPath, ['--type=offline', '--method=apiKey'], {
98+
stdio: ['ignore', 'inherit', 'inherit', 'ipc'],
99+
detached: true,
100+
});
101+
102+
const timeout = setTimeout(() => {
103+
logger.warn('validator spawn timeout. check validator logic');
104+
childProcess.kill();
105+
resolve(null);
106+
}, 3000);
107+
108+
childProcess.on('message', (message: ApiKeyResult) => {
109+
clearTimeout(timeout);
110+
const { result, value } = message;
111+
if (result === ResultCode.LOGIC_ERROR || result === ResultCode.FILE_NOT_FOUND) {
112+
logger.warn(`apiKey fail value: ${result}`);
113+
resolve(null);
114+
} else {
115+
const valueWithVersion = { ...value, 'X-Offline-Version': app.getVersion() };
116+
resolve(valueWithVersion);
117+
}
118+
!childProcess.killed && childProcess.kill();
119+
});
82120
});
83121
}
84122

src/preload/preload.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ window.checkPermission = async (type: 'microphone' | 'camera') => {
108108
await ipcRenderer.invoke('checkPermission', type);
109109
};
110110

111+
window.getPapagoHeaderInfo = async () => {
112+
const result = await ipcRenderer.invoke('getPapagoHeaderInfo');
113+
return result;
114+
};
115+
116+
window.isOffline = true;
117+
111118
window.ipcListen = ipcRenderer.on.bind(ipcRenderer);
112119

113120
window.isOsx = process.platform === 'darwin';

src/renderer/components/workspace.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ class Workspace extends Component<IProps> {
4040
libDir: '../../../node_modules',
4141
defaultDir: '../../renderer/resources',
4242
entryDir: '/entry-js',
43-
baseUrl: 'https://playentry.org',
43+
baseUrl:
44+
process.env.NODE_ENV === 'development'
45+
? 'https://entry2-dev.playentry.org'
46+
: 'https://playentry.org',
4447
fonts: EntryStatic.fonts,
4548
textCodingEnable: true,
4649
dataTableEnable: true,

types/window.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ declare interface Preload {
2626
onLoadProjectFromMain(callback: (project: Promise<IEntry.Project>) => void): void;
2727
openHardwarePage(): void;
2828
checkPermission(type: 'microphone' | 'camera'): Promise<void>;
29+
getPapagoHeaderInfo(): Promise<object>;
2930
weightsPath: () => string;
3031
getEntryjsPath: () => string;
3132
getAppPathWithParams: (...params: string[]) => string;
33+
isOffline: boolean;
3234
}
3335

3436
declare var entrylms: any;

validator/mac/validator.txt

3.47 KB
Binary file not shown.

validator/win/validator.exe

3.21 MB
Binary file not shown.

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5238,7 +5238,7 @@ entities@^2.0.0:
52385238

52395239
"entry-js@git+https://github.com/entrylabs/entryjs.git#dist/offline_v2.1.31":
52405240
version "4.0.22"
5241-
resolved "git+https://github.com/entrylabs/entryjs.git#a7200f57d749b08d15f3ae628210c85e231c9d77"
5241+
resolved "git+https://github.com/entrylabs/entryjs.git#6e078bef7d783521a00480d56e89b66991c7a2c9"
52425242
dependencies:
52435243
uid "^0.0.2"
52445244
"@entrylabs/event" "^1.0.3"

0 commit comments

Comments
 (0)