Skip to content

Commit

Permalink
Refactor file opening for Windows compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
OreQr committed Jul 9, 2024
1 parent e751d55 commit 891de79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "email-viewer",
"version": "1.0.1",
"version": "1.1.0",
"license": "MIT",
"author": "OreQr",
"description": "📧Opens browser with email preview",
Expand Down
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { randomUUID } from "crypto"
import ejs from "ejs"
import template from "templates/template.ejs"
import os from "os"
import openFile from "open"
import path from "path"
import fs from "fs"
import openFile from "open"
import { openExplorer } from "./open"

export interface ViewEmailOptions {
id?: string
Expand All @@ -28,7 +29,13 @@ export const viewEmail = (options: ViewEmailOptions): ViewEmailResult => {
if (open) {
const filePath = path.join(dir, `${id}.html`)
fs.writeFileSync(filePath, html)
openFile(`file://${filePath}`)

const target = `file://${filePath}`
if (process.platform === "win32") {
openExplorer(target)
} else {
openFile(target)
}
}

return { id, html }
Expand Down
5 changes: 5 additions & 0 deletions src/open.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { exec } from "child_process"

export const openExplorer = (target: string) => {
exec("explorer " + target)
}

0 comments on commit 891de79

Please sign in to comment.