Skip to content

Commit

Permalink
[v1.0.1] Minor adjustments and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
GriefMoDz committed Jan 8, 2023
1 parent 66199aa commit 95f4a92
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 108 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ Formally known as "Online Friends Count", this is a Replugged plug-in that has b
- [ ] Add a settings page
- [ ] Implement a context menu to quickly change settings

## Settings
To customize the counter, you will need to manually set your preferences by entering the following method under your DevTools console (`Ctrl` + `Shift` + `I` and click on the "Console" tab):

```js
// Replace the `key` and `value` respectively - you can use the table below as a reference
(await replugged.settings.init('xyz.griefmodz.StatisticCounter')).set(key, value);
```

| Key | Description | Default |
| ------------------------ | ------------------------------ | ------- |
| `autoRotation` | Rotate between counters | `false` |
| `autoRotationDelay` | Delay between rotations | `3e4` |
| `autoRotationHoverPause` | Pause the rotation upon hover | `true` |
| `preserveLastCounter` | Remember the last counter | `false` |
| `online` | Enable online counter | `true` |
| `friends` | Enable friends counter | `true` |
| `pending` | Enable pending counter | `true` |
| `blocked` | Enable blocked counter | `true` |
| `guilds` | Enable servers counter | `true` |

## Previews

### Counter
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"discordID": "350227339784880130",
"github": "griefmodz"
},
"version": "1.0.0",
"version": "1.0.1",
"updater": {
"type": "github",
"id": "griefmodz/statistic-counter"
},
"license": "OSL-3.0",
"license": "MIT",
"type": "replugged-plugin",
"renderer": "src/index.tsx"
}
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "statistic-counter",
"version": "1.0.0",
"version": "1.0.1",
"description": "A Replugged plug-in that has been ported from Powercord which introduces an interchangeable statistic counter in-between the home button and servers list.",
"engines": {
"node": ">=14.0.0"
Expand All @@ -20,10 +20,9 @@
},
"keywords": [],
"author": "",
"license": "OSL-3.0",
"license": "MIT",
"devDependencies": {
"@electron/asar": "^3.2.1",
"@fal-works/esbuild-plugin-global-externals": "^2.1.2",
"@types/node": "^18.11.2",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
Expand All @@ -33,7 +32,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-react": "^7.31.10",
"prettier": "^2.8.1",
"replugged": "4.0.0-beta0.19",
"replugged": "4.0.0-beta0.20",
"tsx": "^3.10.3",
"typescript": "^4.8.4"
}
Expand Down
14 changes: 4 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

169 changes: 92 additions & 77 deletions scripts/build.ts
Original file line number Diff line number Diff line change
@@ -1,149 +1,164 @@
import esbuild from 'esbuild';
import { globalExternals } from '@fal-works/esbuild-plugin-global-externals';
import path, { join } from 'path';
import fs, { existsSync, rmSync } from 'fs';
import _manifest from '../manifest.json';
import { Plugin } from 'replugged/dist/types/addon';

const manifest: Plugin = _manifest;

const NODE_VERSION = '14';
const CHROME_VERSION = '91';

const globalModules = {
replugged: {
varName: 'replugged',
namedExports: [
'Injector',
'Logger',
'webpack',
'common',
'notices',
'commands',
'settings',
'quickCSS',
'themes',
'ignition',
'plugins',
'util',
'types'
],
defaultExport: true
}
import esbuild from "esbuild";
import path, { join } from "path";
import fs, { existsSync, rmSync } from "fs";
import _manifest from "../manifest.json";
import { PluginManifest } from "replugged/dist/types/addon";

const manifest: PluginManifest = _manifest;

const NODE_VERSION = "14";
const CHROME_VERSION = "91";

const globalModules: esbuild.Plugin = {
name: "globalModules",
setup: (build) => {
build.onResolve({ filter: /^replugged.+$/ }, (args) => {
if (args.kind !== "import-statement") return;

return {
errors: [
{
text: `Importing from a path (${args.path}) is not supported. Instead, please import from "replugged" and destructure the required modules.`,
},
],
};
});

build.onResolve({ filter: /^replugged$/ }, (args) => {
if (args.kind !== "import-statement") return;

return {
path: args.path,
namespace: "replugged",
};
});

build.onLoad(
{
filter: /.*/,
namespace: "replugged",
},
() => {
return {
contents: "module.exports = window.replugged",
};
},
);
},
};

const REPLUGGED_FOLDER_NAME = 'replugged';
const REPLUGGED_FOLDER_NAME = "replugged";
export const CONFIG_PATH = (() => {
switch (process.platform) {
case 'win32':
return join(process.env.APPDATA || '', REPLUGGED_FOLDER_NAME);
case 'darwin':
return join(process.env.HOME || '', 'Library', 'Application Support', REPLUGGED_FOLDER_NAME);
case "win32":
return join(process.env.APPDATA || "", REPLUGGED_FOLDER_NAME);
case "darwin":
return join(process.env.HOME || "", "Library", "Application Support", REPLUGGED_FOLDER_NAME);
default:
if (process.env.XDG_CONFIG_HOME) {
return join(process.env.XDG_CONFIG_HOME, REPLUGGED_FOLDER_NAME);
}
return join(process.env.HOME || '', '.config', REPLUGGED_FOLDER_NAME);
return join(process.env.HOME || "", ".config", REPLUGGED_FOLDER_NAME);
}
})();

const install: esbuild.Plugin = {
name: 'install',
name: "install",
setup: (build) => {
build.onEnd(() => {
if (!process.env.NO_INSTALL) {
const dest = join(CONFIG_PATH, 'plugins', manifest.id);
const dest = join(CONFIG_PATH, "plugins", manifest.id);
if (existsSync(dest)) {
rmSync(dest, { recursive: true });
}
fs.cpSync('dist', dest, { recursive: true });
console.log('Installed updated version');
fs.cpSync("dist", dest, { recursive: true });
console.log("Installed updated version");
}
});
}
},
};

