Skip to content

Commit

Permalink
fix: aao notices on ios to use safari and improve watchos implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
singularity-s0 committed Jul 3, 2021
1 parent ab1c46e commit 83f5bea
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 282 deletions.
12 changes: 12 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
8A3543292690371D00A6B16E /* TreeHoleDetailsPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A3542EB268FFF1F00A6B16E /* TreeHoleDetailsPage.swift */; };
8A35432A2690372000A6B16E /* TreeHoleModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A3542E0268FFE4B00A6B16E /* TreeHoleModels.swift */; };
8A35432B2690372400A6B16E /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 8A3542F62690043A00A6B16E /* Localizable.strings */; };
8A35433026908A7E00A6B16E /* WatchConnectivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A35432F26908A7E00A6B16E /* WatchConnectivity.swift */; };
8AAA75822657A6230053E836 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 8AAA75812657A6230053E836 /* GoogleService-Info.plist */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
Expand Down Expand Up @@ -113,6 +114,7 @@
8A35430E269035F000A6B16E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
8A354311269035F000A6B16E /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
8A354313269035F000A6B16E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8A35432F26908A7E00A6B16E /* WatchConnectivity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchConnectivity.swift; sourceTree = "<group>"; };
8AAA75812657A6230053E836 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
8AD96B9F261DAD0C0081F6F4 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Main.strings"; sourceTree = "<group>"; };
8AD96BA0261DAD0C0081F6F4 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/LaunchScreen.strings"; sourceTree = "<group>"; };
Expand All @@ -127,6 +129,13 @@
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
07E95D3B874EE14A1B8C8798 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
8A354300269035EF00A6B16E /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -193,6 +202,7 @@
isa = PBXGroup;
children = (
8A3542C6268FFDF200A6B16E /* RunnerApp.swift */,
8A35432F26908A7E00A6B16E /* WatchConnectivity.swift */,
8A35430C269035EF00A6B16E /* ComplicationController.swift */,
8A3542C4268FFDF200A6B16E /* ContentView.swift */,
8A3542E8268FFF1300A6B16E /* TreeHoleRepository.swift */,
Expand Down Expand Up @@ -284,6 +294,7 @@
buildPhases = (
8A3542F8269035EE00A6B16E /* Resources */,
8A35431A269035F000A6B16E /* Embed App Extensions */,
07E95D3B874EE14A1B8C8798 /* Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -524,6 +535,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8A35433026908A7E00A6B16E /* WatchConnectivity.swift in Sources */,
8A3543202690360600A6B16E /* RunnerApp.swift in Sources */,
8A3543222690360600A6B16E /* ContentView.swift in Sources */,
8A3543282690371B00A6B16E /* THPostView.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,16 @@
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
launchAutomaticallySubstyle = "32">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/dan-xi">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8A3542F9269035EE00A6B16E"
BuildableName = "nano.app"
BlueprintName = "nano"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</RemoteRunnable>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand All @@ -75,27 +73,16 @@
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES"
launchAutomaticallySubstyle = "32">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/dan-xi">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8A3542F9269035EE00A6B16E"
BuildableName = "nano.app"
BlueprintName = "nano"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8A3542F9269035EE00A6B16E"
BuildableName = "nano.app"
BlueprintName = "nano"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</MacroExpansion>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
25 changes: 6 additions & 19 deletions ios/Runner.xcodeproj/xcshareddata/xcschemes/nano.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -54,46 +54,33 @@
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/dan-xi">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8A3542F9269035EE00A6B16E"
BuildableName = "nano.app"
BlueprintName = "nano"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</RemoteRunnable>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<RemoteRunnable
runnableDebuggingMode = "2"
BundleIdentifier = "com.apple.Carousel"
RemotePath = "/dan-xi">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8A3542F9269035EE00A6B16E"
BuildableName = "nano.app"
BlueprintName = "nano"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</RemoteRunnable>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8A3542F9269035EE00A6B16E"
BuildableName = "nano.app"
BlueprintName = "nano"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</MacroExpansion>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
2 changes: 1 addition & 1 deletion ios/nano Extension/Pages/TreeHoleDetailsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct TreeHoleDetailsPage: View {
@State var currentPage: Int = 1
@State var isLoading = false
@State var endReached = false
@EnvironmentObject var fduholeLoginInfo: fduholeTokenProvider
@EnvironmentObject var fduholeLoginInfo: wcDelegate

init(replies: [THReply]) {
replyList = replies
Expand Down
2 changes: 1 addition & 1 deletion ios/nano Extension/Pages/TreeHolePage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct TreeHolePage: View {
@EnvironmentObject var fduholeLoginInfo: fduholeTokenProvider
@EnvironmentObject var fduholeLoginInfo: wcDelegate
@State private var discussions = [THDiscussion]()
@State private var currentPage = 1
@State private var endReached = false
Expand Down
4 changes: 2 additions & 2 deletions ios/nano Extension/Views/THPostView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ struct THPostView: View {
Label("\(discussion.count)", systemImage: "ellipsis.bubble")
.font(.footnote)
.imageScale(.small)
Label(discussion.date_created, systemImage: "clock")
/*Label(humanReadableDateString(dateString: discussion.date_created) , systemImage: "clock")
.lineLimit(1)
.font(.footnote)
.imageScale(.small)
.imageScale(.small)*/
}
.padding(.bottom)
}
Expand Down
55 changes: 55 additions & 0 deletions ios/nano Extension/WatchConnectivity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// WatchConnectivity.swift
// nano Extension
//
// Created by Kavin Zhao on 2021/7/3.
//

