#!/usr/bin/env python3
"""
PDF转SVG脚本 - 使用inkscape转换，通过系统通知提示结果。
用法: pdf2svg.sh <PDF文件路径>
"""

import sys
import os
import subprocess


def notify(title, message, icon="emblem-checked"):
    subprocess.run([
        "notify-send",
        "--app-name=PDF转SVG",
        title,
        message,
        f"--icon={icon}"
    ])


def main():
    try:
        if len(sys.argv) != 2:
            notify("", "失败", "dialog-error")
            sys.exit(1)

        input_pdf = sys.argv[1].strip("'")

        if not os.path.isfile(input_pdf):
            notify("", "失败", "dialog-error")
            sys.exit(1)

        output_svg = os.path.splitext(input_pdf)[0] + ".svg"

        subprocess.run([
            "inkscape", input_pdf,
            "--export-type=svg",
            f"--export-filename={output_svg}",
            "--export-ps-level=1",
            "--export-area-drawing"
        ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)

        notify("", "成功", "emblem-checked")

    except Exception:
        notify("", "失败", "dialog-error")
        sys.exit(1)


if __name__ == "__main__":
    main()
