Skip to content

Commit

Permalink
put icons on session list
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmTomahawkx committed Jul 15, 2024
1 parent db26db3 commit 38ddcab
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 9 deletions.
80 changes: 71 additions & 9 deletions Revolt/Pages/Settings/SessionsSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ struct SessionsSettings: View {

if let session = currentSession {
Section("This Device") {
SessionView(session: session)
SessionView(viewState: viewState, session: session)
}
.listRowBackground(viewState.theme.accent.color)

}

Section("Active Sessions") {
ForEach($sessions.filter({ $0.id != viewState.currentSessionId }).sorted(by: { $0.id > $1.id })) { session in
SessionView(session: session.wrappedValue)
SessionView(viewState: viewState, session: session.wrappedValue)
.swipeActions(edge: .trailing) {
Button {
Task {
Expand Down Expand Up @@ -58,16 +58,78 @@ struct SessionsSettings: View {
}

struct SessionView: View {
@EnvironmentObject var viewState: ViewState
@State var viewState: ViewState
var session: Session
var browserType: Image?
var platformType: Image

init(viewState: ViewState, session sess: Session) {
self._viewState = State(initialValue: viewState)
self.session = sess
let sessionName = sess.name.lowercased()

if sessionName.contains("ios") {
platformType = Image(systemName: "iphone.gen3")
browserType = nil
} else if sessionName.contains("android") {
platformType = Image(.androidLogo!)
browserType = nil
} else if sessionName.contains("on") { // in browser or on desktop
let types = try? /(?<browser>revolt desktop|[^ ]+) on (?<platform>.+)/.firstMatch(in: sessionName)

if let types = types {
let platformName = types.output.platform.lowercased()

if platformName == "mac os" {
platformType = Image(systemName: "apple.logo")
} else if platformName == "windows" {
platformType = Image(.windowsLogo!)
} else {
platformType = Image(.linuxLogo!)
}

let browserName = types.output.browser.lowercased()

if browserName.contains(/chrome|brave|opera|arc/) {
browserType = Image(.chromeLogo!)
} else if browserName == "safari" {
browserType = Image(systemName: "safari")
} else if browserName == "firefox" {
browserType = Image(.firefoxLogo!)
} else if browserName == "revolt desktop" {
browserType = Image(.monochrome!)
} else {
browserType = Image(systemName: "questionmark")
}
} else {
platformType = Image(systemName: "questionmark.circle")
browserType = nil
}
} else {
platformType = Image(systemName: "questionmark.circle")
browserType = nil
}
}

var body: some View {
HStack(alignment: .center) {
Image(systemName: "lock")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 28, height: 28)

ZStack {
platformType
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 64, height: 64)
/*
if browserType != nil {
browserType!
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundStyle(.black)
//.padding(.leading, 20)
//.padding(.top, 20)
.frame(height: 32, alignment: .bottomTrailing) // TODO: unfuck this positioning
}
*/
}
VStack(alignment: .leading) {
Text(session.name)
.bold()
Expand All @@ -77,7 +139,7 @@ struct SessionView: View {
if days == 0 {
Text("Created today")
} else {
Text("Created \(days) days ago")
Text("Created \(days) day(s) ago")
}
}
.padding(.leading, 16)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "AndroidLogo.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "ChromeLogo.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "FirefoxLogo.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "LinuxLogo.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "WindowsLogo.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 38ddcab

Please sign in to comment.