Skip to content

Commit cf2d9e6

Browse files
committed
Update packaging and building scripts; Some detail improvements.
1 parent 9b6cd6f commit cf2d9e6

File tree

11 files changed

+459
-415
lines changed

11 files changed

+459
-415
lines changed

app/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "switchhosts",
33
"productName": "SwitchHosts",
4-
"version": "4.2.0.6105",
4+
"version": "4.2.0.6119",
55
"description": "Switch hosts quickly!",
66
"main": "./main.js",
77
"author": {

package-lock.json

+368-346
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"dev:renderer": "vite --config ./vite.render.config.mts",
1111
"version:up": "node ./scripts/version_up.js",
1212
"_build": "npm run clean:build && npm run version:up && concurrently \"npm run build:main\" \"npm run build:renderer\"",
13-
"build:main": "cross-env NODE_ENV=production vite build --config ./vite.main.config.ts",
14-
"build:renderer": "cross-env NODE_ENV=production vite build --config ./vite.render.config.ts",
13+
"build:main": "cross-env NODE_ENV=production vite build --config ./vite.main.config.mts",
14+
"build:renderer": "cross-env NODE_ENV=production vite build --config ./vite.render.config.mts",
1515
"build": "npm run _build",
1616
"make": "node scripts/make.js",
1717
"make:dev": "cross-env SKIP_NOTARIZATION=1 cross-env MAKE_FOR=dev npm run make",
@@ -36,6 +36,7 @@
3636
},
3737
"devDependencies": {
3838
"@chakra-ui/react": "2.8.2",
39+
"@electron/notarize": "^2.3.2",
3940
"@emotion/react": "11.13.0",
4041
"@emotion/styled": "11.13.0",
4142
"@tabler/icons-react": "3.11.0",
@@ -60,7 +61,6 @@
6061
"dotenv": "16.4.5",
6162
"electron": "30.1.2",
6263
"electron-builder": "24.13.3",
63-
"electron-notarize": "1.2.1",
6464
"espower-typescript": "10.0.1",
6565
"execa": "9.3.0",
6666
"fs-extra": "11.2.0",
@@ -79,7 +79,7 @@
7979
"smooth-scroll-into-view-if-needed": "2.0.2",
8080
"ts-node": "10.9.2",
8181
"typescript": "5.5.4",
82-
"vite": "5.3.5",
82+
"vite": "4.5.3",
8383
"vite-plugin-static-copy": "1.0.6",
8484
"vite-plugin-svgr": "4.2.0",
8585
"vite-tsconfig-paths": "4.3.2"

scripts/make.js

+23-40
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,36 @@
11
/**
2-
* make
2+
* make.js
33
* @author: oldj
44
* @homepage: https://oldj.net
55
*/
66

77
require('dotenv').config()
8+
const path = require('path')
9+
const fse = require('fs-extra')
810
const version = require('../src/version.json')
911
const builder = require('electron-builder')
10-
const fse = require('fs-extra')
1112
const homedir = require('os').homedir()
12-
const path = require('path')
13-
14-
const root_dir = path.normalize(path.join(__dirname, '..'))
15-
const dist_dir = path.normalize(path.join(__dirname, '..', 'dist'))
16-
17-
const electronLanguages = ['en', 'fr', 'zh_CN', 'de', 'ja', 'tr', 'ko']
13+
const { APP_NAME, root_dir, dist_dir, electronLanguages } = require('./vars')
1814

1915
const TARGET_PLATFORMS_configs = {
2016
mac: {
21-
mac: ['default'],
22-
},
23-
macs: {
2417
mac: ['dmg:x64', 'dmg:arm64'],
2518
},
26-
linux: {
27-
linux: [
28-
'AppImage:x64',
29-
'deb:x64',
30-
'AppImage:arm64',
31-
'deb:arm64',
32-
'AppImage:armv7l',
33-
'deb:armv7l',
34-
],
35-
},
3619
win: {
37-
win: ['nsis:ia32', 'nsis:x64', 'portable:ia32'],
20+
win: ['nsis:ia32', 'nsis:x64', 'nsis:arm64', 'portable:x64'],
21+
},
22+
linux: {
23+
linux: ['AppImage:x64', 'AppImage:arm64', 'deb:x64', 'deb:arm64'],
3824
},
3925
all: {
40-
mac: ['dmg:x64', 'dmg:arm64'],
41-
linux: [
42-
'AppImage:x64',
43-
'deb:x64',
44-
'AppImage:arm64',
45-
'deb:arm64',
46-
'AppImage:armv7l',
47-
'deb:armv7l',
48-
],
49-
win: ['nsis:ia32', 'nsis:x64', 'portable:ia32'],
26+
mac: ['dmg:x64', 'dmg:arm64', 'zip:universal'],
27+
win: ['nsis:ia32', 'nsis:x64', 'nsis:arm64', 'portable:x64', 'zip:x64' /* , 'appx:x64'*/],
28+
linux: ['AppImage:x64', 'AppImage:arm64', 'deb:x64', 'deb:arm64'],
5029
},
5130
}
5231

53-
const APP_NAME = 'SwitchHosts'
54-
const { IDENTITY } = process.env
32+
const { APP_BUNDLE_ID, IDENTITY } = process.env
33+
console.log(`APP_BUNDLE_ID: ${APP_BUNDLE_ID}`)
5534

5635
const cfg_common = {
5736
copyright: `Copyright © ${new Date().getFullYear()}`,
@@ -62,8 +41,9 @@ const cfg_common = {
6241
},
6342
electronDownload: {
6443
cache: path.join(homedir, '.electron'),
65-
mirror: 'https://npm.taobao.org/mirrors/electron/',
44+
mirror: 'https://registry.npmmirror.com/-/binary/electron/',
6645
},
46+
asar: true,
6747
}
6848

6949
const beforeMake = async () => {
@@ -104,14 +84,12 @@ const doMake = async () => {
10484
let targets = TARGET_PLATFORMS_configs.all
10585

10686
cfg_common.compression = 'maximum'
107-
if (MAKE_FOR && MAKE_FOR !== 'all') {
108-
cfg_common.compression = 'store'
109-
}
11087

11188
if (MAKE_FOR === 'dev') {
11289
targets = TARGET_PLATFORMS_configs.mac
90+
cfg_common.compression = 'store'
11391
} else if (MAKE_FOR === 'mac') {
114-
targets = TARGET_PLATFORMS_configs.macs
92+
targets = TARGET_PLATFORMS_configs.mac
11593
} else if (MAKE_FOR === 'win') {
11694
targets = TARGET_PLATFORMS_configs.win
11795
} else if (MAKE_FOR === 'linux') {
@@ -140,6 +118,7 @@ const doMake = async () => {
140118
CFBundleLocalizations: electronLanguages,
141119
CFBundleDevelopmentRegion: 'en',
142120
},
121+
notarize: false,
143122
},
144123
dmg: {
145124
//backgroundColor: '#f1f1f6',
@@ -173,6 +152,8 @@ const doMake = async () => {
173152
installerIcon: 'assets/installer-icon.ico',
174153
oneClick: false,
175154
allowToChangeInstallationDirectory: true,
155+
deleteAppDataOnUninstall: false,
156+
shortcutName: 'SwitchHosts',
176157
artifactName: '${productName}_windows_installer_${arch}_${version}(${buildVersion}).${ext}',
177158
},
178159
portable: {
@@ -205,8 +186,10 @@ const doMake = async () => {
205186
await beforeMake()
206187
await doMake()
207188
await afterMake()
189+
//await macSign()
190+
208191
console.log('-> make Done!')
209192
} catch (e) {
210-
console.error(e)
193+
console.log(e)
211194
}
212195
})()

scripts/notarize.js

+29-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@
55
*/
66

77
require('dotenv').config()
8-
const { notarize } = require('electron-notarize')
8+
const { notarize } = require('@electron/notarize')
9+
const { exec } = require('child_process')
10+
11+
function getPasswordFromKeychain(account, service) {
12+
return new Promise((resolve, reject) => {
13+
const command = `security find-generic-password -a '${account}' -s '${service}' -w`
14+
exec(command, (error, stdout, stderr) => {
15+
if (error) {
16+
reject(new Error(`Error fetching password: ${stderr}`))
17+
} else {
18+
resolve(stdout.trim())
19+
}
20+
})
21+
})
22+
}
923

1024
exports.default = async function notarizing(context) {
1125
const appName = context.packager.appInfo.productFilename
@@ -21,23 +35,32 @@ exports.default = async function notarizing(context) {
2135
}
2236

2337
let appPath = `${appOutDir}/${appName}.app`
24-
let { appleId, appBundleId, ascProvider, appleIdPassword } = process.env
38+
let {
39+
APP_BUNDLE_ID: appBundleId,
40+
TEAM_ID: teamId,
41+
APPLE_ID: appleId,
42+
APPLE_APP_SPECIFIC_PASSWORD: appleIdPassword,
43+
} = process.env
2544
if (!appleIdPassword) {
26-
appleIdPassword = `@keychain:Apple Notarize: ${appleId}`
45+
//appleIdPassword = `@keychain:"Apple Notarize: ${appleId}"`
46+
appleIdPassword = await getPasswordFromKeychain(appleId, `Apple Notarize: ${appleId}`)
47+
process.env.APPLE_APP_SPECIFIC_PASSWORD = appleIdPassword
2748
}
2849

29-
if (!appleId || !appBundleId || !ascProvider || !appleIdPassword) {
50+
if (!appleId || !appBundleId || !teamId || !appleIdPassword) {
3051
console.log('Not notarized.')
3152
return
3253
}
3354

3455
console.log('Start notarizing...')
3556
await notarize({
36-
appBundleId,
3757
appPath,
38-
ascProvider,
58+
tool: 'notarytool',
59+
//appBundleId,
60+
//ascProvider,
3961
appleId,
4062
appleIdPassword,
63+
teamId,
4164
})
4265
console.log('Notarize done.')
4366
}

scripts/vars.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const path = require('path')
2+
3+
const root_dir = path.normalize(path.join(__dirname, '..'))
4+
const dist_dir = path.normalize(path.join(__dirname, '..', 'dist'))
5+
6+
const APP_NAME = 'SwitchHosts'
7+
8+
const electronLanguages = ['en', 'fr', 'zh_CN', 'de', 'ja', 'tr', 'ko']
9+
10+
module.exports = {
11+
APP_NAME,
12+
root_dir,
13+
dist_dir,
14+
electronLanguages,
15+
}

src/renderer/components/List/ListItem.module.scss

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
flex: 0 0 auto;
7878
display: flex;
7979
align-items: center;
80+
gap: 5px;
8081
margin: auto 6px auto auto;
8182
}
8283

src/renderer/index.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import React from 'react'
1111
import { createRoot } from 'react-dom/client'
1212
import { createHashRouter, RouterProvider } from 'react-router-dom'
1313
import { ChakraProvider, ColorModeScript } from '@chakra-ui/react'
14+
import './styles/common.scss'
1415
import theme from './theme'
1516

1617
const router = createHashRouter([

src/renderer/styles/common.scss

-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,2 @@
11
@import "fn";
22

3-
html, body {
4-
margin: 0;
5-
padding: 0;
6-
font-size: 14px;
7-
line-height: 1.5em;
8-
box-sizing: border-box;
9-
color: var(--swh-font-color);
10-
color-scheme: var(--swh-color-scheme);
11-
}
12-
13-
button, a, input {
14-
&:focus:not(:focus-visible) {
15-
outline: 0;
16-
box-shadow: none;
17-
}
18-
}
19-

src/renderer/styles/global.scss

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
html, body {
2+
margin: 0;
3+
padding: 0;
4+
font-size: 14px;
5+
line-height: 1.5em;
6+
box-sizing: border-box;
7+
color: var(--swh-font-color);
8+
color-scheme: var(--swh-color-scheme);
9+
}
10+
11+
button, a, input {
12+
&:focus:not(:focus-visible) {
13+
outline: 0;
14+
box-shadow: none;
15+
}
16+
}

src/version.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[4, 2, 0, 6105]
1+
[4, 2, 0, 6119]

0 commit comments

Comments
 (0)