Эх сурвалжийг харах

fix(tauri.js) exit dev when running as admin, fixes #781 (#839)

Lucas Fernandes Nogueira 5 жил өмнө
parent
commit
17800571fe

+ 5 - 0
.changes/tauri-cli-admin.md

@@ -0,0 +1,5 @@
+---
+"tauri.js": patch
+---
+
+Prevent running the `dev` pipeline when running with administrator privileges.

+ 4 - 4
.github/workflows/core-lint-fmt.yml

@@ -3,10 +3,10 @@ name: clippy and fmt check
 on:
   pull_request:
     paths:
-      - .github/workflows/core-lint-fmt.yml
-      - ./tauri/**
-      - ./tauri-utils/**
-      - ./tauri-api/**
+      - '.github/workflows/core-lint-fmt.yml'
+      - './tauri/**'
+      - './tauri-utils/**'
+      - './tauri-api/**'
 
 jobs:
   workspace_clippy_fmt_check:

+ 2 - 2
.github/workflows/js-lint.yml

@@ -3,8 +3,8 @@ name: eslint check
 on:
   pull_request:
     paths:
-      - .github/workflows/js-lint.yml
-      - ./cli/tauri.js/**
+      - '.github/workflows/js-lint.yml'
+      - './cli/tauri.js/**'
 
 jobs:
   eslint-check:

+ 2 - 2
.github/workflows/test-bundler.yml

@@ -3,8 +3,8 @@ name: test bundler
 on:
   pull_request:
     paths:
-      - .github/workflows/test-bundler.yml
-      - ./cli/tauri-bundler/**
+      - '.github/workflows/test-bundler.yml'
+      - './cli/tauri-bundler/**'
 env:
   RUST_BACKTRACE: 1
 

+ 5 - 5
.github/workflows/test-core.yml

@@ -3,11 +3,11 @@ name: test core
 on:
   pull_request:
     paths:
-      - .github/workflows/test-core.yml
-      - ./cli/**
-      - ./tauri/**
-      - ./tauri-api/**
-      - ./tauri-utils/**
+      - '.github/workflows/test-core.yml'
+      - './cli/**'
+      - './tauri/**'
+      - './tauri-api/**'
+      - './tauri-utils/**'
 
 env:
   RUST_BACKTRACE: 1

+ 3 - 11
cli/tauri.js/.gitignore

@@ -1,5 +1,7 @@
-# Webpack output
+# Build output
 /dist
+/api
+
 
 # Logs
 logs
@@ -62,13 +64,3 @@ typings/
 debug.log
 package-lock.json
 .vscode/settings.json
-
-#api
-api/*
-
-# Tauri output
-bundle.json
-config.json
-
-# rust compiled folders
-target

+ 1 - 0
cli/tauri.js/scripts/is-admin.ps1

@@ -0,0 +1 @@
+[bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544");

+ 16 - 0
cli/tauri.js/src/api/dev.ts

@@ -2,6 +2,13 @@ import { TauriConfig } from 'types'
 import { merge } from 'webpack-merge'
 import Runner from '../runner'
 import getTauriConfig from '../helpers/tauri-config'
+import logger from '../helpers/logger'
+import chalk from 'chalk'
+import { platform } from 'os'
+import { resolve } from 'path'
+import { sync as spawnSync } from 'cross-spawn'
+
+const error = logger('tauri:dev', chalk.red)
 
 interface DevResult {
   promise: Promise<void>
@@ -9,6 +16,15 @@ interface DevResult {
 }
 
 module.exports = (config: TauriConfig): DevResult => {
+  if (platform() === 'win32') {
+    const child = spawnSync('powershell', [resolve(__dirname, '../../scripts/is-admin.ps1')])
+    const response = String(child.output[1]).replace('\n', '').trim()
+    if (response === 'True') {
+      error('Administrator privileges detected. Tauri doesn\'t work when running as admin, see https://github.com/Boscop/web-view/issues/96')
+      process.exit(1)
+    }
+  }
+
   const tauri = new Runner()
   const tauriConfig = getTauriConfig(
     merge(