()
| 857 | } |
| 858 | |
| 859 | func fetchLatestWindowFocusEntry() (*windowFocusEntry, error) { |
| 860 | dbPath, err := windowFocusDatabasePath() |
| 861 | if err != nil { |
| 862 | return nil, fmt.Errorf("determine window focus database path: %w", err) |
| 863 | } |
| 864 | if dbPath == "" { |
| 865 | return nil, fmt.Errorf("window focus database path is empty") |
| 866 | } |
| 867 | |
| 868 | if _, err := os.Stat(dbPath); err != nil { |
| 869 | return nil, fmt.Errorf("access %s: %w", dbPath, err) |
| 870 | } |
| 871 | |
| 872 | db, err := sql.Open("sqlite", dbPath) |
| 873 | if err != nil { |
| 874 | return nil, fmt.Errorf("open window focus database: %w", err) |
| 875 | } |
| 876 | defer db.Close() |
| 877 | db.SetMaxOpenConns(1) |
| 878 | db.SetMaxIdleConns(1) |
| 879 | |
| 880 | const query = ` |
| 881 | SELECT |
| 882 | id, |
| 883 | window_title, |
| 884 | workspace_name, |
| 885 | workspace_path, |
| 886 | active_file, |
| 887 | focused_at |
| 888 | FROM window_focus |
| 889 | WHERE |
| 890 | workspace_name IS NOT NULL |
| 891 | AND workspace_name = rtrim(workspace_name, '.') |
| 892 | ORDER BY focused_at DESC |
| 893 | LIMIT 1; |
| 894 | ` |
| 895 | |
| 896 | var ( |
| 897 | entry windowFocusEntry |
| 898 | windowTitle sql.NullString |
| 899 | workspaceName sql.NullString |
| 900 | workspacePath sql.NullString |
| 901 | activeFile sql.NullString |
| 902 | ) |
| 903 | |
| 904 | err = db.QueryRow(query).Scan( |
| 905 | &entry.ID, |
| 906 | &windowTitle, |
| 907 | &workspaceName, |
| 908 | &workspacePath, |
| 909 | &activeFile, |
| 910 | &entry.FocusedAt, |
| 911 | ) |
| 912 | if err != nil { |
| 913 | if errors.Is(err, sql.ErrNoRows) { |
| 914 | return nil, nil |
| 915 | } |
| 916 | return nil, fmt.Errorf("query window_focus: %w", err) |
no test coverage detected