From 35d4d3494a496d07588259f893efdc612c1047d2 Mon Sep 17 00:00:00 2001
From: "Mr. Stallion" <mrstallion@nobody.nowhere.fauxdomain.ext>
Date: Sat, 31 Oct 2020 16:25:28 -0500
Subject: [PATCH] Cleaner adblock fix

---
 chat/preview/CharacterPreview.vue |  2 +-
 electron/main.ts                  | 22 ++++++++++++----------
 electron/webpack.config.js        |  5 +++++
 3 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/chat/preview/CharacterPreview.vue b/chat/preview/CharacterPreview.vue
index 02b5fc3..a310852 100644
--- a/chat/preview/CharacterPreview.vue
+++ b/chat/preview/CharacterPreview.vue
@@ -133,7 +133,7 @@ export default class CharacterPreview extends Vue {
     }
 
     this.statusMessage = this.onlineCharacter.statusText;
-    this.statusClasses = getStatusClasses(this.onlineCharacter, undefined, true, true, false);
+    this.statusClasses = getStatusClasses(this.onlineCharacter, undefined, true, false, false);
   }
 
 
diff --git a/electron/main.ts b/electron/main.ts
index 0abb0d4..27f3714 100644
--- a/electron/main.ts
+++ b/electron/main.ts
@@ -236,11 +236,13 @@ function createWindow(): Electron.BrowserWindow | undefined {
 
             blocker.enableBlockingInSession(electron.session.defaultSession);
 
-            // Temp fix -- manually override adblocker's preload script 1) to point to CJS; 2) to use absolute path
-            const originPath = require.resolve('@cliqz/adblocker-electron-preload');
-            const preloadScript = path.resolve(path.dirname(originPath), 'preload.cjs.js');
+            // Temp fix -- manually override adblocker's preload script
+            // to point to CJS  that has been copied over with config in webpack.config.js
+            const preloadScript = './preview/assets/adblocker/preload.cjs.js'; // require.resolve('@cliqz/adblocker-electron-preload');
 
-            log.debug('adblock.preload.path', { finalPath: preloadScript, originPath });
+            // const originPath = require.resolve('@cliqz/adblocker-electron-preload');
+            // const preloadScript = path.resolve(path.dirname(originPath), 'preload.cjs.js');
+            log.debug('adblock.preload.path', { finalPath: preloadScript /*, originPath */ });
 
             electron.session.defaultSession.setPreloads(
                 _.concat(
@@ -252,28 +254,28 @@ function createWindow(): Electron.BrowserWindow | undefined {
                 )
             );
 
-            log.debug('adblock.preloaders', { loaders: electron.session.defaultSession.getPreloads() })
+            log.debug('adblock.preloaders', { loaders: electron.session.defaultSession.getPreloads() });
 
             blocker.on('request-blocked', (request: Request) => {
                 log.debug('adblock.request.blocked', { url: request.url });
             });
-            
+
             blocker.on('request-redirected', (request: Request) => {
                 log.debug('adblock.request.redirected', { url: request.url });
             });
-            
+
             blocker.on('request-whitelisted', (request: Request) => {
                 log.debug('adblock.request.whitelisted', { url: request.url });
             });
-            
+
             blocker.on('csp-injected', (request: Request) => {
                 log.debug('adblock.inject.csp', { url: request.url });
             });
-            
+
             blocker.on('script-injected', (script: string, url: string) => {
                 log.debug('adblock.inject.script', { length: script.length, url });
             });
-            
+
             blocker.on('style-injected', (style: string, url: string) => {
                 log.debug('adblock.inject.style', { length: style.length, url });
             });
diff --git a/electron/webpack.config.js b/electron/webpack.config.js
index dcacc19..b575036 100644
--- a/electron/webpack.config.js
+++ b/electron/webpack.config.js
@@ -121,6 +121,11 @@ const mainConfig = {
                         from: path.resolve(__dirname, '..', 'chat', 'preview', 'assets', '**', '*').replace(/\\/g, '/'),
                         to: path.join('preview', 'assets'),
                         context: path.resolve(__dirname, '..', 'chat', 'preview', 'assets')
+                    },
+                    {
+                        from: path.resolve(__dirname, '..', 'node_modules', '@cliqz', 'adblocker-electron-preload', 'dist', 'preload.cjs.js').replace(/\\/g, '/'),
+                        to: path.join('preview', 'assets', 'adblocker'),
+                        context: path.resolve(__dirname, '..', 'node_modules', '@cliqz', 'adblocker-electron-preload', 'dist')
                     }
                 ]
             }