diff --git a/package.json b/package.json index 03170f7..241dd6c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.ts b/src/index.ts index 507603e..3fc6876 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 @@ -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 } diff --git a/src/open.ts b/src/open.ts new file mode 100644 index 0000000..57fc825 --- /dev/null +++ b/src/open.ts @@ -0,0 +1,5 @@ +import { exec } from "child_process" + +export const openExplorer = (target: string) => { + exec("explorer " + target) +}