mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 03:08:09 +08:00 
			
		
		
		
	feat(cpu_dialog): add actual Windows CPU detection
This commit is contained in:
		
							parent
							
								
									0a81e26e7e
								
							
						
					
					
						commit
						c6c59c63bb
					
				
					 2 changed files with 29 additions and 5 deletions
				
			
		|  | @ -4,7 +4,7 @@ import utils from "../../services/utils.js"; | |||
| import { t } from "../../services/i18n.js"; | ||||
| 
 | ||||
| const TPL = /*html*/` | ||||
| <div class="rosetta-warning-dialog modal mx-auto" tabindex="-1" role="dialog" style="z-index: 2000;"> | ||||
| <div class="cpu-arch-dialog modal mx-auto" tabindex="-1" role="dialog" style="z-index: 2000;"> | ||||
|     <div class="modal-dialog modal-lg" role="document"> | ||||
|         <div class="modal-content"> | ||||
|             <div class="modal-header"> | ||||
|  |  | |||
|  | @ -1,9 +1,10 @@ | |||
| import { execSync } from "child_process"; | ||||
| import { isMac } from "../../services/utils"; | ||||
| import { isMac, isWindows } from "../../services/utils"; | ||||
| import { arch, cpus } from "os"; | ||||
| 
 | ||||
| function systemChecks() { | ||||
|     return { | ||||
|         isCpuArchMismatch: isRunningUnderRosetta2() | ||||
|         isCpuArchMismatch: isCpuArchMismatch() | ||||
|     } | ||||
| } | ||||
| 
 | ||||
|  | @ -13,8 +14,31 @@ function systemChecks() { | |||
|  * Uses the macOS sysctl.proc_translated to properly detect translation. | ||||
|  * @returns true if running under Rosetta 2, false otherwise | ||||
|  */ | ||||
| export const isRunningUnderRosetta2 = () => { | ||||
|     return true; | ||||
| export const isCpuArchMismatch = () => { | ||||
|     if (isMac) { | ||||
|         try { | ||||
|             // Use child_process to check sysctl.proc_translated
 | ||||
|             // This is the proper way to detect Rosetta 2 translation
 | ||||
|             const result = execSync("sysctl -n sysctl.proc_translated 2>/dev/null", { | ||||
|                 encoding: "utf8", | ||||
|                 timeout: 1000 | ||||
|             }).trim(); | ||||
| 
 | ||||
|             // 1 means the process is being translated by Rosetta 2
 | ||||
|             // 0 means native execution
 | ||||
|             // If the sysctl doesn't exist (on Intel Macs), this will return empty/error
 | ||||
|             return result === "1"; | ||||
|         } catch (error) { | ||||
|             // If sysctl fails or doesn't exist (Intel Macs), not running under Rosetta 2
 | ||||
|             return false; | ||||
|         } | ||||
|     } else if (isWindows && arch() === "x64") { | ||||
|         return cpus().some(cpu => | ||||
|             cpu.model.includes('Microsoft SQ') || | ||||
|             cpu.model.includes('Snapdragon')); | ||||
|     } else { | ||||
|         return false; | ||||
|     } | ||||
| }; | ||||
| 
 | ||||
| export default { | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue