Skip to content

Commit 891de79

Browse files
committed
Refactor file opening for Windows compatibility
1 parent e751d55 commit 891de79

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "email-viewer",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"license": "MIT",
55
"author": "OreQr",
66
"description": "📧Opens browser with email preview",

src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { randomUUID } from "crypto"
22
import ejs from "ejs"
33
import template from "templates/template.ejs"
44
import os from "os"
5-
import openFile from "open"
65
import path from "path"
76
import fs from "fs"
7+
import openFile from "open"
8+
import { openExplorer } from "./open"
89

910
export interface ViewEmailOptions {
1011
id?: string
@@ -28,7 +29,13 @@ export const viewEmail = (options: ViewEmailOptions): ViewEmailResult => {
2829
if (open) {
2930
const filePath = path.join(dir, `${id}.html`)
3031
fs.writeFileSync(filePath, html)
31-
openFile(`file://${filePath}`)
32+
33+
const target = `file://${filePath}`
34+
if (process.platform === "win32") {
35+
openExplorer(target)
36+
} else {
37+
openFile(target)
38+
}
3239
}
3340

3441
return { id, html }

src/open.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { exec } from "child_process"
2+
3+
export const openExplorer = (target: string) => {
4+
exec("explorer " + target)
5+
}

0 commit comments

Comments
 (0)