const watch = process.argv.includes('--watch');
const watch = process.argv.includes("--watch");

const common: esbuild.BuildOptions = {
absWorkingDir: path.join(__dirname, '..'),
absWorkingDir: path.join(__dirname, ".."),
bundle: true,
minify: false,
sourcemap: true,
format: 'cjs' as esbuild.Format,
logLevel: 'info',
format: "cjs" as esbuild.Format,
logLevel: "info",
watch,
plugins: [install]
plugins: [install],
};

const targets = [];

if ('renderer' in manifest) {
if ("renderer" in manifest) {
targets.push(
esbuild.build({
...common,
entryPoints: [manifest.renderer],
platform: 'browser',
platform: "browser",
target: `chrome${CHROME_VERSION}`,
outfile: 'dist/renderer.js',
format: 'esm' as esbuild.Format,
plugins: [globalExternals(globalModules), install]
})
outfile: "dist/renderer.js",
format: "esm" as esbuild.Format,
plugins: [globalModules, install],
}),
);

manifest.renderer = 'renderer.js';
manifest.renderer = "renderer.js";
}

if ('preload' in manifest) {
if ("preload" in manifest) {
targets.push(
esbuild.build({
...common,
entryPoints: [manifest.preload],
platform: 'node',
platform: "node",
target: [`node${NODE_VERSION}`, `chrome${CHROME_VERSION}`],
outfile: 'dist/preload.js',
external: ['electron']
})
outfile: "dist/preload.js",
external: ["electron"],
}),
);

manifest.preload = 'preload.js';
manifest.preload = "preload.js";
}

if ('main' in manifest) {
if ("main" in manifest) {
targets.push(
esbuild.build({
...common,
entryPoints: [manifest.main],
platform: 'node',
platform: "node",
target: `node${NODE_VERSION}`,
outfile: 'dist/main.js',
external: ['electron']
})
outfile: "dist/main.js",
external: ["electron"],
}),
);

manifest.main = 'main.js';
manifest.main = "main.js";
}

if ('plaintextPatches' in manifest) {
if ("plaintextPatches" in manifest) {
targets.push(
esbuild.build({
...common,
entryPoints: [manifest.plaintextPatches],
platform: 'browser',
platform: "browser",
target: `chrome${CHROME_VERSION}`,
outfile: 'dist/plaintextPatches.js',
format: 'esm' as esbuild.Format,
plugins: [globalExternals(globalModules), install]
})
outfile: "dist/plaintextPatches.js",
format: "esm" as esbuild.Format,
plugins: [globalModules, install],
}),
);

manifest.plaintextPatches = 'plaintextPatches.js';
manifest.plaintextPatches = "plaintextPatches.js";
}

if (!fs.existsSync('dist')) {
fs.mkdirSync('dist');
if (!fs.existsSync("dist")) {
fs.mkdirSync("dist");
}

fs.writeFileSync('dist/manifest.json', JSON.stringify(manifest));
fs.writeFileSync("dist/manifest.json", JSON.stringify(manifest));

Promise.all(targets);
10 changes: 5 additions & 5 deletions scripts/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asar from '@electron/asar';
import { readFileSync } from 'fs';
import { Plugin } from 'replugged/dist/types/addon';
import asar from "@electron/asar";
import { readFileSync } from "fs";
import { PluginManifest } from "replugged/dist/types/addon";

const manifest = JSON.parse(readFileSync('manifest.json', 'utf-8')) as Plugin;
const manifest = JSON.parse(readFileSync("manifest.json", "utf-8")) as PluginManifest;
const outputName = `${manifest.id}.asar`;

asar.createPackage('dist', outputName);
asar.createPackage("dist", outputName);
Loading

0 comments on commit 95f4a92

Please sign in to comment.