mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Clipper: Make dev icon look different and run dev server on different port
This commit is contained in:
parent
a2da2f681c
commit
0938297250
@ -7,6 +7,10 @@ if (typeof browser !== 'undefined') {
|
||||
browserSupportsPromises_ = false;
|
||||
}
|
||||
|
||||
function env() {
|
||||
return !('update_url' in browser_.runtime.getManifest()) ? 'dev' : 'prod';
|
||||
}
|
||||
|
||||
async function browserCaptureVisibleTabs(windowId, options) {
|
||||
if (browserSupportsPromises_) return browser_.tabs.captureVisibleTab(windowId, { format: 'jpeg' });
|
||||
|
||||
@ -17,8 +21,12 @@ async function browserCaptureVisibleTabs(windowId, options) {
|
||||
});
|
||||
}
|
||||
|
||||
chrome.runtime.onInstalled.addListener(function() {
|
||||
|
||||
browser_.runtime.onInstalled.addListener(function() {
|
||||
if (env() === 'dev') {
|
||||
browser_.browserAction.setIcon({
|
||||
path: 'icons/32-dev.png',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
browser_.runtime.onMessage.addListener((command) => {
|
||||
@ -37,4 +45,4 @@ browser_.runtime.onMessage.addListener((command) => {
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
BIN
Clipper/joplin-webclipper/icons/32-dev.png
Normal file
BIN
Clipper/joplin-webclipper/icons/32-dev.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
@ -35,9 +35,15 @@ class Bridge {
|
||||
|
||||
this.browser_.runtime.onMessage.addListener(this.browser_notify);
|
||||
|
||||
console.info('Popup: Env: ', this.env());
|
||||
|
||||
this.findClipperServerPort();
|
||||
}
|
||||
|
||||
env() {
|
||||
return !('update_url' in this.browser().runtime.getManifest()) ? 'dev' : 'prod';
|
||||
}
|
||||
|
||||
browser() {
|
||||
return this.browser_;
|
||||
}
|
||||
@ -49,7 +55,7 @@ class Bridge {
|
||||
async findClipperServerPort() {
|
||||
let state = null;
|
||||
for (let i = 0; i < 10; i++) {
|
||||
state = randomClipperPort(state);
|
||||
state = randomClipperPort(state, this.env());
|
||||
|
||||
try {
|
||||
console.info('findClipperServerPort: Trying ' + state.port);
|
||||
|
@ -132,13 +132,15 @@ const AleaModule = function () {
|
||||
|
||||
const Alea = AleaModule()
|
||||
|
||||
function findClipperPort(state) {
|
||||
function findClipperPort(state, mode = 'prod') {
|
||||
const seed = mode === 'prod' ? 1867 : 2001;
|
||||
|
||||
const minPort = 1024
|
||||
const maxPort = 49151
|
||||
|
||||
let prng = null;
|
||||
if (!state) {
|
||||
prng = new Alea(1867)
|
||||
prng = new Alea(seed)
|
||||
state = { prng: prng }
|
||||
} else {
|
||||
prng = state.prng;
|
||||
|
@ -203,7 +203,7 @@ class ClipperServer {
|
||||
|
||||
let state = null;
|
||||
for (let i = 0; i < 10000; i++) {
|
||||
state = randomClipperPort(state);
|
||||
state = randomClipperPort(state, Setting.value('env'));
|
||||
const inUse = await tcpPortUsed.check(state.port);
|
||||
if (!inUse) return state.port;
|
||||
}
|
||||
|
@ -132,13 +132,15 @@ const AleaModule = function () {
|
||||
|
||||
const Alea = AleaModule()
|
||||
|
||||
function findClipperPort(state) {
|
||||
function randomClipperPort(state, env) {
|
||||
const seed = env === 'prod' ? 1867 : 2001;
|
||||
|
||||
const minPort = 1024
|
||||
const maxPort = 49151
|
||||
|
||||
let prng = null;
|
||||
if (!state) {
|
||||
prng = new Alea(1867)
|
||||
prng = new Alea(seed)
|
||||
state = { prng: prng }
|
||||
} else {
|
||||
prng = state.prng;
|
||||
@ -161,4 +163,4 @@ function findClipperPort(state) {
|
||||
return state;
|
||||
}
|
||||
|
||||
module.exports = findClipperPort;
|
||||
module.exports = randomClipperPort;
|
Loading…
Reference in New Issue
Block a user