Skip to content

Commit

Permalink
Release 1.4.0
Browse files Browse the repository at this point in the history
- Allow to customize the port in case that can't find available port automatically. Fixed [Issue #117](#117).
- Optimize the sound request cycle when the server is down. Fixed [Issue #110](#110
  • Loading branch information
SaekiRaku committed Jul 13, 2020
1 parent c453f00 commit 892ee52
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 9 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to the "vscode-rainbow-fart" extension will be documented in

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [1.4.0] - 2020-06-30

### Added

- Allow to customize the port in case that can't find available port automatically. Fixed [Issue #117](https://github.com/SaekiRaku/vscode-rainbow-fart/issues/117).

### Fixed

- Optimize the sound request cycle when the server is down. Fixed [Issue #110](https://github.com/SaekiRaku/vscode-rainbow-fart/issues/110)

## [1.3.0] - 2020-06-29

### Added
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.0
1.4.0
10 changes: 10 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to the "vscode-rainbow-fart" extension will be documented in

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [1.4.0] - 2020-06-30

### Added

- Allow to customize the port in case that can't find available port automatically. Fixed [Issue #117](https://github.com/SaekiRaku/vscode-rainbow-fart/issues/117).

### Fixed

- Optimize the sound request cycle when the server is down. Fixed [Issue #110](https://github.com/SaekiRaku/vscode-rainbow-fart/issues/110)

## [1.3.0] - 2020-06-29

### Added
Expand Down
2 changes: 1 addition & 1 deletion docs/global.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
window.VERSION = "1.3.0";
window.VERSION = "1.4.0";
window.URL_PREFIX = location.pathname === "/" ? "" : location.pathname;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "rainbow-fart",
"displayName": "🌈 Rainbow Fart",
"description": "This extension will keep giving you compliment while you are coding.",
"version": "1.3.0",
"version": "1.4.0",
"engines": {
"vscode": "^1.33.0"
},
Expand Down
7 changes: 6 additions & 1 deletion src/commands.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
const vscode = require('vscode');
const { registerCommand } = vscode.commands;
const share = require("./share.js");
const initService = require("./service.js");

module.exports = function (context) {
context.subscriptions.push(registerCommand('rainbow-fart.enable', function () {
share.showTip && share.showTip();
if (share.showTip) {
share.showTip();
} else {
initService();
}
}));
}
4 changes: 2 additions & 2 deletions src/findAvailablePort.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ async function checkAvailable(port) {
return true;
}

module.exports = async function(port) {
while (true) {
module.exports = async function (port, retry = Infinity) {
for (let i = 0; i < retry; i++){
let available = await checkAvailable(port);
if (!available) {
port += Math.ceil(Math.random() * 7);
Expand Down
26 changes: 26 additions & 0 deletions src/message/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const messages = require("./messages.json");

let locale;
const currentLanguage = JSON.parse(process.env.VSCODE_NLS_CONFIG).locale;
const supportLanguage = ["en", "zh"]
if (supportLanguage.indexOf(currentLanguage) != -1) {
locale = currentLanguage
} else {
for (let lang of supportLanguage) {
if (currentLanguage.indexOf(lang) == 0) {
locale = lang;
break;
}
}
}

module.exports = function (str) {
let result = messages[locale] || messages["en"];
let props = str.split(".");
props.forEach(prop => { result = result[prop] });
if (!result && locale != "en") {
result = messages["en"];
props.forEach(prop => { result = result[prop] });
}
return result;
}
24 changes: 24 additions & 0 deletions src/message/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"en": {
"service": {
"require-port": {
"title": "Can't find available port after retry 3 times, please provide one.",
"placeholder": "E.g. 7777, 6666, 5555 ...",
"available": "✅ Current port is available, please press Enter to confirm.",
"unavailable": "❌ Current port is unavailable, please change."
},
"failed": "Can't enable Rainbow Fart, please retry."
}
},
"zh": {
"service": {
"require-port": {
"title": "经过 3 次尝试后仍无法自动找到可用端口,请手动提供一个。",
"placeholder": "例如 7777, 6666, 5555 ...",
"available": "✅ 当前端口可用,请按回车确认。",
"unavailable": "❌ 当前端口不可用,请更换。"
},
"failed": "无法启用彩虹屁,请重试。"
}
}
}
9 changes: 8 additions & 1 deletion src/page/src/components/player/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default {
data(){
return {
authorized: false,
failedTimes: 0
}
},
mounted(){
Expand All @@ -87,9 +88,15 @@ export default {
try {
response = await axios.get("/playsound");
}catch(e){
this.requestPlaySound();
if(this.failedTimes > 5){
setTimeout(this.requestPlaySound, 1000);
}else{
this.failedTimes++;
this.requestPlaySound();
}
return;
}
this.failedTime = 0;
let voice = response.data;
if(voice.lastIndexOf(".") < voice.length - 5){
return;
Expand Down
46 changes: 45 additions & 1 deletion src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const multer = require('multer')
const findAvailablePort = require("./findAvailablePort.js");
const open = require("open");
const _ = require("lodash");
const message = require("./message");

const assets = require("./assets.js");
const share = require("./share.js");
Expand All @@ -24,9 +25,52 @@ const settings = require("./settings.js");
// }
// };

function requireCustomPort() {
let checkTimeoutID, currentInput;

let inputbox = vscode.window.createInputBox();
inputbox.ignoreFocusOut = true;
inputbox.title = message("service.require-port.title");
inputbox.placeholder = message("service.require-port.placeholder");
inputbox.show()

inputbox.onDidChangeValue((value) => {
currentInput = value;
if (checkTimeoutID) {
clearTimeout(checkTimeoutID);
}
checkTimeoutID = setTimeout(async () => {
let isAvailable = await findAvailablePort(value, 1);
if (isAvailable !== undefined) {
inputbox.validationMessage = message("service.require-port.available");
} else {
inputbox.validationMessage = message("service.require-port.unavailable");
}
}, 500);
})

return new Promise((resolve, reject) => {
inputbox.onDidAccept(async (value) => {
resolve(currentInput);
inputbox.hide();
inputbox.dispose();
});
})

}

module.exports = async function () {

let port = await findAvailablePort(7777);
var port = await findAvailablePort(7777, 3)

if (!port) {
port = await requireCustomPort();
let isAvailable = await findAvailablePort(port, 1);
if (!isAvailable) {
vscode.window.showInformationMessage(message("service.failed"));
return;
}
}

const app = express();

Expand Down
3 changes: 2 additions & 1 deletion src/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ const os = require("os");

module.exports = {
play(name) {
if (!name) {
if (!name || !this.playVoiceRes) {
return;
}
console.log("Playing voice - " + name);
this.playVoiceRes && this.playVoiceRes.send(name);
this.playVoiceRes = null;
},
uri(thepath) {
if (os.type() == "Windows_NT") {
Expand Down

0 comments on commit 892ee52

Please sign in to comment.