diff --git a/example.js b/example.js index 3334e5b..f601b26 100644 --- a/example.js +++ b/example.js @@ -470,6 +470,10 @@ client.on('message', async msg => { console.log(statuses); const chat = await statuses[0]?.getChat(); // Get user chat of a first status 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); } }); diff --git a/index.d.ts b/index.d.ts index a6c3250..a26e4dc 100644 --- a/index.d.ts +++ b/index.d.ts @@ -180,6 +180,13 @@ declare namespace WAWebJS { */ setAutoDownloadVideos(flag: boolean): Promise + /** + * 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 + /** * Get user device count by ID * Each WaWeb Connection counts as one device, and the phone (if exists) counts as one diff --git a/src/Client.js b/src/Client.js index 70a1418..6779723 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1721,6 +1721,23 @@ class Client extends EventEmitter { }, flag); } + /** + * Setting background synchronization. + * NOTE: this action will take effect after you restart the client. + * @param {boolean} flag true/false + * @returns {Promise} + */ + 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 * Each WaWeb Connection counts as one device, and the phone (if exists) counts as one diff --git a/src/util/Injected/Store.js b/src/util/Injected/Store.js index 3aae7b2..d9ef224 100644 --- a/src/util/Injected/Store.js +++ b/src/util/Injected/Store.js @@ -93,14 +93,17 @@ exports.ExposeStore = () => { window.Store.pinUnpinMsg = window.require('WAWebSendPinMessageAction').sendPinInChatMsg; window.Store.QueryExist = window.require('WAWebQueryExistsJob').queryWidExists; window.Store.ReplyUtils = window.require('WAWebMsgReply'); - window.Store.Settings = window.require('WAWebUserPrefsGeneral'); window.Store.BotSecret = window.require('WAWebBotMessageSecret'); window.Store.BotProfiles = window.require('WAWebBotProfileCollection'); window.Store.DeviceList = window.require('WAWebApiDeviceList'); 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.Settings = { + ...window.require('WAWebUserPrefsGeneral'), + ...window.require('WAWebUserPrefsNotifications') + }; window.Store.NumberInfo = { ...window.require('WAPhoneUtils'), ...window.require('WAPhoneFindCC') @@ -109,7 +112,6 @@ exports.ExposeStore = () => { window.Store.ForwardUtils = { ...window.require('WAWebForwardMessagesToChat') }; - window.Store.StickerTools = { ...window.require('WAWebImageUtils'), ...window.require('WAWebAddWebpMetadata')