Skip to content

Commit dbe5eac

Browse files
committed
Add Windows Support
1 parent 043b4e4 commit dbe5eac

File tree

5 files changed

+184
-11
lines changed

5 files changed

+184
-11
lines changed

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,34 @@ Tested on Postman versions from ***`8.1.0`*** to ***`8.10.0`***
1616
* `cd Postman-Scratchpad-Banner-Fix`
1717
* Run ***`npm install`*** to install dependencies
1818

19+
# Linux and MacOS
1920
# Usage
2021
## Patch your already installed postman
21-
Run ***`node fix.js -r ${requester_js}`*** , where ***`${requester_js}`*** is Postman file which renders scratchpad banner
22+
Run ***`node fix.js -r ${requester_js}`*** , where ***`${requester_js}`*** is Postman file (***`requester.js`***) which renders scratchpad banner
2223

23-
### requester.js path:
24+
### `requester.js` path:
2425

2526
* For Linux users, requester.js is used
2627
It can be found on path like this: ***`${Postman_install_dir}/resources/app/js/requester.js`***
2728

2829
* For MacOS users, requester.js is used
2930
It can be found on path like this: ***`${Postman_install_dir}/Contents/Resources/app/js/requester.js`***
3031

31-
## Download prepatch postman
32+
## Download patched postman
3233
You can find downloads for linux and macos at [Releases](https://github.com/3omar-mostafa/Postman-Scratchpad-Banner-Fix/releases)
3334

34-
Windows is not included because its installer is `exe` file which I can not extract and re-create the installer, but you can still patch you existing installation
35+
# Windows
36+
# Usage
37+
## Patch your already installed postman
38+
Run ***`node fix.js -a ${app_asar}`*** , where ***`${app_asar}`*** is Postman file (***`app.asar`***) which is like a `tar` archive and contains most of postman's files
39+
40+
### `app.asar` path:
41+
It can be found on path like this: ***`%localappdata%\Postman\app-8.10.0\resources\app.asar`***
42+
43+
You can learn more about *`asar`* file format [from here](https://github.com/electron/asar).
44+
45+
## Download patched postman
46+
Windows is not included because its installer is *`exe`* file which I can extract and patch the files, but unfortunately I can not re-create the same installer, but you can still patch you existing installation
3547

3648
# Methodology and Manual Patching
3749
The file which is responsible for displaying scratchpad banner is ***`requester.js`***

fix.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/usr/bin/env node
22

33
let fs = require('fs');
4+
let path = require('path');
5+
let os = require('os')
46
let esprima = require('esprima');
57
let colors = require('chalk'); // print colored text into console
8+
let asar = require('asar');
69
let { args } = require('./parse_args');
710
let { findNestedObject, replaceRangeInString, printDebug } = require("./utils");
811

@@ -18,9 +21,10 @@ function injectCode(rawFileData, searchQuery, replaceString) {
1821
return rawFileData;
1922
}
2023

21-
(async function () {
2224

23-
let data = String(await fs.readFileSync(args.requester_js));
25+
async function fixPostmanScratchpadBanner(requester_js_path) {
26+
27+
let data = String(await fs.readFileSync(requester_js_path));
2428

2529
let getWorkingInScratchpadBanner = {
2630
query: {
@@ -52,8 +56,28 @@ function injectCode(rawFileData, searchQuery, replaceString) {
5256

5357
data = injectCode(data, CONST_SHOW_BANNER_IN_SCRATCHPAD.query, CONST_SHOW_BANNER_IN_SCRATCHPAD.replaceString);
5458

55-
console.log(colors.yellow(`[INFO] Saving the file into ${args.requester_js}`))
56-
await fs.writeFileSync(args.requester_js, data);
59+
console.log(colors.yellow(`[INFO] Saving the file into ${requester_js_path}`))
60+
await fs.writeFileSync(requester_js_path, data);
61+
62+
}
63+
64+
(async function () {
65+
66+
if (args.app_asar) {
67+
let tmpDir = path.join(os.tmpdir(), "postman_app.asar_extracted");
68+
asar.extractAll(args.app_asar, tmpDir);
69+
console.log(colors.yellow(`[INFO] Extracted ${args.app_asar} into ${tmpDir}`));
70+
let requester_js = path.join(tmpDir, 'js', 'requester.js');
71+
72+
await fixPostmanScratchpadBanner(requester_js);
73+
74+
await asar.createPackage(tmpDir, args.app_asar);
75+
console.log(colors.yellow(`[INFO] Archived ${tmpDir} back into ${args.app_asar}`));
76+
await fs.rmSync(tmpDir, { recursive: true });
77+
78+
} else {
79+
await fixPostmanScratchpadBanner(args.requester_js);
80+
}
5781

5882
}
5983
)()

package-lock.json

Lines changed: 121 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
},
1919
"homepage": "https://github.com/3omar-mostafa/Postman-Scratchpad-Banner-Fix#readme",
2020
"dependencies": {
21+
"asar": "^3.0.3",
2122
"chalk": "^4.1.2",
2223
"esprima": "^4.0.1",
2324
"lodash": "^4.17.21",

parse_args.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
let yargs = require('yargs');
22

3-
const usage = `npm run fix -r requester.js
3+
const usage = `npm run fix [-r requester.js] | [-a app.asar]
4+
You must only use -r or -a but not both
5+
6+
* For Windows users, app.asar is used
7+
It can be found on path like this: %localappdata%\\Postman\\app-8.10.0\\resources\\app.asar
48
59
* For Linux users, requester.js is used
610
It can be found on path like this: \${Postman_install_dir}/resources/app/js/requester.js
@@ -13,8 +17,19 @@ module.exports.args = yargs.usage(usage)
1317
.option('requester_js', {
1418
alias: 'r',
1519
describe: 'Path to requester.js file',
16-
nargs: 1,
17-
demandOption: true
20+
nargs: 1
21+
})
22+
.option('app_asar', {
23+
alias: 'a',
24+
describe: 'Path to app.asar file',
25+
nargs: 1
26+
})
27+
.conflicts('requester_js', 'app_asar')
28+
.check((argv) => {
29+
if (!(argv.app_asar || argv.requester_js)) {
30+
throw new Error("You need to provide either requester.js or app.asar");
31+
}
32+
return true;
1833
})
1934
.alias('h', 'help')
2035
.alias('v', 'version')

0 commit comments

Comments
 (0)