Skip to content

Commit

Permalink
feat: Added WPP.conn.isMainInit function
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Dec 6, 2022
1 parent b69c09e commit 6840878
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/conn/events/registerMainInit.ts
Expand Up @@ -16,14 +16,13 @@

import { internalEv } from '../../eventEmitter';
import * as webpack from '../../webpack';
import { isMainInit } from '../functions';

webpack.onInjected(register);

function register() {
const check = setInterval(() => {
const version = (window as any).Debug?.VERSION;

if (version) {
if (isMainInit()) {
clearInterval(check);
internalEv.emit('conn.main_init');
}
Expand Down
1 change: 1 addition & 0 deletions src/conn/functions/index.ts
Expand Up @@ -20,6 +20,7 @@ export { getMyUserId } from './getMyUserId';
export { getPlatform } from './getPlatform';
export { isAuthenticated } from './isAuthenticated';
export { isIdle } from './isIdle';
export { isMainInit } from './isMainInit';
export { isMainLoaded } from './isMainLoaded';
export { isMainReady } from './isMainReady';
export { isMultiDevice } from './isMultiDevice';
Expand Down
27 changes: 27 additions & 0 deletions src/conn/functions/isMainInit.ts
@@ -0,0 +1,27 @@
/*!
* Copyright 2021 WPPConnect Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* Check is main interface is initializing
*
* @example
* ```javascript
* const isMainInit = WPP.conn.isMainInit();
* ```
*/
export function isMainInit(): boolean {
return Boolean((window as any).Debug?.VERSION);
}

0 comments on commit 6840878

Please sign in to comment.