diff --git a/index.js b/index.js index 75dac50..7d2e281 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,7 @@ const fs = require('mz/fs'); const { app, BrowserWindow, + session } = require('electron'); const store = require('./modules/store/store'); const ctxMenu = require('./modules/menu/ctxMenu'); @@ -111,10 +112,22 @@ app.on("ready", () => { win.show(); }) - // Skip advertising - skipAdvert.init(); - // Notification for next sing - notifiNextSing.init(win); + let sendNotifi = notifiNextSing.init(win); + + session.defaultSession.webRequest.onBeforeRequest(['*'], (details, callback) => { + // Skip advertising + if (/awaps.yandex.net/.test(details.url) || /vh-bsvideo-converted/.test(details.url) || /get-video-an/.test(details.url)) { + return { + cancel: true + } + } + // Notification for next sing + if (/start\?__t/.test(details.url)) { + setTimeout(sendNotifi, 1000) + } + + callback(details); + }) }) app.on('before-quit', () => { diff --git a/modules/notifiNextSing.js b/modules/notifiNextSing.js index 39e92df..e6356b9 100644 --- a/modules/notifiNextSing.js +++ b/modules/notifiNextSing.js @@ -1,6 +1,3 @@ -const { - session -} = require('electron'); const notification = require('./notification/notification') const getTrack = ` @@ -42,12 +39,8 @@ const getImg = ` `; exports.init = (win) => { - session.defaultSession.webRequest.onBeforeRequest(['*'], (details, callback) => { - if (/start\?__t/.test(details.url)) { - setTimeout(sendNotifi, 1000) - } - callback(details); - }) + + return sendNotifi function sendNotifi() { Promise.all([getInfoFromDOM(getTrack), getInfoFromDOM(getArtist), getInfoFromDOM(getImg)]).then((v) => { diff --git a/modules/skipAdvert.js b/modules/skipAdvert.js deleted file mode 100644 index 198e276..0000000 --- a/modules/skipAdvert.js +++ /dev/null @@ -1,14 +0,0 @@ -const { - session -} = require('electron'); - -exports.init = () => { - session.defaultSession.webRequest.onBeforeRequest(['*'], (details, callback) => { - if (/awaps.yandex.net/.test(details.url) || /vh-bsvideo-converted/.test(details.url) || /get-video-an/.test(details.url)) { - return { - cancel: true - } - } - callback(details); - }) -} \ No newline at end of file diff --git a/package.json b/package.json index 2dcf2fe..64351a9 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "build:all": "npm run build:win && npm run build:linux && npm run build:mac", "build:win": "electron-packager . --platform=win32 --arch=all --icon=media/icon/yaradio_64x64.ico --name=yaMusic --executableName=yaMusic --out=distr/win --overwrite=true --ignore=distr", "build:linux": "electron-packager . --platform=linux --arch=all --icon=media/icon/yaradio_64x64.ico --name=yaMusic --executableName=yaMusic --out=distr/linux --overwrite=true --ignore=distr", - "build:mac": "electron-packager . --platform=darwin --arch=all --icon=media/icon/yaradio_64x64.icns --name=yaMusic --executableName=yaMusic --out=distr/mac --overwrite=true --appBundleId=yaMusic --appCategoryType=public.app-category.music --ignore=distr", + "build:mac": "electron-packager . --platform=darwin --arch=all --icon=media/icon/yaradio_64x64.icns --name=yaMusic --executableName=yaMusic --out=distr/mac --overwrite=true --app-bundle-id=yaMusic --app-category-type=public.app-category.music --ignore=distr", "gen:changelog": "github_changelog_generator -u dedpnd -p yaradio-yamusic" }, "repository": {