Skip to content

Commit

Permalink
feat: Added option to define device name
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Sep 29, 2021
1 parent dc38435 commit df6f1e2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*!
* 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.
*/

/**
* Define some global configurations
*
* @example
* ```javascript
* // Global variable before injection
* WPPConfig = {
* deviceName: 'WPPConnect'
* };
* ```
*/
export interface Config {
deviceName: string;
}

export const defaultConfig: Config = {
deviceName: 'WPPConnect',
};

export const config: Config = defaultConfig;

// Init config from global environment;
const w = window as unknown as { WPPConfig: Config };

w.WPPConfig = w.WPPConfig || defaultConfig;

for (const key of Object.keys(w.WPPConfig)) {
(config as any)[key] = (w.WPPConfig as any)[key];
}
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* limitations under the License.
*/

// eslint-disable-next-line simple-import-sort/imports
import './config';

import './deviceName';
import './patch';

Expand All @@ -26,6 +29,7 @@ export { auth, chat, status, webpack };

export * as Auth from './auth';
export * as Chat from './chat';
export * as config from './config';
export * as Status from './status';
export { isInjected, isReady } from './webpack';
export * as whatsapp from './whatsapp';
Expand Down

0 comments on commit df6f1e2

Please sign in to comment.