import Foundation
import WatchConnectivity
import SwiftUI

class wcDelegate: NSObject, WCSessionDelegate, ObservableObject {
let session = WCSession.default;
@Published var token = ""

override init() {
super.init()
token = getFduholeToken()
session.delegate = self
session.activate()
}


func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {

}

func sendString(text: String) -> Bool {
if(session.isReachable){
DispatchQueue.main.async {
self.session.sendMessage(["fduhole": text], replyHandler: nil, errorHandler: {error -> Void in
print(error)
})
}
return true
}
return false
}

func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
DispatchQueue.main.async {
self.token = message["fduhole_token"] as! String
}
setFduholeToken(token: message["fduhole_token"] as! String)
}

let defaults = UserDefaults.standard
func setFduholeToken(token: String) -> Void {
defaults.set(token, forKey: "fduhole_token")
}

func getFduholeToken() -> String {
return defaults.string(forKey: "fduhole_token") ?? ""
}
}
1 change: 1 addition & 0 deletions ios/nano Extension/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
"gettingtoken" = "Waiting for account information from iPhone...";
"image_tag" = "[Image]";
"iphoneunreachable" = "iPhone Unreachable. Tap to retry";
"manualInputToken" = "Manually import Token";
1 change: 1 addition & 0 deletions ios/nano Extension/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
"gettingtoken" = "正在从iPhone获取账户信息...";
"image_tag" = "[图片]";
"iphoneunreachable" = "无法连接到iPhone,点击重试";
"manualInputToken" = "手动导入Token";
21 changes: 18 additions & 3 deletions ios/nanoDanxi WatchKit Extension/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
//

import SwiftUI
import WatchKit

struct ContentView: View {
@EnvironmentObject var fduholeLoginInfo: fduholeTokenProvider
@EnvironmentObject var fduholeLoginInfo: wcDelegate
@State var connectionReachable = true;
@State private var capturedText = ""


var body: some View {

Expand All @@ -18,16 +21,28 @@ struct ContentView: View {
if (connectionReachable) {
ProgressView()
Text("gettingtoken")
.onTapGesture {
connectionReachable = wcDelegate().sendString(text: "get_token")
}
}
else {
Text("iphoneunreachable")
.onTapGesture {
connectionReachable = fduholeTokenProvider().sendString(text: "get_token")
connectionReachable = wcDelegate().sendString(text: "get_token")
}
}

TextField("test", text: $capturedText)
{ isEditing in

} onCommit: {
UserDefaults.standard.set(capturedText, forKey: "fduhole_token")
fduholeLoginInfo.token = capturedText
}
.textContentType(.oneTimeCode)
}
.onAppear() {
connectionReachable = fduholeTokenProvider().sendString(text: "get_token")
connectionReachable = wcDelegate().sendString(text: "get_token")
}
}
else {
Expand Down
56 changes: 1 addition & 55 deletions ios/nanoDanxi WatchKit Extension/RunnerApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI

@main
struct RunnerApp: App {
@StateObject var fduholeLoginInfo = fduholeTokenProvider()
@StateObject var fduholeLoginInfo = wcDelegate()

var body: some Scene {
WindowGroup {
Expand All @@ -20,57 +20,3 @@ struct RunnerApp: App {
}
}
}


// WCSession
import WatchKit
import Foundation
import WatchConnectivity


class fduholeTokenProvider: NSObject, WCSessionDelegate, ObservableObject {
@Published var token = ""
var session: WCSession

init(session: WCSession = .default) {
self.session = session
super.init()
self.session.delegate = self
session.activate()
token = getFduholeToken()
}


func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
}

func sendString(text: String) -> Bool {
let session = WCSession.default;
if(session.isReachable){
DispatchQueue.main.async {
session.sendMessage(["fduhole": text], replyHandler: nil, errorHandler: {error -> Void in

})
}
return true
}
return false
}

func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
DispatchQueue.main.async {
self.token = message["fduhole_token"] as! String
}
setFduholeToken(token: message["fduhole_token"] as! String)
}

let defaults = UserDefaults.standard
func setFduholeToken(token: String) -> Void {
defaults.set(token, forKey: "fduhole_token")
}

func getFduholeToken() -> String {
return defaults.string(forKey: "fduhole_token") ?? ""
}

}
5 changes: 4 additions & 1 deletion lib/page/aao_notices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ class _AAONoticesListState extends State<AAONoticesList> {
title: Text(value.title),
subtitle: Text(value.time),
onTap: () => BrowserUtil.openUrl(
value.url, FudanAAORepository.getInstance().cookieJar),
value.url,
PlatformX.isAndroid
? FudanAAORepository.getInstance().cookieJar
: null), // TODO: fix this for iOS
)));
});

Expand Down
Loading

0 comments on commit 83f5bea

Please sign in to comment.