Skip to content

Commit

Permalink
Add profile disable, allow copy euiccinfo2
Browse files Browse the repository at this point in the history
  • Loading branch information
creamlike1024 committed Jan 18, 2024
1 parent 00cc77a commit e5b4c8b
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 26 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Build for Windows
if: runner.os == 'Linux'
run: |
fyne-cross windows -icon asset/icon2.png
fyne-cross windows -icon assets/icon2.png
cd fyne-cross/bin/windows-amd64
mkdir lpac
wget https://github.com/creamlike1024/lpac/releases/download/v2024.1.3/lpac-windows-x86_64-cygwin.zip -O lpac.zip
Expand All @@ -58,22 +58,22 @@ jobs:
if: runner.os == 'macOS'
run: |
go install fyne.io/fyne/v2/cmd/fyne@latest
fyne package -icon asset/icon.png
fyne package -icon assets/icon.png
cd EasyLPAC.app/Contents/MacOS
mkdir lpac
wget https://github.com/creamlike1024/lpac/releases/download/v2024.1.3/lpac-macos-universal.zip -O lpac.zip
unzip lpac.zip -d lpac && rm lpac.zip
chmod +x lpac/*
cd $GITHUB_WORKSPACE
zip -r EasyLPAC-macOS-x86_64-with-lpac.zip EasyLPAC.app
zip -r EasyLPAC-macOS-universal-with-lpac.zip EasyLPAC.app
mkdir dmg && cp -r EasyLPAC.app dmg
hdiutil create -volname "EasyLPAC" -srcfolder dmg -ov -format UDRW EasyLPAC.dmg
hdiutil attach EasyLPAC.dmg
cp asset/icon.icns /Volumes/EasyLPAC/.VolumeIcon.icns
cp assets/icon.icns /Volumes/EasyLPAC/.VolumeIcon.icns
SetFile -c icnC /Volumes/EasyLPAC/.VolumeIcon.icns
SetFile -a C /Volumes/EasyLPAC
hdiutil detach /Volumes/EasyLPAC
hdiutil convert EasyLPAC.dmg -format UDZO -o EasyLPAC-macOS-x86_64-with-lpac.dmg
hdiutil convert EasyLPAC.dmg -format UDZO -o EasyLPAC-macOS-universal-with-lpac.dmg
- name: Upload Artifact
uses: actions/upload-artifact@v3
Expand All @@ -82,8 +82,8 @@ jobs:
path: |
EasyLPAC-windows-x86_64-with-lpac.zip
EasyLPAC-linux-x86_64.tar.gz
EasyLPAC-macOS-x86_64-with-lpac.zip
EasyLPAC-macOS-x86_64-with-lpac.dmg
EasyLPAC-macOS-universal-with-lpac.zip
EasyLPAC-macOS-universal-with-lpac.dmg
- name: Release
uses: softprops/action-gh-release@v1
Expand All @@ -92,5 +92,5 @@ jobs:
files: |
EasyLPAC-windows-x86_64-with-lpac.zip
EasyLPAC-linux-x86_64.tar.gz
EasyLPAC-macOS-x86_64-with-lpac.zip
EasyLPAC-macOS-x86_64-with-lpac.dmg
EasyLPAC-macOS-universal-with-lpac.zip
EasyLPAC-macOS-universal-with-lpac.dmg
2 changes: 1 addition & 1 deletion FyneApp.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ Website = "https://github.com/creamlike1024/EasyLPAC"
Icon = "Icon.png"
Name = "EasyLPAC"
ID = "github.creamlike1024.EasyLPAC"
Version = "0.5.1"
Version = "0.5.2"
Build = 0
Binary file added assets/DejaVuSansMono.ttf
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
9 changes: 9 additions & 0 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ func LpacProfileEnable(iccid string) error {
return nil
}

func LpacProfileDisable(iccid string) error {
args := []string{"profile", "disable", iccid}
_, err := runLpac(args)
if err != nil {
return err
}
return nil
}

func LpacProfileDelete(iccid string) error {
args := []string{"profile", "delete", iccid}
_, err := runLpac(args)
Expand Down
12 changes: 8 additions & 4 deletions control.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var RefreshNotificationNeeded bool
var RefreshChipInfoNeeded bool
var ProfileMaskNeeded bool
var NotificationMaskNeeded bool
var ProfileStateAllowDisable bool

var StatusChan chan int
var LockButtonChan chan bool
Expand Down Expand Up @@ -72,9 +73,10 @@ func RefreshChipInfo() {
}
CopyEidButton.Show()
SetDefaultSmdpButton.Show()
EuiccInfo2Entry.Show()

EuiccInfo2TextGrid.SetText(string(bytes))

// EuiccInfo2TextGrid.SetText(string(bytes))
EuiccInfo2Entry.SetText(string(bytes))
// 计算剩余空间
freeSpace := float32(ChipInfo.EUICCInfo2.ExtCardResource.FreeNonVolatileMemory) / 1024
FreeSpaceLabel.SetText(fmt.Sprintf("Free space: %.2f KB", freeSpace))
Expand All @@ -91,6 +93,8 @@ func RefreshApduDriver() {
options = append(options, d.Name)
}
ApduDriverSelect.SetOptions(options)
ApduDriverSelect.ClearSelected()
ConfigInstance.DriverIFID = ""
ApduDriverSelect.Refresh()
}

Expand Down Expand Up @@ -170,7 +174,7 @@ func LockButton() {
DiscoveryButton.Disable()
SetNicknameButton.Disable()
RefreshButton.Disable()
EnableButton.Disable()
SwitchStateButton.Disable()
DeleteButton.Disable()
ProcessNotificationButton.Disable()
RemoveNotificationButton.Disable()
Expand All @@ -184,7 +188,7 @@ func LockButton() {
DiscoveryButton.Enable()
SetNicknameButton.Enable()
RefreshButton.Enable()
EnableButton.Enable()
SwitchStateButton.Enable()
DeleteButton.Enable()
ProcessNotificationButton.Enable()
RemoveNotificationButton.Enable()
Expand Down
10 changes: 9 additions & 1 deletion font.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ import (
"fyne.io/fyne/v2"
)

//go:embed NotoSansMonoCJKsc-Regular.otf
//go:embed assets/NotoSansMonoCJKsc-Regular.otf
var monoFontRegular []byte

//go:embed assets/DejaVuSansMono.ttf
var dejaVuMonoFontRegular []byte

var resourceNotoSansMonoCJKscRegular = &fyne.StaticResource{
StaticName: "NotoSansMonoCJKsc-Regular.otf",
StaticContent: monoFontRegular,
}

var resourceDejaVuSansMonoRegular = &fyne.StaticResource{
StaticName: "DejaVuSansMono.ttf",
StaticContent: dejaVuMonoFontRegular,
}
3 changes: 3 additions & 0 deletions theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func (myTheme) Font(s fyne.TextStyle) fyne.Resource {
if s.Monospace {
return resourceNotoSansMonoCJKscRegular
}
if s.Italic {
return resourceDejaVuSansMonoRegular
}
return theme.DefaultTheme().Font(s)
}

Expand Down
64 changes: 56 additions & 8 deletions widgets.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var SetNicknameButton *widget.Button
var DownloadButton *widget.Button
var DiscoveryButton *widget.Button
var DeleteButton *widget.Button
var EnableButton *widget.Button
var SwitchStateButton *widget.Button
var ProcessNotificationButton *widget.Button
var RemoveNotificationButton *widget.Button

Expand All @@ -42,7 +42,7 @@ var NotificationMaskCheck *widget.Check
var EidLabel *widget.Label
var DefaultDpAddressLabel *widget.Label
var RootDsAddressLabel *widget.Label
var EuiccInfo2TextGrid *widget.TextGrid
var EuiccInfo2Entry *ReadOnlyEntry
var CopyEidButton *widget.Button
var SetDefaultSmdpButton *widget.Button

Expand All @@ -55,6 +55,35 @@ var NotificationTab *container.TabItem
var ChipInfoTab *container.TabItem
var AboutTab *container.TabItem

type ReadOnlyEntry struct{ widget.Entry }

func (entry *ReadOnlyEntry) TypedRune(r rune) {}
func (entry *ReadOnlyEntry) TypedKey(key *fyne.KeyEvent) {}
func (entry *ReadOnlyEntry) TypedShortcut(shortcut fyne.Shortcut) {
switch shortcut := shortcut.(type) {
case *fyne.ShortcutCopy:
entry.Entry.TypedShortcut(shortcut)
}
}

func (entry *ReadOnlyEntry) TappedSecondary(ev *fyne.PointEvent) {
c := fyne.CurrentApp().Driver().AllWindows()[0].Clipboard()
copyItem := fyne.NewMenuItem("Copy", func() {
c.SetContent(entry.SelectedText())
})
menu := fyne.NewMenu("", copyItem)
widget.ShowPopUpMenuAtPosition(menu, fyne.CurrentApp().Driver().AllWindows()[0].Canvas(), ev.AbsolutePosition)
}

func NewReadOnlyEntry() *ReadOnlyEntry {
entry := &ReadOnlyEntry{}
entry.ExtendBaseWidget(entry) // 确保自定义的 widget 被正确地初始化
entry.MultiLine = true // 支持多行文本
entry.TextStyle = fyne.TextStyle{Italic: true}
entry.Wrapping = fyne.TextWrapOff
return entry
}

func InitWidgets() {
StatusProcessBar = widget.NewProgressBarInfinite()
StatusProcessBar.Stop()
Expand All @@ -70,7 +99,7 @@ func InitWidgets() {

DeleteButton = &widget.Button{Text: "Delete", OnTapped: deleteButtonFunc, Icon: theme.DeleteIcon()}

EnableButton = &widget.Button{Text: "Enable", OnTapped: enableButtonFunc, Icon: theme.ConfirmIcon()}
SwitchStateButton = &widget.Button{Text: "Enable", OnTapped: switchStateButtonFunc, Icon: theme.ConfirmIcon()}

ProfileList = initProfileList()

Expand Down Expand Up @@ -118,7 +147,8 @@ func InitWidgets() {
EidLabel = widget.NewLabel("")
DefaultDpAddressLabel = widget.NewLabel("")
RootDsAddressLabel = widget.NewLabel("")
EuiccInfo2TextGrid = widget.NewTextGrid()
EuiccInfo2Entry = NewReadOnlyEntry()
EuiccInfo2Entry.Hide()
CopyEidButton = &widget.Button{Text: "Copy", OnTapped: copyEidButtonFunc, Icon: theme.ContentCopyIcon()}
CopyEidButton.Hide()
SetDefaultSmdpButton = &widget.Button{OnTapped: setDefaultSmdpButtonFunc, Icon: theme.DocumentCreateIcon()}
Expand Down Expand Up @@ -279,7 +309,7 @@ func deleteButtonFunc() {
d.Show()
}

func enableButtonFunc() {
func switchStateButtonFunc() {
if ConfigInstance.DriverIFID == "" {
SelectCardReaderDialog()
return
Expand All @@ -292,12 +322,22 @@ func enableButtonFunc() {
SelectItemDialog()
return
}
if err := LpacProfileEnable(Profiles[SelectedProfile].Iccid); err != nil {
ErrDialog(err)
if ProfileStateAllowDisable {
if err := LpacProfileDisable(Profiles[SelectedProfile].Iccid); err != nil {
ErrDialog(err)
}
} else {
if err := LpacProfileEnable(Profiles[SelectedProfile].Iccid); err != nil {
ErrDialog(err)
}
}
RefreshProfile()
RefreshNotification()
RefreshChipInfo()
if ProfileStateAllowDisable {
SwitchStateButton.SetText("Enable")
SwitchStateButton.SetIcon(theme.ConfirmIcon())
}
}

func processNotificationButtonFunc() {
Expand Down Expand Up @@ -493,6 +533,15 @@ func initProfileList() *widget.List {
},
OnSelected: func(id widget.ListItemID) {
SelectedProfile = id
if Profiles[SelectedProfile].ProfileState == "enabled" {
ProfileStateAllowDisable = true
SwitchStateButton.SetText("Disable")
SwitchStateButton.SetIcon(theme.CancelIcon())
} else {
ProfileStateAllowDisable = false
SwitchStateButton.SetText("Enable")
SwitchStateButton.SetIcon(theme.ConfirmIcon())
}
}}
}

Expand Down Expand Up @@ -547,5 +596,4 @@ func initNotificationList() *widget.List {
OnSelected: func(id widget.ListItemID) {
SelectedNotification = id
}}

}
7 changes: 4 additions & 3 deletions window.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var WMain fyne.Window
func InitMainWindow() fyne.Window {
w := App.NewWindow("EasyLPAC")
w.Resize(fyne.Size{
Width: 830,
Width: 850,
Height: 545,
})
w.SetMaster()
Expand Down Expand Up @@ -50,7 +50,7 @@ func InitMainWindow() fyne.Window {
nil,
nil,
nil,
container.NewHBox(ProfileMaskCheck, DownloadButton, spacer, DiscoveryButton, spacer, SetNicknameButton, spacer, EnableButton, spacer, DeleteButton),
container.NewHBox(ProfileMaskCheck, DownloadButton, spacer, DiscoveryButton, spacer, SetNicknameButton, spacer, SwitchStateButton, spacer, DeleteButton),
statusBar),
nil,
nil,
Expand Down Expand Up @@ -95,7 +95,8 @@ func InitMainWindow() fyne.Window {
nil,
nil,
nil,
container.NewScroll(EuiccInfo2TextGrid)))
container.NewScroll(EuiccInfo2Entry),
))
ChipInfoTab = container.NewTabItem("Chip Info", chipInfoTabContent)

thankstoText := widget.NewRichTextFromMarkdown(`
Expand Down

0 comments on commit e5b4c8b

Please sign in to comment.