|
1 | 1 | import { |
| 2 | + FileTextMode, |
2 | 3 | NotificationRequest, |
3 | 4 | nova, |
4 | 5 | Process, |
@@ -56,6 +57,69 @@ export function registerRunAll(testsDataProvider: TestsDataProvider) { |
56 | 57 | ); |
57 | 58 |
|
58 | 59 | async function runAll() { |
| 60 | + const hiddenWorkspaceDataPath = nova.path.join( |
| 61 | + nova.extension.workspaceStoragePath, |
| 62 | + "state.json", |
| 63 | + ); |
| 64 | + |
| 65 | + console.log(hiddenWorkspaceDataPath); |
| 66 | + |
| 67 | + function warningWasShown(path: string): boolean { |
| 68 | + try { |
| 69 | + const file = nova.fs.open(path) as FileTextMode; |
| 70 | + const data = JSON.parse(file.readlines().join("\n")); |
| 71 | + file.close(); |
| 72 | + return data.warningWasShown; |
| 73 | + } catch { |
| 74 | + // I hope it's OK to create so many `File` objects. |
| 75 | + try { |
| 76 | + nova.fs.mkdir(nova.extension.workspaceStoragePath); |
| 77 | + } catch (e) { |
| 78 | + throw new Error( |
| 79 | + "Could not access the extension's workspace storage path.", |
| 80 | + { cause: e }, |
| 81 | + ); |
| 82 | + } |
| 83 | + nova.fs.open(path, "x").close(); |
| 84 | + console.log("hi"); |
| 85 | + const file = nova.fs.open(path, "w"); |
| 86 | + console.log("hii"); |
| 87 | + file.write(JSON.stringify({ warningWasShown: false })); |
| 88 | + console.log("hiii"); |
| 89 | + file.close(); |
| 90 | + return warningWasShown(path); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + if (!warningWasShown(hiddenWorkspaceDataPath)) { |
| 95 | + const permissionsNotificationRequest = new NotificationRequest( |
| 96 | + "co.gwil.deno.notifications.findSymbolUnavailable", |
| 97 | + ); |
| 98 | + permissionsNotificationRequest.title = |
| 99 | + "Tests are awarded all permissions."; |
| 100 | + permissionsNotificationRequest.body = |
| 101 | + "Test files may access environment variables, load dynamic libraries, measure time in high resolution, utilize the network, read files and write files. This is not configurable at the moment."; |
| 102 | + permissionsNotificationRequest.actions = ["Cancel", "Allow"]; |
| 103 | + |
| 104 | + const response = await nova.notifications.add( |
| 105 | + permissionsNotificationRequest, |
| 106 | + ); |
| 107 | + if (response.actionIdx == 0) { |
| 108 | + return; |
| 109 | + } |
| 110 | + |
| 111 | + const oldFile = nova.fs.open(hiddenWorkspaceDataPath) as FileTextMode; |
| 112 | + const data = JSON.parse(oldFile.readlines().join("\n")); |
| 113 | + console.log(JSON.stringify(data)); |
| 114 | + oldFile.close(); |
| 115 | + nova.fs.remove(hiddenWorkspaceDataPath); |
| 116 | + nova.fs.open(hiddenWorkspaceDataPath, "x").close(); |
| 117 | + const file = nova.fs.open(hiddenWorkspaceDataPath, "w"); |
| 118 | + data.warningWasShown = true; |
| 119 | + file.write(JSON.stringify(data)); |
| 120 | + file.close(); |
| 121 | + } |
| 122 | + |
59 | 123 | try { |
60 | 124 | await testsDataProvider.runTests(); |
61 | 125 | testsDataProvider.treeView.reload(); |
|
0 commit comments