Skip to content

Commit

Permalink
Add cross-platform support for opening files
Browse files Browse the repository at this point in the history
- Added platform checks for Windows, Linux, and Mac
- Implemented open_path function to handle platform-specific file opening
  • Loading branch information
Lenochxd committed Dec 16, 2024
1 parent 980bf2b commit fb01876
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/buttons/system/openfile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
from app.utils.platform import is_windows, is_linux, is_mac
import os


def openfile(path):
def open_path(path):
if is_windows:
os.startfile(path)
elif is_linux:
os.system(f'xdg-open "{path}"')
elif is_mac:
os.system(f'open "{path}"')

if "://" not in path and ":" in path:
initial_path = os.getcwd()
file_directory = os.path.dirname(path)
try:
file_directory = os.path.dirname(path)
os.chdir(file_directory)
os.startfile(path)
open_path(path)
finally:
os.chdir(initial_path)
else:
os.startfile(path)
open_path(path)

0 comments on commit fb01876

Please sign in to comment.