Quellcode durchsuchen

improve the launch performance of portable

Cyril Taylor vor 5 Jahren
Ursprung
Commit
9b7c446fd7
4 geänderte Dateien mit 28 neuen und 13 gelöschten Zeilen
  1. 4 0
      README.md
  2. 18 9
      app/lib/portable.ts
  3. 5 3
      electron-builder.yml
  4. 1 1
      scripts/build-windows.js

+ 4 - 0
README.md

@@ -35,6 +35,10 @@
 
 ---
 
+# Portable
+
+For portable in windows, user can create folder `data` at the same directory as `Terminal.exe` to save the settings.
+
 # Plugins
 
 Plugins and themes can be installed directly from the Settings view inside Terminus.

+ 18 - 9
app/lib/portable.ts

@@ -1,15 +1,24 @@
 import * as path from 'path'
 import * as fs from 'fs'
 
-if (process.env.PORTABLE_EXECUTABLE_DIR) {
-    const portableData = path.join(process.env.PORTABLE_EXECUTABLE_DIR, 'terminus-data')
-    if (!fs.existsSync(portableData)) {
-        fs.mkdirSync(portableData)
-    }
+let appPath: string | null = null
+try {
+    appPath = path.dirname(require('electron').app.getPath('exe'))
+} catch {
+    appPath = path.dirname(require('electron').remote.app.getPath('exe'))
+}
 
-    try {
-        require('electron').app.setPath('userData', portableData)
-    } catch {
-        require('electron').remote.app.setPath('userData', portableData)
+if (null != appPath) {
+    if(fs.existsSync(path.join(appPath, 'terminus-data'))) {
+        fs.renameSync(path.join(appPath, 'terminus-data'), path.join(appPath, 'data'))
+    }
+    const portableData = path.join(appPath, 'data')
+    if (fs.existsSync(portableData)) {
+        console.log('reset user data to ' + portableData)
+        try {
+            require('electron').app.setPath('userData', portableData)
+        } catch {
+            require('electron').remote.app.setPath('userData', portableData)
+        }
     }
 }

+ 5 - 3
electron-builder.yml

@@ -14,14 +14,16 @@ publish:
 
 win:
   icon: "./build/windows/icon.ico"
-  artifactName: terminus-${version}-setup.exe
+  target: [
+    'nsis',
+    'zip'
+  ]
+  artifactName: terminus-${version}.${ext}
   rfc3161TimeStampServer: http://sha256timestamp.ws.symantec.com/sha256/timestamp
 nsis:
   oneClick: false
   artifactName: terminus-${version}-setup.${ext}
   installerIcon: "./build/windows/icon.ico"
-portable:
-  artifactName: terminus-${version}-portable.exe
 
 mac:
   category: public.app-category.video

+ 1 - 1
scripts/build-windows.js

@@ -7,7 +7,7 @@ const isCI = !!process.env.GITHUB_REF
 
 builder({
     dir: true,
-    win: ['nsis', 'portable'],
+    win: ['nsis', 'zip'],
     config: {
         extraMetadata: {
             version: vars.version,