summarylogtreecommitdiffstats
path: root/replugged.patch
blob: 5fe6c7a7c49846573bb1fbc46cbe4e68a40c2635 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
diff --git a/src/Powercord/coremods/moduleManager/components/manage/Base.jsx b/src/Powercord/coremods/moduleManager/components/manage/Base.jsx
index 0b8a45d9..3e69cf77 100644
--- a/src/Powercord/coremods/moduleManager/components/manage/Base.jsx
+++ b/src/Powercord/coremods/moduleManager/components/manage/Base.jsx
@@ -3,6 +3,7 @@ const { shell } = require('electron');
 const { React, getModule, contextMenu, i18n: { Messages } } = require('powercord/webpack');
 const { Button, Tooltip, ContextMenu, Divider, Icons: { Overflow } } = require('powercord/components');
 const { TextInput } = require('powercord/components/settings');
+const XDG_DATA_HOME = process.env.XDG_DATA_HOME || join(process.env.HOME, '.local', 'share');
 
 class Base extends React.Component {
   constructor () {
@@ -91,7 +92,7 @@ class Base extends React.Component {
           {
             type: 'button',
             name: Messages[`REPLUGGED_${this.state.key}_OPEN_FOLDER`],
-            onClick: () => shell.openPath(join(__dirname, '..', '..', '..', '..', '..', '..', this.constructor.name.toLowerCase()))
+            onClick: () => shell.openPath(join(XDG_DATA_HOME, 'replugged', this.constructor.name.toLowerCase()))
           },
           {
             type: 'button',
diff --git a/src/Powercord/coremods/moduleManager/index.js b/src/Powercord/coremods/moduleManager/index.js
index 2c3a2a9d..14b0f77a 100644
--- a/src/Powercord/coremods/moduleManager/index.js
+++ b/src/Powercord/coremods/moduleManager/index.js
@@ -6,7 +6,7 @@ const { React, getModule, i18n: { Messages } } = require('powercord/webpack');
 const { PopoutWindow } = require('powercord/components');
 const { inject, uninject } = require('powercord/injector');
 const { findInReactTree, forceUpdateElement } = require('powercord/util');
-const { SpecialChannels: { CSS_SNIPPETS, STORE_PLUGINS, STORE_THEMES }, WEBSITE } = require('powercord/constants');
+const { SpecialChannels: { CSS_SNIPPETS, STORE_PLUGINS, STORE_THEMES }, WEBSITE, SETTINGS_FOLDER } = require('powercord/constants');
 const { join } = require('path');
 const commands = require('./commands');
 const deeplinks = require('./deeplinks');
@@ -23,7 +23,7 @@ const { injectContextMenu } = require('powercord/util');
 const Menu = getModule([ 'MenuItem' ], false);
 
 let _quickCSS = '';
-const _quickCSSFile = join(__dirname, '..', '..', '..', '..', 'settings', 'quickcss', 'main.css');
+const _quickCSSFile = join(SETTINGS_FOLDER, 'quickcss', 'main.css');
 let _quickCSSElement;
 
 async function _installerInjectCtxMenu () {
diff --git a/src/Powercord/coremods/moduleManager/util/cloneRepo.js b/src/Powercord/coremods/moduleManager/util/cloneRepo.js
index f015ea76..eb058858 100644
--- a/src/Powercord/coremods/moduleManager/util/cloneRepo.js
+++ b/src/Powercord/coremods/moduleManager/util/cloneRepo.js
@@ -4,16 +4,18 @@ const fs = require('fs');
 const { REPO_URL_REGEX } = require('./misc');
 const { i18n: { Messages } } = require('powercord/webpack');
 
+const XDG_DATA_HOME = process.env.XDG_DATA_HOME || join(process.env.HOME, '.local', 'share');
+
 module.exports = async function download (url, powercord, type) {
   return new Promise((resolve) => {
   // const dir = type === 'plugin' ? join(__dirname, '..', '..') : join(__dirname, '..', '..', 'themes');
     let dir;
     switch (type) {
       case 'plugin':
-        dir = join(__dirname, '..', '..', '..', '..', '..', 'plugins');
+        dir = join(XDG_DATA_HOME, 'replugged', 'plugins');
         break;
       case 'theme':
-        dir = join(__dirname, '..', '..', '..', '..', '..', 'themes');
+        dir = join(XDG_DATA_HOME, 'replugged', 'themes');
         break;
     }
 
diff --git a/src/Powercord/coremods/updater/components/Settings.jsx b/src/Powercord/coremods/updater/components/Settings.jsx
index b915af1c..fbe64da4 100644
--- a/src/Powercord/coremods/updater/components/Settings.jsx
+++ b/src/Powercord/coremods/updater/components/Settings.jsx
@@ -82,7 +82,7 @@ module.exports = class UpdaterSettings extends React.PureComponent {
         <div className="about">
           <div>
             <span>{Messages.REPLUGGED_UPDATES_UPSTREAM}</span>
-            <span>{powercord.gitInfos.upstream.replace(REPO_URL, Messages.REPLUGGED_UPDATES_UPSTREAM_OFFICIAL)}</span>
+            <span>{powercord.gitInfos.upstream.replace(REPO_URL, Messages.REPLUGGED_UPDATES_UPSTREAM_OFFICIAL+' (AUR)')}</span>
           </div>
           <div>
             <span>{Messages.REPLUGGED_UPDATES_REVISION}</span>
diff --git a/src/Powercord/coremods/updater/components/Update.jsx b/src/Powercord/coremods/updater/components/Update.jsx
index 7d8fbcaa..ab5be0e9 100644
--- a/src/Powercord/coremods/updater/components/Update.jsx
+++ b/src/Powercord/coremods/updater/components/Update.jsx
@@ -28,6 +28,7 @@ module.exports = class Update extends React.PureComponent {
         </div>
       </div>
       <div className='summary'>
+        {name === 'Powercord' ? <span>Note: Please download the update from the AUR!</span> : ''}
         {commits.map(commit => <div key={commit.id}>
           <a href={`https://github.com/${repo}/commit/${commit.id}`} target='_blank'>
             <code>{commit.id.substring(0, 7)}</code>
diff --git a/src/Powercord/coremods/updater/index.js b/src/Powercord/coremods/updater/index.js
index 770e195a..e542774c 100644
--- a/src/Powercord/coremods/updater/index.js
+++ b/src/Powercord/coremods/updater/index.js
@@ -44,9 +44,6 @@ class Updater {
     const themes = [ ...powercord.styleManager.themes.values() ];
 
     const entities = plugins.concat(themes).filter(e => !disabled.includes(e.updateIdentifier) && e.isUpdatable());
-    if (!disabled.includes(powercord.updateIdentifier)) {
-      entities.push(powercord);
-    }
 
     let done = 0;
     const updates = [];
@@ -232,33 +229,10 @@ class Updater {
   }
 
   async getGitInfos () {
-    const branch = await PowercordNative.exec('git branch', this.cwd)
-      .then(({ stdout }) =>
-        stdout
-          .toString()
-          .split('\n')
-          .find(l => l.startsWith('*'))
-          .slice(2)
-          .trim()
-      );
-
-    const revision = await PowercordNative.exec(`git rev-parse ${branch}`, this.cwd)
-      .then(r => r.stdout.toString().trim());
-
-    let upstream = '???';
-
-    const remoteBranch = await powercord.getUpstreamBranch();
-    if (remoteBranch) {
-      const remote = remoteBranch.split('/')[0];
-      upstream = await PowercordNative.exec(`git remote get-url ${remote}`, this.cwd)
-        .then(r => r.stdout.toString().match(/github\.com[:/]([\w-_]+\/[\w-_]+)/)?.[1] ||
-          r.stdout.toString().trim().match(/(.*):(.*\/.*)/)[2]);
-    }
-
     return {
-      upstream,
-      branch,
-      revision
+      upstream: "@PKG_UPSTREAM@",
+      branch: "@PKG_BRANCH@",
+      revision: "@PKG_REVISION@"
     };
   }
 
diff --git a/src/Powercord/index.js b/src/Powercord/index.js
index 1ff93b59..2a0d9529 100644
--- a/src/Powercord/index.js
+++ b/src/Powercord/index.js
@@ -253,6 +253,32 @@ class Powercord extends Updatable {
     }
     return success;
   }
+
+  async _getUpdateCommits () {
+    return [];
+  }
+  async getBranch () {return this.gitInfos.branch;}
+  async getGitRepo () {return this.gitInfos.upstream;}
+  async _checkForUpdates () {
+    const abort = new AbortController();
+    const timeout = setTimeout(() => {
+      abort.abort();
+      throw new Error('Timed out.');
+    }, 10000);
+
+    try {
+      const latestCommitSha = await exec(`curl https://api.github.com/repos/${this.gitInfos.upstream}/commits/${this.gitInfos.branch} | jq -r .sha`, {
+        cwd: this.entityPath,
+        signal: abort.signal
+      }).then(({ stdout }) => stdout.toString());
+
+      clearTimeout(timeout);
+      return !latestCommitSha.includes(this.gitInfos.revision);
+    } catch (e) {
+      clearTimeout(timeout);
+      return false;
+    }
+  }
 }
 
 module.exports = Powercord;
diff --git a/src/Powercord/managers/plugins.js b/src/Powercord/managers/plugins.js
index c45b34fe..f0cd4dea 100644
--- a/src/Powercord/managers/plugins.js
+++ b/src/Powercord/managers/plugins.js
@@ -1,10 +1,12 @@
-const { resolve } = require('path');
+const { resolve, join } = require('path');
 const { readdirSync } = require('fs');
 const { rmdirRf } = require('powercord/util');
 
+const XDG_DATA_HOME = process.env.XDG_DATA_HOME || join(process.env.HOME, '.local', 'share');
+
 module.exports = class PluginManager {
   constructor () {
-    this.pluginDir = resolve(__dirname, '..', '..', '..', 'plugins');
+    this.pluginDir = resolve(XDG_DATA_HOME, 'replugged', 'plugins');
     this.plugins = new Map();
 
     this.manifestKeys = [ 'name', 'version', 'description', 'author', 'license' ];
diff --git a/src/Powercord/managers/styles.js b/src/Powercord/managers/styles.js
index c5b184e4..118b5025 100644
--- a/src/Powercord/managers/styles.js
+++ b/src/Powercord/managers/styles.js
@@ -14,10 +14,12 @@ const ErrorTypes = Object.freeze({
   INVALID_MANIFEST: 'INVALID_MANIFEST'
 });
 
+const XDG_DATA_HOME = process.env.XDG_DATA_HOME || join(process.env.HOME, '.local', 'share');
+
 module.exports = class StyleManager {
   constructor () {
     this._coreStyles = [];
-    this.themesDir = join(__dirname, '..', '..', '..', 'themes');
+    this.themesDir = join(XDG_DATA_HOME, 'replugged', 'themes');
     this.themes = new Map();
 
     if (!window.__SPLASH__) {
diff --git a/src/browserWindow.js b/src/browserWindow.js
index 82620e56..cafc41a0 100644
--- a/src/browserWindow.js
+++ b/src/browserWindow.js
@@ -28,7 +28,6 @@ class PatchedBrowserWindow extends BrowserWindow {
       if (opts.webPreferences.nativeWindowOpen) {
         // Discord Client
         opts.webPreferences.preload = join(__dirname, './preload.js');
-        opts.webPreferences.contextIsolation = false; // shrug
       } else {
         // Splash Screen on macOS (Host 0.0.262+) & Windows (Host 0.0.293 / 1.0.17+)
         opts.webPreferences.preload = join(__dirname, './preloadSplash.js');
diff --git a/src/fake_node_modules/powercord/constants.js b/src/fake_node_modules/powercord/constants.js
index 147e02e9..948f2b02 100644
--- a/src/fake_node_modules/powercord/constants.js
+++ b/src/fake_node_modules/powercord/constants.js
@@ -1,5 +1,9 @@
 const { join } = require('path');
 
+const XDG_CONFIG_HOME = process.env.XDG_CONFIG_HOME || join(process.env.HOME, '.config');
+const XDG_CACHE_HOME  = process.env.XDG_CACHE_HOME  || join(process.env.HOME, '.cache');
+const XDG_DATA_HOME  = process.env.XDG_DATA_HOME    || join(process.env.HOME, '.local', 'share');
+
 module.exports = Object.freeze({
   // Replugged
   WEBSITE: 'https://replugged.dev',
@@ -7,9 +11,9 @@ module.exports = Object.freeze({
   REPO_URL: 'replugged-org/replugged',
 
   // Runtime
-  SETTINGS_FOLDER: join(__dirname, '..', '..', '..', 'settings'),
-  CACHE_FOLDER: join(__dirname, '..', '..', '..', '.cache'),
-  LOGS_FOLDER: join(__dirname, '..', '..', '..', '.logs'),
+  SETTINGS_FOLDER: join(XDG_CONFIG_HOME, 'replugged'),
+  CACHE_FOLDER: join(XDG_CACHE_HOME, 'replugged'),
+  LOGS_FOLDER: join(XDG_DATA_HOME, 'replugged', 'logs'),
 
   // Discord Server
   DISCORD_INVITE: 'B2TcnXV9Rg',
diff --git a/src/patcher.js b/src/patcher.js
index 372e41f5..a8d59761 100644
--- a/src/patcher.js
+++ b/src/patcher.js
@@ -7,7 +7,7 @@ const { existsSync, unlinkSync } = require('fs');
 
 // Restore the classic path; The updater relies on it and it makes Discord go corrupt
 const electronPath = require.resolve('electron');
-const discordPath = join(dirname(require.main.filename), '..', 'app.asar');
+const discordPath = join('/', 'usr', 'lib', 'discord-canary', 'app.asar');
 require.main.filename = join(discordPath, 'app_bootstrap/index.js');
 
 const electron = require('electron');