feat: Setting background synchronization (#3331)

* Changing the background synchronization setting

* add  example

* return function

* style: add clarification note

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
Co-authored-by: Shir Serlui <70711723+shirser121@users.noreply.github.com>
This commit is contained in:
tofers 2025-05-30 11:06:08 +03:00 • committed by GitHub
commit c0ba5e545b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 3 deletions

View file

@ -470,6 +470,10 @@ client.on('message', async msg => {
console.log(statuses); console.log(statuses);
const chat = await statuses[0]?.getChat(); // Get user chat of a first status const chat = await statuses[0]?.getChat(); // Get user chat of a first status
console.log(chat); console.log(chat);
} else if (msg.body === '!changeSync') {
// NOTE: this action will take effect after you restart the client.
const backgroundSync = await client.setBackgroundSync(true);
console.log(backgroundSync);
} }
}); });

7
index.d.ts vendored
View file

@ -180,6 +180,13 @@ declare namespace WAWebJS {
*/ */
setAutoDownloadVideos(flag: boolean): Promise<void> setAutoDownloadVideos(flag: boolean): Promise<void>
/**
* Changing the background synchronization setting.
* NOTE: this action will take effect after you restart the client.
* @param flag true/false on or off
*/
setBackgroundSync(flag: boolean): Promise<void>
/** /**
* Get user device count by ID * Get user device count by ID
* Each WaWeb Connection counts as one device, and the phone (if exists) counts as one * Each WaWeb Connection counts as one device, and the phone (if exists) counts as one

View file

@ -1721,6 +1721,23 @@ class Client extends EventEmitter {
}, flag); }, flag);
} }
/**
* Setting background synchronization.
* NOTE: this action will take effect after you restart the client.
* @param {boolean} flag true/false
* @returns {Promise<boolean>}
*/
async setBackgroundSync(flag) {
return await this.pupPage.evaluate(async flag => {
const backSync = window.Store.Settings.getGlobalOfflineNotifications();
if (backSync === flag) {
return flag;
}
await window.Store.Settings.setGlobalOfflineNotifications(flag);
return flag;
}, flag);
}
/** /**
* Get user device count by ID * Get user device count by ID
* Each WaWeb Connection counts as one device, and the phone (if exists) counts as one * Each WaWeb Connection counts as one device, and the phone (if exists) counts as one

View file

@ -93,14 +93,17 @@ exports.ExposeStore = () => {
window.Store.pinUnpinMsg = window.require('WAWebSendPinMessageAction').sendPinInChatMsg; window.Store.pinUnpinMsg = window.require('WAWebSendPinMessageAction').sendPinInChatMsg;
window.Store.QueryExist = window.require('WAWebQueryExistsJob').queryWidExists; window.Store.QueryExist = window.require('WAWebQueryExistsJob').queryWidExists;
window.Store.ReplyUtils = window.require('WAWebMsgReply'); window.Store.ReplyUtils = window.require('WAWebMsgReply');
window.Store.Settings = window.require('WAWebUserPrefsGeneral');
window.Store.BotSecret = window.require('WAWebBotMessageSecret'); window.Store.BotSecret = window.require('WAWebBotMessageSecret');
window.Store.BotProfiles = window.require('WAWebBotProfileCollection'); window.Store.BotProfiles = window.require('WAWebBotProfileCollection');
window.Store.DeviceList = window.require('WAWebApiDeviceList'); window.Store.DeviceList = window.require('WAWebApiDeviceList');
window.Store.HistorySync = window.require('WAWebSendNonMessageDataRequest'); window.Store.HistorySync = window.require('WAWebSendNonMessageDataRequest');
if (window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.1014111620')) if (window.compareWwebVersions(window.Debug.VERSION, '>=', '2.3000.1014111620'))
window.Store.AddonReactionTable = window.require('WAWebAddonReactionTableMode').reactionTableMode; window.Store.AddonReactionTable = window.require('WAWebAddonReactionTableMode').reactionTableMode;
window.Store.Settings = {
...window.require('WAWebUserPrefsGeneral'),
...window.require('WAWebUserPrefsNotifications')
};
window.Store.NumberInfo = { window.Store.NumberInfo = {
...window.require('WAPhoneUtils'), ...window.require('WAPhoneUtils'),
...window.require('WAPhoneFindCC') ...window.require('WAPhoneFindCC')
@ -109,7 +112,6 @@ exports.ExposeStore = () => {
window.Store.ForwardUtils = { window.Store.ForwardUtils = {
...window.require('WAWebForwardMessagesToChat') ...window.require('WAWebForwardMessagesToChat')
}; };
window.Store.StickerTools = { window.Store.StickerTools = {
...window.require('WAWebImageUtils'), ...window.require('WAWebImageUtils'),
...window.require('WAWebAddWebpMetadata') ...window.require('WAWebAddWebpMetadata')