Skip to content

Commit

Permalink
sync with go version
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnywong committed Oct 29, 2023
1 parent 6b2f301 commit db94360
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
14 changes: 8 additions & 6 deletions src/comm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ export const trzszVersion = "[VersionInject]{version}[/VersionInject]";

/* eslint-disable require-jsdoc */

export const isRunningInWindows = (function() {
export const isRunningInWindows = (function () {
try {
return process.platform === "win32";
} catch (err) {
return false;
}
})();

export const isRunningInBrowser = (function() {
export const isRunningInBrowser = (function () {
try {
if (require.resolve("fs") === "fs") {
require("fs");
return false;
}
} catch (err) { }
} catch (err) {}
return true;
})();

Expand Down Expand Up @@ -247,20 +247,22 @@ export async function checkTmux() {

const fs = require("fs");
const [tmuxTty, controlMode, paneWidth] = tokens;
const tmuxPaneWidth = parseInt(paneWidth, 10);

if (controlMode == "1" || !tmuxTty.startsWith("/") || !fs.existsSync(tmuxTty)) {
return [TmuxMode.TmuxControlMode, stdoutWriter, -1];
return [TmuxMode.TmuxControlMode, stdoutWriter, tmuxPaneWidth];
}

const fd = fs.openSync(tmuxTty, "w");
const tmuxRealWriter = (data: string | Uint8Array) => fs.writeSync(fd, data);

const statusInterval = await getTmuxStatusInterval();
await setTmuxStatusInterval("0");
process.on("exit", async function() {
process.on("exit", async function () {
await setTmuxStatusInterval(statusInterval);
});

return [TmuxMode.TmuxNormalMode, tmuxRealWriter, parseInt(paneWidth, 10)];
return [TmuxMode.TmuxNormalMode, tmuxRealWriter, tmuxPaneWidth];
}

async function getTmuxStatusInterval() {
Expand Down
14 changes: 8 additions & 6 deletions src/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class TrzszTransfer {
setTimeout(() => {
this.cleanTimeoutInMilliseconds = 3000;
reject(new TrzszError("Receive data timeout"));
}, timeoutInMilliseconds)
}, timeoutInMilliseconds),
),
(async () => {
if (!binary) {
Expand Down Expand Up @@ -238,7 +238,7 @@ export class TrzszTransfer {
}

public async recvAction() {
const buf = await this.recvString("ACT");
const buf = await this.recvString("ACT", true);
const action = JSON.parse(buf);
if (action.newline) {
this.protocolNewline = action.newline;
Expand Down Expand Up @@ -269,10 +269,12 @@ export class TrzszTransfer {
}
if (tmuxMode == TmuxMode.TmuxNormalMode) {
config.tmux_output_junk = true;
}
if (tmuxPaneWidth > 0) {
config.tmux_pane_width = tmuxPaneWidth;
}
let jsonStr = JSON.stringify(config);
jsonStr = jsonStr.replace(/[\u007F-\uFFFF]/g, function(chr) {
jsonStr = jsonStr.replace(/[\u007F-\uFFFF]/g, function (chr) {
return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).slice(-4);
});
this.transferConfig = config;
Expand Down Expand Up @@ -390,7 +392,7 @@ export class TrzszTransfer {
binary: boolean,
escapeCodes: Array<number[]>,
maxBufSize: number,
progressCallback: ProgressCallback
progressCallback: ProgressCallback,
) {
let step = 0;
if (progressCallback) {
Expand Down Expand Up @@ -480,7 +482,7 @@ export class TrzszTransfer {
openSaveFile: OpenSaveFile,
directory: boolean,
overwrite: boolean,
progressCallback: ProgressCallback
progressCallback: ProgressCallback,
) {
const fileName = await this.recvString("NAME");
const file = await openSaveFile(saveParam, fileName, directory, overwrite);
Expand All @@ -506,7 +508,7 @@ export class TrzszTransfer {
binary: boolean,
escapeCodes: Array<number[]>,
timeoutInMilliseconds: number,
progressCallback: ProgressCallback
progressCallback: ProgressCallback,
) {
let step = 0;
if (progressCallback) {
Expand Down

0 comments on commit db94360

Please sign in to comment.